Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/perl -w
- use strict;
- use warnings;
- use lib "/usr/local/nagios/libexec/";
- use Getopt::Long qw(:config no_ignore_case getopt_compat);
- use vars qw($opt_H $opt_s $opt_w $opt_c $opt_h $opt_d);
- my $stateOK=0;
- my $stateWARNING=1;
- my $stateCRITICAL=2;
- my $stateUNKNOWN=3;
- sub help () {
- print "\nUsage:\n";
- print " check_snmp_sensor -H <host> -s <service name> -w <warning threshold> -c <critical threshold> [-d]\n";
- print " check_snmp_sensor [-h | --help]\n";
- print "\nOptions:\n";
- print " -H, --host\n";
- print " The address of the host\n";
- print " -s, --sensorName\n";
- print " The ILOM sensor to check\n";
- print " -w, --warning\n";
- print " Warning threshold\n";
- print " -c, --critical\n";
- print " Critical threshold\n";
- print " -h, --help\n";
- print " Show this help screen\n";
- print " -d, --debug\n";
- print " Print debug output to help diagnose problems\n";
- }
- if (!GetOptions
- (
- "H|host=s" => \$opt_H,
- "s|sensorName=s" => \$opt_s,
- "w|warning=i" => \$opt_w,
- "c|critical=i" => \$opt_c,
- "h|help" => \$opt_h,
- "d|debug" => \$opt_d,
- )
- )
- {
- print("Supply valid options - see plugin help\n");
- exit $stateUNKNOWN;
- }
- if ($opt_h)
- {
- help();
- exit $stateUNKNOWN;
- }
- if(!defined $opt_H ||
- !defined $opt_s ||
- !defined $opt_w ||
- !defined $opt_c)
- {
- help();
- exit $stateUNKNOWN;
- }
- my $sensorIndex = `snmpwalk -v 2c -c public $opt_H .1.3.6.1.2.1.47.1.1.1.1.7 | grep \"$opt_s\" | sed -e 's/\\./ /g' | awk '{print \$8}' 2>&1`;
- if ($opt_d)
- {
- print "Prechomped Sensor Index:(".$sensorIndex.")\n";
- }
- chomp($sensorIndex);
- if ($opt_d)
- {
- print "Sensor Index:(".$sensorIndex.")\n";
- }
- if ($sensorIndex eq "")
- {
- print("Sensor ($opt_s) not found on host ($opt_H) - is SNMP v2c enabled?\n");
- exit $stateUNKNOWN;
- }
- if ( $? == -1 )
- {
- print("command failed: $!\n");
- exit $stateUNKNOWN;
- }
- else
- {
- system("/usr/local/nagios/libexec/check_snmp -H $opt_H -o .1.3.6.1.4.1.42.2.70.101.1.1.8.1.4.$sensorIndex -C public -P 2c -w $opt_w -c $opt_c");
- my $sensorValueResult = $? >> 8;
- if ($opt_d)
- {
- print "Sensor Return:(".$sensorValueResult.")\n";
- }
- if ( $? == -1 )
- {
- print("command failed: $!\n");
- exit $stateUNKNOWN;
- }
- else
- {
- exit $sensorValueResult;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement