| 1 |
package Core::Pf::Labels; |
|---|
| 2 |
|
|---|
| 3 |
use strict; |
|---|
| 4 |
use warnings; |
|---|
| 5 |
|
|---|
| 6 |
use base 'Resmon::Module'; |
|---|
| 7 |
|
|---|
| 8 |
use Resmon::ExtComm qw(run_command); |
|---|
| 9 |
|
|---|
| 10 |
=pod |
|---|
| 11 |
|
|---|
| 12 |
=head1 NAME |
|---|
| 13 |
|
|---|
| 14 |
Core::Pf::Labels - gather label statistics from PF firewalls |
|---|
| 15 |
|
|---|
| 16 |
=head1 SYNOPSIS |
|---|
| 17 |
|
|---|
| 18 |
Core::Pf::Labels { |
|---|
| 19 |
* : pfctl_path => /sbin/pfctl |
|---|
| 20 |
} |
|---|
| 21 |
|
|---|
| 22 |
=head1 DESCRIPTION |
|---|
| 23 |
|
|---|
| 24 |
This module retrieves label statistics from PF firewalls using |
|---|
| 25 |
the pfctl command. Metrics for each label are returned as a separate check. |
|---|
| 26 |
|
|---|
| 27 |
=head1 CONFIGURATION |
|---|
| 28 |
|
|---|
| 29 |
=over |
|---|
| 30 |
|
|---|
| 31 |
=item check_name |
|---|
| 32 |
|
|---|
| 33 |
This is a wildcard module and will return metrics for all labels. As such, the |
|---|
| 34 |
check name should be an asterisk (*). |
|---|
| 35 |
|
|---|
| 36 |
=item pfctl_path |
|---|
| 37 |
|
|---|
| 38 |
Optional path to the pfctl executable. |
|---|
| 39 |
|
|---|
| 40 |
=back |
|---|
| 41 |
|
|---|
| 42 |
=head1 METRICS |
|---|
| 43 |
|
|---|
| 44 |
=over |
|---|
| 45 |
|
|---|
| 46 |
=item evals |
|---|
| 47 |
|
|---|
| 48 |
=item pkts |
|---|
| 49 |
|
|---|
| 50 |
=item bytes |
|---|
| 51 |
|
|---|
| 52 |
=item pkts_in |
|---|
| 53 |
|
|---|
| 54 |
=item bytes_in |
|---|
| 55 |
|
|---|
| 56 |
=item pkts_out |
|---|
| 57 |
|
|---|
| 58 |
=item bytes_out |
|---|
| 59 |
|
|---|
| 60 |
=item states |
|---|
| 61 |
|
|---|
| 62 |
=back |
|---|
| 63 |
|
|---|
| 64 |
=cut |
|---|
| 65 |
|
|---|
| 66 |
sub wildcard_handler { |
|---|
| 67 |
my $self = shift; |
|---|
| 68 |
my $config = $self->{'config'}; |
|---|
| 69 |
my $pfctl_path = $config->{'pfctl_path'} || 'pfctl'; |
|---|
| 70 |
my $output = run_command("$pfctl_path -sl"); |
|---|
| 71 |
my $osname = $^O; |
|---|
| 72 |
my $metrics; |
|---|
| 73 |
|
|---|
| 74 |
if ($osname eq 'openbsd') { |
|---|
| 75 |
foreach (split(/\n/, $output)) { |
|---|
| 76 |
if (/(\w+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/) { |
|---|
| 77 |
$metrics->{$1}->{"evals"} += $2; |
|---|
| 78 |
$metrics->{$1}->{"pkts"} += $3; |
|---|
| 79 |
$metrics->{$1}->{"bytes"} += $4; |
|---|
| 80 |
$metrics->{$1}->{"pkts_in"} += $5; |
|---|
| 81 |
$metrics->{$1}->{"bytes_in"} += $6; |
|---|
| 82 |
$metrics->{$1}->{"pkts_out"} += $7; |
|---|
| 83 |
$metrics->{$1}->{"bytes_out"} += $8; |
|---|
| 84 |
$metrics->{$1}->{"states"} += $9; |
|---|
| 85 |
} |
|---|
| 86 |
} |
|---|
| 87 |
for my $queue (keys %$metrics) { |
|---|
| 88 |
for my $key (keys %{$metrics->{$queue}}) { |
|---|
| 89 |
$metrics->{$queue}->{$key} = [$metrics->{$queue}->{$key}, 'L']; |
|---|
| 90 |
} |
|---|
| 91 |
} |
|---|
| 92 |
} else { |
|---|
| 93 |
die "Unknown platform: $osname\n"; |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
die "No labels found\n" unless (%$metrics); |
|---|
| 97 |
|
|---|
| 98 |
return $metrics; |
|---|
| 99 |
}; |
|---|
| 100 |
|
|---|
| 101 |
1; |
|---|