forked from ofalk/Nagios
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_snmp_zombies.pl
More file actions
executable file
·58 lines (47 loc) · 1.3 KB
/
Copy pathcheck_snmp_zombies.pl
File metadata and controls
executable file
·58 lines (47 loc) · 1.3 KB
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
#!/usr/bin/perl -w
# Copyright (c) by Oliver Falk <oliver@linux-kernel.at>, 2012-2014
use strict;
use warnings;
use Getopt::Long;
use Net::SNMP;
use constant ERRORS => {
UNKNOWN => -1,
OK => 0,
WARNING => 1,
CRITICAL => 2,
};
use constant TABLE => 'HOST-RESOURCES-MIB::hrSWRunStatus';
sub snmpwalkgrep {
my ($hostname, $community, $tree, $text) = @_;
my $walk = `snmpwalk -v 1 -c $community $hostname $tree |grep $text`;
return $walk;
}
my ($hostname, $num_zombies);
my $warning = 1;
my $critical = 5;
my $community = 'public';
GetOptions(
"hostname|h=s" => \$hostname,
"community|c=s" => \$community,
"warning|w=i" => \$warning,
"error|e=i" => \$critical,
);
die "No hostname given!" unless $hostname;
my $inval = snmpwalkgrep($hostname, $community, TABLE, 'invalid');
if($inval) {
my $i = 0;
$i++ foreach (split(/\n/, $inval));
if($i >= $critical) {
print "CRITICAL: $i invalid processes found | invalid=$i;$warning;$critical\n";
exit ERRORS->{CRITICAL};
} elsif ($i >= $warning) {
print "WARNING: $i invalid processes found | invalid=$i;$warning;$critical\n";
exit ERRORS->{WARNING};
} else {
print "OK: $i invalid processes found | invalid=$i;$warning;$critical\n";
exit ERRORS->{OK};
}
}
print "OK: 0 invalid processes found | invalid=0;$warning;$critical\n";
exit ERRORS->{OK};
1;