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
| #!/opt/csw/bin/perl -w
use strict;
use Net::SNMP;
use Data::Dumper;
use Getopt::Long;
use Nagios::Plugin;
my $temp;
my $OID = "1.3.6.1.4.1.2021.13.16.5.1.3.1";
my $host = "";
my $community = "public" ;
my $warn = "" ;
my $crit = "" ;
Getopt::Long::Configure ("bundling");
GetOptions ( 'H:s' => \$host,
'C:s'=> \$community,
'w:s' => \$warn,
'c:s' => \$crit)
or die("Error in command line arguments\n");
#print " Flag host $host\n Flag community $community\n Flag Warning $warn\n Flag Critical $crit\n";
# requires a hostname and a community string as its arguments
(my $session, my $error) = Net::SNMP->session(Hostname => $host,Community => $community);
die "session error: $error" unless ($session);
# Check OID temp CPU
# 1.3.6.1.4.1.2021.13.16.5.1.3.1
#my $result = $session->get_request("1.3.6.1.4.1.2021.13.16.5.1.3.1");
my $result = $session->get_request($OID);
die "request error: ".$session->error unless (defined $result);
$session->close;
# Affichache de la valeur result
# print Dumper $result;
foreach my $cle (keys(%{$result})){
$temp =$result->{$cle} ;
}
$temp=$temp/1000 ;
#print "Température CPU $temp C\n";
#Preparation du Plugin Nagios
my $VERSION = 'Beta';
my $LICENCE
= "Ce plugin Nagios est gratuit et libre de droits, et vous pouvez l'utiliser à votre convenance."
. ' Il est livré avec ABSOLUMENT AUCUNE GARANTIE.';
my $plugin_nagios = Nagios::Plugin->new(
shortname => 'Verification Temperature CPU',
usage =>
'Usage : %s [-H=<hostname>] [-C=<community>] [-c=<critical threshold> ] [ -w=<warning threshold> ]',
version => $VERSION,
license => $LICENCE,
);
if ( $temp < $warn ) {
$plugin_nagios-> nagios_exit (OK, " - $temp C");
# exit 0;
}
if ( $temp > $crit ) {
$plugin_nagios->nagios_exit(CRITICAL, " - $temp C");
# exit 2;
}
else {
$plugin_nagios->nagios_exit(WARNING, " - $temp C");
# exit 1;
}
#__END__ |
Partager