From 355af3d431c8818995d28c648b12b82f190c4332 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Sun, 22 Sep 2013 11:15:46 +0200 Subject: add packet counter --- check_snmp_switch_traffic.pl | 58 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/check_snmp_switch_traffic.pl b/check_snmp_switch_traffic.pl index 8c5e57f..fae39cc 100755 --- a/check_snmp_switch_traffic.pl +++ b/check_snmp_switch_traffic.pl @@ -8,8 +8,12 @@ use Pod::Usage; my $rmon_oid = '.1.3.6.1.2.1.2.2.1.2'; my $name_oid = '.1.3.6.1.2.1.31.1.1.1.1'; -my $in_oid = '.1.3.6.1.2.1.2.2.1.10'; -my $out_oid = '.1.3.6.1.2.1.2.2.1.16'; +my $in_oct_oid = '.1.3.6.1.2.1.2.2.1.10'; +my $out_oct_oid = '.1.3.6.1.2.1.2.2.1.16'; +my $in_uni_pkt_oid = '.1.3.6.1.2.1.2.2.1.11'; +my $out_uni_pkt_oid = '.1.3.6.1.2.1.2.2.1.17'; +my $in_non_uni_pkt_oid = '.1.3.6.1.2.1.2.2.1.12'; +my $out_non_uni_pkt_oid = '.1.3.6.1.2.1.2.2.1.18'; sub snmp_walk($$$) { my $session = shift; @@ -65,8 +69,10 @@ sub generate_oids ($@) { return @results; } -sub get_info ($$) { +sub get_info ($$$$) { my $session = shift; + my $in_oid = shift; + my $out_oid = shift; my $IFACES = shift; foreach my $root ($name_oid, $in_oid, $out_oid) { @@ -111,14 +117,18 @@ my $host; my $port = 161; my $community = 'public'; my $timeout = 10; +my $packets = 0; +my $non_unicast_packets = 0; my $help = 0; Getopt::Long::Configure ("bundling"); -GetOptions('host|H=s' => \$host, - 'port|p=i' => \$port, - 'community|C=s' => \$community, - 'timeout|t=i' => \$timeout, - 'help|?' => \$help) +GetOptions('host|H=s' => \$host, + 'port|p=i' => \$port, + 'community|C=s' => \$community, + 'timeout|t=i' => \$timeout, + 'packets' => \$packets, + 'non-unicast-packets' => \$non_unicast_packets, + 'help|?' => \$help) or pod2usage(2); pod2usage(0) if $help; pod2usage(2) unless (defined $host); @@ -135,8 +145,23 @@ my ($session, $err) = Net::SNMP->session( ); nagios_die($err) unless defined $session; +my $in_oid; +my $out_oid; +if ($non_unicast_packets) { + $in_oid = $in_non_uni_pkt_oid; + $out_oid = $out_non_uni_pkt_oid; +} +elsif ($packets) { + $in_oid = $in_uni_pkt_oid; + $out_oid = $out_uni_pkt_oid; +} +else { + $in_oid = $in_oct_oid; + $out_oid = $out_oct_oid; +} + my $IFACES = get_ifaces($session); -get_info($session, $IFACES); +get_info($session, $in_oid, $out_oid, $IFACES); $session->close(); my $channel = grep { $IFACES->{$_}{'name'} =~ /^ch/} keys %{ $IFACES }; @@ -163,6 +188,8 @@ check_snmp_swtich_traffic --host|-H HOSTNAME [options] --port|-p PORT --community|-C COMMUNITY --timeout|-t TIMEOUT + --packets + --non-unicast-packets --help|-? =head1 OPTIONS @@ -186,6 +213,16 @@ SNMPv1 Community string. If not specified it defaults to "public". Maximum runtime in seconds of this script before returning UNKNOWN. If not specified it defaults to 10. +=item B<--packets> + +Get the counter for the send and received unicast packets. + +=item B<--non-unicast-packets> + +Get the counter for the send and received non unicast packets. +If B<--packets> and B<--non-unicast-packets> are given, the +B<--packets> switch is ignored. + =item B<--help|-?> Display a help message about the available options. @@ -195,6 +232,7 @@ Display a help message about the available options. =head1 DESCRIPTION B fetches the available ports of a switch -and queries the in and out octet counters via SNMP. +and queries the in and out octet counters via SNMP. It is also possible +to get the counter for unicast and non-unicast packets. =cut -- cgit v1.2.3-1-g7c22