3
# Copyright (c) 2000 Hugo Gayosso
6
# Nagios plug-in that monitors the resources on an HP-UX machine
7
# by querying the SNMP daemon
9
# License: General Public License (GPL)
10
# http://www.gnu.org/copyleft/gpl.txt
15
# Requirements: Perl 5.005 or higher
17
# Variable initialization
23
if (-e "/usr/bin/snmpwalk") {
24
$snmpwalk = "/usr/bin/snmpwalk";
25
} elsif (-e "/usr/local/bin/snmpwalk") {
26
$snmpwalk = "/usr/local/snmpwalk";
31
$filesystemID1_OID = ".1.3.6.1.4.1.11.2.3.1.2.2.1.1";
32
$mounted_OID = ".1.3.6.1.4.1.11.2.3.1.2.2.1.3";
33
$totalspace_OID = ".1.3.6.1.4.1.11.2.3.1.2.2.1.4";
34
$freespace_OID = ".1.3.6.1.4.1.11.2.3.1.2.2.1.6";
35
$path_OID = ".1.3.6.1.4.1.11.2.3.1.2.2.1.10";
36
$cpu_5min_OID = ".1.3.6.1.4.1.11.2.3.1.1.4";
40
GetOptions( "check-filesystem" => \$chk_fs,
41
"show-filesystems" => \$show_fs,
42
"check-filesystemID" => \$chk_fsid,
43
"check-cpu" => \$chk_cpu,
44
"host=s" => \$target_host,
45
"community=s" => \$target_community,
46
"filesystemID1=i" => \$fsid1_opt,
47
"filesystem=s" => \$fs_opt,
48
"warning=i" => \$warning_opt,
49
"critical=i" => \$critical_opt);
52
walk_data($snmpwalk, $target_host, $target_community, $mounted_OID );
53
walk_data($snmpwalk, $target_host, $target_community, $totalspace_OID );
54
walk_data($snmpwalk, $target_host, $target_community, $freespace_OID ); check_filesystem($fs_opt, $warning_opt, $critical_opt);
56
walk_data($snmpwalk, $target_host, $target_community, $filesystemID1_OID);
57
walk_data($snmpwalk, $target_host, $target_community, $mounted_OID );
58
walk_data($snmpwalk, $target_host, $target_community, $path_OID);
61
$totalspace_fsID_OID = "$totalspace_OID.$fsid1_opt";
62
$freespace_fsID_OID = "$freespace_OID.$fsid1_opt";
63
walk_data($snmpwalk, $target_host, $target_community, $totalspace_fsID_OID);
64
walk_data($snmpwalk, $target_host, $target_community, $freespace_fsID_OID);
65
check_filesystemID1($fsid1_opt, $warning_opt, $critical_opt);
67
get_cpu_load($snmpwalk, $target_host, $target_community, $cpu_5min_OID);
68
check_cpu_5min($cpu, $warning_opt, $critical_opt);
71
print "Checking 5-min CPU Load:\n";
72
print " $0 --check-cpu -warning <threshold> --critical <threshold> --host <yourhost> --community <SNMP community>\n\n";
73
print "Checking local filesystem mounted on a host:\n";
74
print " $0 --show-filesystems --host <hostname> --community <SNMP community>\n\n";
75
print "Checking by filesystem name:\n";
76
print " $0 --check-filesystem --filesystem </dev/vg00/lvol1> --warning <% used space> --critical <% used space> --host <hostname> --community <SNMP community>\n\n";
77
print "Checking by filesystem ID:\n";
78
print " $0 --check-filesystemID --filesystemID <filesystemID1> --warning <% used space> --critical <% used space> --host <hostname> --community <SNMP community>\n\n";
82
my ($snmpwalk, $target_host, $target_community, $OID) = @_;
83
die "cannot fork: $!" unless defined($pid = open(SNMPWALK, "-|"));
87
my @snmpdata = split(/:/,$_);
88
$cpu = $snmpdata[1]/100;
90
close(SNMPWALK) or warn "kid exited $?";
92
exec($snmpwalk,$target_host,$target_community,$OID) or die "can't exec program: $!";
97
#This function queries the SNMP daemon for the specific OID
98
my ($snmpwalk, $target_host, $target_community, $OID) = @_;
100
die "cannot fork: $!" unless defined($pid = open(SNMPWALK, "-|"));
105
sort_walk_data($output);
107
close(SNMPWALK) or warn "kid exited $?";
109
exec($snmpwalk,$target_host,$target_community,$OID) or die "can't exec program: $!";
114
my ($snmp_data) = @_;
115
@fields = split(/\./,$snmp_data);
117
$filesystemID1 = $fields[9];
118
@fields2 = split(/=/,$fields[10]);
119
# $filesystemID2 = $fields2[0];
120
$value = $fields2[1];
123
@fields3 = split(/"/,$value);
124
$value = $fields3[1];
127
$mounted{$filesystemID1} = "$value";
128
} elsif ($item == 4) {
129
$totalspace{$filesystemID1} = "$value";
130
} elsif ($item == 6) {
131
$freespace{$filesystemID1} = "$value";
132
} elsif ($item == 10) {
133
$filesystempath{$filesystemID1} = "$value";
137
sub show_filesystem {
138
print "\n\nfilesystemID1\tmounted filesystem\tfilesystem path\n";
139
foreach $element (keys %mounted) {
140
print "$element\t$mounted{$element}\t\t$filesystempath{$element}\n";
145
sub check_filesystem {
147
# Warning = percentage of used space >= $warning and < $critical
148
# Critical = percentage of used space > $warning and >= $critical
149
# OK = percentage of used space < $warning and < $critical
151
my ($mounted_filesystem, $warning, $critical) = @_;
152
foreach $element (keys %mounted) {
153
if ($mounted{$element} eq $mounted_filesystem) {
154
my $warning_result = $totalspace{$element}*(100-$warning)/100;
155
my $critical_result = $totalspace{$element}*(100-$critical)/100;
156
my $result_percent = $freespace{$element}*100/$totalspace{$element};
157
if (($freespace{$element} <= $warning_result) && ($freespace{$element} > $critical_result)) {
158
printf "Only %d M (%d%s) free\n",$freespace{$element}/1024,$result_percent,"%";
160
} elsif ($freespace{$element} <= $critical_result) {
161
printf "Only %d M (%d%s) free\n",$freespace{$element}/1024,$result_percent,"%";
164
printf "Disk ok - %d M (%d%s) free\n",$freespace{$element}/1024,$result_percent,"%";
169
print "$mounted_filesystem doesn't exist in $target_host\n\n";
173
sub check_filesystemID1{
174
# Warning = percentage of used space >= $warning and < $critical
175
# Critical = percentage of used space > $warning and >= $critical
176
# OK = percentage of used space < $warning and < $critical
178
my ($fsid1, $warning, $critical) = @_;
179
foreach $element (keys %totalspace) {
180
if ($element eq $fsid1) {
181
my $warning_result = $totalspace{$element}*(100-$warning)/100;
182
my $critical_result = $totalspace{$element}*(100-$critical)/100;
183
my $result_percent = $freespace{$element}*100/$totalspace{$element};
184
if (($freespace{$element} <= $warning_result) && ($freespace{$element} >= $critical_result)) {
185
printf "Only %d M (%d%s) free\n",$freespace{$element}/1024,$result_percent,"%";
187
} elsif ($freespace{$element} <= $critical_result) {
188
printf "Only %d M (%d%s) free\n",$freespace{$element}/1024,$result_percent,"%";
191
printf "Disk ok - %d M (%d%s) free\n",$freespace{$element}/1024,$result_percent,"%";
196
print "$fsid1 doesn't exist in $target_host\n\n";
201
my ($cpu, $warn, $crit) = @_;
203
print "Critical- 5-min load: $cpu\n";
205
} elsif ($cpu >= $warn) {
206
print "Warning - 5-min load: $cpu\n";
209
print "Load ok - 5-min load: $cpu\n";