summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2013-09-22 11:15:46 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2013-09-22 11:15:46 +0200
commit355af3d431c8818995d28c648b12b82f190c4332 (patch)
treea7c0528e497bd342cb096da285496b699f34a3f4
parent578d6409a0f6438dab75e077a2256e1710376d05 (diff)
downloadcheck-snmp-switch-355af3d431c8818995d28c648b12b82f190c4332.tar.gz
check-snmp-switch-355af3d431c8818995d28c648b12b82f190c4332.tar.bz2
check-snmp-switch-355af3d431c8818995d28c648b12b82f190c4332.zip
add packet counterHEADmaster
-rwxr-xr-xcheck_snmp_switch_traffic.pl58
1 files 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<check_snmp_switch_traffic> 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