This repository has been archived by the owner on Feb 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New plugin to check Blade switches' temperature sensors.
- Loading branch information
Showing
1 changed file
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
#!/usr/bin/perl -w | ||
#=============================================================================== | ||
# Name : check_cisco_cpu_module.pl | ||
# Author : Thibaut COURVOISIER <thibaut.courvoisier-ext@faurecia.com> | ||
# License : Creative Commons Attribution-Noncommercial-Share Alike 2.0 France | ||
# Description : Check which CPU module is active on Cisco Core Switch. | ||
#------------------------------------------------------------------------------- | ||
# This work is licensed under the | ||
# Creative Commons Attribution-Noncommercial-Share Alike 2.0 France License. | ||
# To view a copy of this license, visit | ||
# http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ or send a letter to | ||
# | ||
# Creative Commons | ||
# 171 Second Street, Suite 300 | ||
# San Francisco, California | ||
# 94105, USA. | ||
#=============================================================================== | ||
|
||
use strict; | ||
use Net::SNMP; | ||
use Getopt::Long; | ||
#use Data::Dumper::Simple; | ||
use File::Basename; | ||
|
||
# Program info | ||
my $plugin_name = basename($0); | ||
|
||
# SNMP info | ||
my $session; | ||
my $error; | ||
my $oid_temp_sensor_1 = '.1.3.6.1.4.1.1872.2.5.1.3.1.22.0'; #Value of the primary sensor | ||
my $oid_temp_sensor_2 = '.1.3.6.1.4.1.1872.2.5.1.3.1.23.0'; #Value of secondary sensor | ||
my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4); | ||
|
||
|
||
# Command line arguments | ||
my $o_hostname = ''; | ||
my $o_community = ''; | ||
my $o_help = undef; | ||
|
||
|
||
# Linking arguments | ||
GetOptions( | ||
'H=s' => \$o_hostname, | ||
'C=s' => \$o_community, | ||
'help' => \$o_help | ||
); | ||
|
||
# Checking arguments | ||
if (defined($o_help)) { help(); exit 3; } | ||
if (!defined($o_hostname) || !defined($o_community)) { help(); print "\nMissing hostname or SNMP community arguments. Check syntax.\n"; exit 3; } | ||
|
||
sub print_usage { | ||
print "Usage: $plugin_name -C <snmp_community> -H <hostname/ip_address> ]\n"; | ||
} | ||
|
||
sub print_description { | ||
print <<EOT; | ||
Description: | ||
Check which temperature sensor are in good health. | ||
EOT | ||
} | ||
|
||
sub help { | ||
print "\n==== $plugin_name ====\n\n"; | ||
print "Creative Commons Attribution-Noncommercial-Share Alike 2.0 France\n"; | ||
print "(c)2010 Thibaut COURVOISIER, <thibaut.courvoisier-ext\@faurecia.com>\n\n"; | ||
print_description(); | ||
print_usage(); | ||
print <<EOT; | ||
--help | ||
Print this help message. | ||
-H | ||
Hostname or IP address. | ||
-C | ||
SNMP Community. | ||
EOT | ||
} | ||
|
||
sub temp_sensor { | ||
my $error=""; | ||
my $nagios_output = ""; | ||
my $nagios_long_output = ""; | ||
my $cpt_error = 0; | ||
my $resultat1 = $session->get_request($oid_temp_sensor_1); #43.5 C (Warn at 90.0 C/Recover at 80.0 C) | ||
my $resultat2 = $session->get_request($oid_temp_sensor_2); #43.5 C (Warn at 90.0 C/Recover at 80.0 C) | ||
|
||
my @temp_elements = split(" ", $$resultat1{$oid_temp_sensor_1}); # séparation de : 43.5 C (Warn at 90.0 C/Recover at 80.0 C) | ||
my $temp = $temp_elements[0]; # reccupération de : 43.5 | ||
|
||
|
||
my @temp2_elements = split(" ", $$resultat2{$oid_temp_sensor_2}); # séparation de : 43.5 C (Warn at 90.0 C/Recover at 80.0 C) | ||
my $temp2 = $temp2_elements[0]; # reccupération de : 43.5 | ||
|
||
|
||
if (!defined($resultat1 or $resultat2)) { | ||
printf("ERROR: Description table : %s.\n", $session->error); | ||
$session->close; | ||
exit $ERRORS{"UNKNOWN"}; | ||
} | ||
|
||
if ($temp > 55) { | ||
$cpt_error = $cpt_error + 1; | ||
$nagios_long_output = "WARNING: Primary temperature sensor is above the warning threshold !\n"; | ||
$error = $ERRORS{"WARNING"}; | ||
|
||
} | ||
|
||
if ($temp2 > 55) { | ||
$cpt_error = $cpt_error + 1; | ||
$nagios_long_output .= "WARNING: Secondary temperature sensor is above the warningthreshold !\n"; | ||
$error = $ERRORS{"WARNING"}; | ||
} | ||
|
||
|
||
if($temp > 70){ | ||
$cpt_error = $cpt_error + 1; | ||
$nagios_long_output .= "CRITICAL: Primary temperature sensor is above the critical threshold !\n"; | ||
$error = $ERRORS{"CRITICAL"}; | ||
} | ||
|
||
if($temp2 > 70){ | ||
$cpt_error = $cpt_error + 1; | ||
$nagios_long_output .= "CRITICAL: Secondary temperature sensor is above the critical threshold !\n"; | ||
$error = $ERRORS{"CRITICAL"}; | ||
} | ||
|
||
|
||
if($cpt_error >= 1 ){ | ||
$nagios_output = "Click to see that temperature sensor is above the threshold"; | ||
$nagios_long_output .= "Primary sensor: ".$temp."\n"; | ||
$nagios_long_output .= "Secondary sensor: ".$temp2."\n"; | ||
$nagios_output .= "\n".$nagios_long_output; | ||
return $nagios_output; | ||
$session->close; | ||
exit $error; | ||
} | ||
|
||
else{ | ||
$nagios_output = "OK: Temperature sensor are in good health.\n"; | ||
$nagios_long_output .= "Primary sensor: ".$temp."\n"; | ||
$nagios_long_output .= "Secondary sensor: ".$temp2."\n"; | ||
|
||
return $nagios_output.$nagios_long_output; | ||
} | ||
} | ||
|
||
($session, $error) = Net::SNMP->session( | ||
-hostname => $o_hostname, | ||
-version => 2, | ||
-community => $o_community, | ||
-port => 161, | ||
-timeout => 10 | ||
); | ||
|
||
if (!defined($session)) { | ||
printf("ERROR opening session: %s.\n", $error); | ||
exit 3; | ||
} | ||
|
||
print temp_sensor(); |