#!/usr/bin/perl -w =head1 NAME fw_packets_ds - Plugin to monitor the throughput of a firewall in an IPv4/IPv6 DualStack setup =head1 CONFIGURATION This plugin must run with root privileges =head1 CONFIGURATION EXAMPLE /etc/munin/plugin-conf.d/global or other file in that dir must contain: [fw*] user root =head1 NOTES This plugin is insprired by the original fw_packets plugin. The plugin tries to use the nstat tool to determine the metrics in a more consistent way. If this fails it falls back to parsing /proc files. =head1 AUTHOR Nis 'eNBeWe' Wechselberg =head1 LICENSE MIT =head1 MAGIC MARKERS #%# family=auto #%# capabilities=autoconf =cut use strict; my $nstat = '/usr/bin/nstat'; my $snmp_file = '/proc/net/snmp'; my $snmp6_file = '/proc/net/snmp6'; # Autoconf Mode if ( defined($ARGV[0]) and $ARGV[0] eq "autoconf" ) { if ( -x $nstat or -r $snmp_file or -r $snmp6_file ) { print "yes\n"; } else { print "no\n"; } exit 0; } # Graph config if ( defined($ARGV[0]) and $ARGV[0] eq "config" ) { print < 0, 'v6RECEIVED' => 0 ); if ( -x $nstat ) { # Use nstat tool for metrics my $command = "$nstat -a -z IpIn* Ip6In* 2>/dev/null"; open CMD, "$command|"; while () { if (/^(\S+)\s+(\d+)/) { if ( $1 eq 'IpInReceives' ) { $state{'v4RECEIVED'} = $2; } if ( $1 eq 'Ip6InReceives' ) { $state{'v6RECEIVED'} = $2; } } } close CMD; } else { # Parse /proc files if ( -r $snmp_file ) { my $index_received = 0; open SNMP, $snmp_file; while () { if (/^Ip:\s+\D/) { my @ip = split; while ( not $ip[$index_received] =~ /InReceives/ ) { $index_received++; } } if (/^Ip:\s+\d/) { my @ip = split; $state{'v4RECEIVED'} = $ip[$index_received]; last; } } close SNMP; } if ( -r $snmp6_file ) { open SNMP6, $snmp6_file; while () { if (/^Ip6InReceives\s+(\d+)/) { $state{'v6RECEIVED'} = $1; } } close SNMP6; } } print "v4_received.value $state{'v4RECEIVED'}\n"; print "v6_received.value $state{'v6RECEIVED'}\n";