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
| #!/opt/perl/bin/perl
#
# check multiswap hpux
#
#use strict;
use Getopt::Std;
use vars qw(@swap1 @swap2 $command_line1 $command_line2 %exit_codes $PCT_used1 $P
CT_used2 $Name1 $Name2 $opt_w $opt_c $crit_level $warn_level);
# Predefined exit codes for Nagios
%exit_codes = ('UNKNOWN',-1,
'OK',0,
'WARNING',1,
'CRITICAL',2);
# Command lines to get the data
$command_line1 = `swapinfo -tam | grep lvol2`;
$command_line2 = `swapinfo -tam | grep lvol9`;
# Put the data in tables
chomp $command_line1;
@swap1 = split(/\s+/,$command_line1);
chomp $command_line2;
@swap2 = split(/\s+/, $command_line2);
# Define the calculating scalars
$PCT_used1 = $swap1[4];
$Name1 = $swap1[8];
$PCT_used2 = $swap2[4];
$Name2 = $swap2[8];
# get the options
if ($#ARGV le 0)
{
&usage;
}
else
{
getopts('c:w:');
}
# Error messages
if (!$opt_w or $opt_w == 0 or !$opt_c or $opt_c == 0)
{
print "*** You must define WARN and CRITICAL levels! ***";
&usage;
}
#Check if levels are sane
if ($opt_w >= $opt_c)
{
print "*** WARN level must not be greater than CRITICAL when checking USED memo
ry! ***";
&usage;
}
$warn_level = $opt_w;
$crit_level = $opt_c;
# Tests des seuils
if (($PCT_used1 or PCT_used2) >= $crit_level)
{
print "Swap CRITICAL -- Swap $Name1 : $PCT_used1 used - Swap $Name2 : $PCT_us
ed2 used - (w:$warn_level/c:$crit_level used)\n";
exit $exit_codes{'CRITICAL'};
}
elsif (($PCT_used1 or $PCT_used2) >= $warn_level)
{
print "Swap WARNING -- Swap $Name1 : $PCT_used1 used - Swap $Name2 : $PCT_use
d2 used - (w:$warn_level/c:$crit_level used)\n";
exit $exit_codes{'WARNING'};
}
else
{
print "Swap OK -- Swap $Name1 : $PCT_used1 used - Swap $Name2 : $PCT_used2 us
ed - (w:$warn_level/c:$crit_level used)\n";
exit $exit_codes{'OK'};
}
# Show usage
sub usage()
{
print "\ncheck_multiswap.pl v1.0 - Nagios Plugin\n\n";
print "usage:\n";
print " check_multiswap.pl -w <warnlevel> -c <critlevel>\n\n";
print "options:\n";
print " -w PERCENT Percent USED when WARN\n";
print " -c PERCENT Percent USED when CRITICAL\n";
print "\nexample : ./check_multiswap.pl -w 30 -c 50\n";
exit $exit_codes{'UNKNOWN'};
} |