From 17c54160e7532746b5838daede55749160fca46e Mon Sep 17 00:00:00 2001 From: Nis Wechselberg Date: Tue, 10 Jan 2017 11:48:33 +0100 Subject: [PATCH] Added plugin for received firewall packets --- .gitignore | 69 ++++++++++++++++++++++++++ README.md | 7 +++ fw_packets_ds | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 207 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 fw_packets_ds diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dcda687 --- /dev/null +++ b/.gitignore @@ -0,0 +1,69 @@ +# Created by https://www.gitignore.io/api/sublimetext,perl + +### SublimeText ### +# cache files for sublime text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache + +# workspace files are user-specific +*.sublime-workspace + +# project files should be checked into the repository, unless a significant +# proportion of contributors will probably not be using SublimeText +# *.sublime-project + +# sftp configuration file +sftp-config.json + +# Package control specific files +Package Control.last-run +Package Control.ca-list +Package Control.ca-bundle +Package Control.system-ca-bundle +Package Control.cache/ +Package Control.ca-certs/ +bh_unicode_properties.cache + +# Sublime-github package stores a github token in this file +# https://packagecontrol.io/packages/sublime-github +GitHub.sublime-settings + + +### Perl ### +!Build/ +.last_cover_stats +/META.yml +/META.json +/MYMETA.* +*.o +*.bs + +# Devel::Cover +cover_db/ + +# Devel::NYTProf +nytprof.out + +# Dizt::Zilla +/.build/ + +# Module::Build +_build/ +Build +Build.bat + +# Module::Install +inc/ + +# ExtUitls::MakeMaker +/blib/ +/_eumm/ +/*.gz +/Makefile +/Makefile.old +/MANIFEST.bak +/pm_to_blib +/*.zip + +# End of https://www.gitignore.io/api/sublimetext,perl diff --git a/README.md b/README.md new file mode 100644 index 0000000..749c95f --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# munin-ipv6 - A collection of Munin plugins made IPv6-capable + +This is just a collection of munin plugins, modified to properly work in an IPv6-enabled or IPv6-only environment. Sadly, many older plugins are only measuring IPv4 traffic. + +## fw_packets_ds + +Adaption of the original fw_packets plugin for IPv6. diff --git a/fw_packets_ds b/fw_packets_ds new file mode 100755 index 0000000..58c3998 --- /dev/null +++ b/fw_packets_ds @@ -0,0 +1,131 @@ +#!/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";