[Resmon-devel] [resmon commit] r362 - branches/resmon2/lib/Core/Pf

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Thu May 6 20:15:03 EDT 2010


Author: jdixon
Date: 2010-05-06 20:15:03 -0400 (Thu, 06 May 2010)
New Revision: 362

Added:
   branches/resmon2/lib/Core/Pf/Labels.pm
Log:
new module for IP accounting with PF labels

Added: branches/resmon2/lib/Core/Pf/Labels.pm
===================================================================
--- branches/resmon2/lib/Core/Pf/Labels.pm	                        (rev 0)
+++ branches/resmon2/lib/Core/Pf/Labels.pm	2010-05-07 00:15:03 UTC (rev 362)
@@ -0,0 +1,96 @@
+package Core::Pf::Labels;
+
+use strict;
+use warnings;
+
+use base 'Resmon::Module';
+
+use Resmon::ExtComm qw(run_command);
+
+=pod
+
+=head1 NAME
+
+Core::Pf::Labels - gather label statistics from PF firewalls
+
+=head1 SYNOPSIS
+
+ Core::Pf::Labels {
+    local : pfctl_path => /sbin/pfctl
+ }
+
+=head1 DESCRIPTION
+
+This module retrieves label statistics from PF firewalls using
+the pfctl command.  Each metric returned is prefixed with the
+name of the associated label.
+
+=head1 CONFIGURATION
+
+=over
+
+=item check_name
+
+Arbitrary name of the check.
+
+=item pfctl_path
+
+Optional path to the pfctl executable.
+
+=back
+
+=head1 METRICS
+
+=over
+
+=item evals
+
+=item pkts
+
+=item bytes
+
+=item pkts_in
+
+=item bytes_in
+
+=item pkts_out
+
+=item bytes_out
+
+=item states
+
+=back
+
+=cut
+
+sub handler {
+    my $self = shift;
+    my $config = $self->{'config'};
+    my $pfctl_path = $config->{'pfctl_path'} || 'pfctl';
+    my $output = run_command("$pfctl_path -sl") || die "Unable to execute: $pfctl_path";
+    my $osname = $^O;
+    my %metrics;
+
+    if ($osname eq 'openbsd') {
+        foreach (split(/\n/, $output)) {
+            if (/(\w+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/) {
+                $metrics{"${1}_evals"} += $2;
+                $metrics{"${1}_pkts"} += $3;
+                $metrics{"${1}_bytes"} += $4;
+                $metrics{"${1}_pkts_in"} += $5;
+                $metrics{"${1}_bytes_in"} += $6;
+                $metrics{"${1}_pkts_out"} += $7;
+                $metrics{"${1}_bytes_out"} += $8;
+                $metrics{"${1}_states"} += $9;
+            } else {
+                die "No queues found";
+            }
+        }
+    } else {
+        die "Unknown platform: $osname";
+    }
+
+    return { %metrics };
+};
+
+1;



More information about the Resmon-devel mailing list