1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#!/usr/bin/perl
#
# Monitor snmp processes
#
# Arguments are:
#
# [-c community] host [host ...]
#
# This script will exit with value 1 if host:community has prErrorFlag
# set. The summary output line will be the host names that failed
# and the name of the process. The detail lines are what UCD snmp returns
# for an prErrMessage. ('Too (many|few) (name) running (# = x)').
# If there is an SNMP error (either a problem with the SNMP libraries,
# or a problem communicating via SNMP with the destination host),
# this script will exit with a warning value of 2.
#
# There probably should be a better way to specify a given process to
# watch instead of everything-ucd-snmp-is-watching.
#
# $Id: process.monitor 1.2 Sat, 30 Jun 2001 14:44:29 -0400 trockij $
#
#
# Copyright (C) 1998, Brian Moore
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
use SNMP;
use Getopt::Std;
$ENV{'MIBS'} = "UCD-SNMP-MIB";
getopts("c:");
$community = $opt_c || 'public';
$RETVAL = 0;
foreach $host (@ARGV) {
$session = new SNMP::Session(DestHost => $host,
Community => $community);
if (!defined ($session)) {
$RETVAL = ($RETVAL == 1) ? 1 : 2;
push @failures, "$host session error";
push @longerr, "$host could not get SNMP session";
next;
}
my $v = new SNMP::Varbind (["prIndex"]);
$session->getnext ($v);
while (!$session->{"ErrorStr"} && $v->tag eq "prIndex") {
my @q = $session->get ([
["prNames", $v->iid],
["prMin", $v->iid],
["prMax", $v->iid],
["prCount", $v->iid],
["prErrorFlag", $v->iid],
["prErrMessage", $v->iid],
# ["prErrFix", $v->iid],
]);
last if ($session->{"ErrorStr"});
if ($q[4] > 0) {
$RETVAL = 1;
push (@failures, $host);
push (@longerr, "$host: count=$q[3] min=$q[1] max=$q[2] err=$q[5]");
}
$session->getnext ($v);
}
if ($session->{"ErrorStr"}) {
push (@failures, $host);
push (@longerr, "$host returned an SNMP error: " . $session->{"ErrorStr"});
}
}
if (@failures) {
print join (", ", sort @failures), "\n", "\n";
print join ("\n", @longerr), "\n";
}
exit $RETVAL;
|