#!/usr/bin/perl -wT # # check processes op nodes # # syntax: # ./check_process --host= --community= [--ignore=,,...] # # jorg@wirelessleiden.nl - 17 april 2004 use strict; use Getopt::Long; use Net::SNMP; #use Data::Dumper; # # settings # my $hostname = ""; my $community = "public"; my $ignorestring = ""; GetOptions("hostname:s" => \$hostname, "community:s" => \$community, "ignore:s" => \$ignorestring); my @ignore = parse_csv($ignorestring); 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 $i = 1; my $result = 1; # mag initieel niet leeg zijn ivm whilecheck. while (defined $result) { # prNames.$i prMin.$i prMax.$i prCount.$i my @oids = (".1.3.6.1.4.1.2021.2.1.2.$i", ".1.3.6.1.4.1.2021.2.1.3.$i", ".1.3.6.1.4.1.2021.2.1.4.$i", ".1.3.6.1.4.1.2021.2.1.5.$i"); $result = $session->get_request(-varbindlist => \@oids); if (defined $result) { # als we iets terug krijgen, dan opslaan, anders hebben we alle processen gehad. # # skip some processes # my $skip = 0; foreach my $item (@ignore) { if ($result->{$oids[0]} eq $item) { $skip = 1; } } if (($result->{$oids[0]} ne '') && (! $skip)) { # # parse data # if ($result->{$oids[3]} < $result->{$oids[1]}) { print "$result->{$oids[3]}x $result->{$oids[0]} running. "; $errorcode = 2; } if (($result->{$oids[3]} > $result->{$oids[2]}) && ($result->{$oids[2]} != 0)) { print "$result->{$oids[3]}x $result->{$oids[0]} running. "; $errorcode = 2; } } } $i++; } if ($i == 2) { # blijkbaar niet eens in de while-loop geweest print "0x snmpd running. (or bad connection)\n"; exit 3; } # # exit # (0=ok 1=warning 2=critical 3=unknown 4=dependent) # if ($errorcode == 0) { print "OK"; } print "\n"; exit $errorcode; # # subs # sub parse_csv { my $text = shift; # record containing comma-separated values my @new = (); push(@new, $+) while $text =~ m{ # the first part groups the phrase inside the quotes. "([^\"\\]*(?:\\.[^\"\\]*)*)",? | ([^,]+),? | , }gx; push(@new, undef) if substr($text, -1,1) eq ','; return @new; # list of values that were comma-separated }