#!/usr/bin/perl -w # # check network traffic on nodes # # syntax: # ./check_traffic --host= --community= [--warning=] [--critical=] [--interface=] # # jorg@wirelessleiden.nl - 11 september 2005 use strict; use Getopt::Long; use Net::SNMP; #use Data::Dumper; # # settings # my $hostname = ""; my $community = "public"; my $warning = "10"; my $critical = "20"; my $interface; my $tmpdir = '/tmp/nagios'; GetOptions("hostname:s" => \$hostname, "community:s" => \$community, "warning:i" => \$warning, "critical:i" => \$critical, "interface:s" => \$interface); my $errorcode = 0; my ($session, $error) = Net::SNMP->session(-hostname => $hostname, -community => $community, -timeout => 60, -retries => 1); if (! defined $session) { printf("ERROR: %s.\n", $error); exit 3; # unknown } my @oids = (".1.3.6.1.4.1.2021.50.1"); my $result = $session->get_request(-varbindlist => \@oids); if (! defined $result) { print "No snmpd running or bad connection\n"; exit 0; # ok } my $counters; my @fields = split(/ /, $result->{$oids[0]}); foreach my $field (@fields) { my ($ip, $data) = split(',', $field); if ($ip eq $interface) { $counters = $data; last; }; } if (! defined $counters) { print "Interface not found\n"; exit 2; # error } print "OK|$counters\n"; exit 0; # ok