#!/usr/bin/perl # This Plugin checks the sam Components of 3com Switches (fan, temp-sensors, power supply) # # # Copyright (c) 2008 Sascha Tentscher , # http://www.nagios-portal.org/wbb/index.php?page=Thread&threadID=9746 # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-130 use strict; use Net::SNMP; if ($#ARGV == -1) { print_help(); } my %status = ( 'UNKNOWN' => '-1', 'OK' => '0', 'WARNING' => '1', 'CRITICAL' => '2' ); my %unitstates = ( '1' => 'uknw', '2' => 'inactive', '3' => 'operational', '4' => 'loading' ); my %entitystate = ( '1' => 'unknw', '2' => 'initialising', '3' => 'idle', '4' => 'OK', '5' => 'failure', '6' => '-' ); my %entityfaultnum = ( 'fan_1' => 'fan is slow', 'fan_2' => 'fan stopped', 'temp_1' => 'temperatue is warm', 'temp_2' => 'temperatue is critical', 'temp_3' => 'temperatue is too high', 'psu_1' => 'not working', 'psu_2' => 'temperatue is critical', 'psu_3' => 'temperatue is too high', 'exp_1' => 'test failed', 'exp_2' => 'unsupported', 'exp_3' => 'power up fail', 'exp_4' => 'temperatue is critical', 'exp_5' => 'temperatue is too high', 'exp_6' => 'reset requires', 'exp_7' => 'unknown failure', 'exp_8' => 'not in use' ); sub pars_args { my $ip = ""; my $community = ""; my $unit = ""; while($ARGV[0] =~/^-/) { if($ARGV[0] =~/^-H|^--host/) { $ip = $ARGV[1]; shift @ARGV; shift @ARGV; next; } if($ARGV[0] =~/^-C|^--Commuity/) { $community = $ARGV[1]; shift @ARGV; shift @ARGV; next; } if($ARGV[0] =~/^-u|^--Unit/) { $unit = $ARGV[1]; shift @ARGV; shift @ARGV; next; } } return ($ip, $community, $unit); } sub print_help() { print "Usage: check_3com -H host -C community -u unit\n"; print "Options:\n"; print " -H --host STRING or IPADDRESS\n"; print " Check interface on the indicated host.\n"; print " -C --community STRING\n"; print " Community-String for SNMP-Walk.\n"; print " -u --unit INT\n"; print " Unit welche gecheckt werden soll.\n"; exit($status{"UNKNOWN"}); } sub get_snmp_session { my $ip = $_[0]; my $community = $_[1]; my ($session, $error) = Net::SNMP->session( -hostname => $ip, -community => $community, -port => 161, -timeout => 1, -retries => 3, -translate => [-timeticks => 0x0] #schaltet Umwandlung von Timeticks in Zeitformat aus ); return ($session, $error); } sub close_snmp_session { my $session = $_[0]; $session->close(); } sub get_snmp_request { my $session = $_[0]; my $oid = $_[1]; return $session->get_request($oid); } sub get_snmp_table { my $session = $_[0]; my $oid = $_[1]; return $session->get_table($oid); } my ($ip, $community, $unit) = pars_args(); my ($session, $error) = get_snmp_session($ip, $community); my $oid_unitdesc = ".1.3.6.1.4.1.43.10.27.1.1.1.5.".$unit; my $oid_unitstate = ".1.3.6.1.4.1.43.10.27.1.1.1.7.".$unit; my $oid_phsysentityname = ".1.3.6.1.4.1.43.43.1.1.7.".$unit; my $oid_phsysentitystate = ".1.3.6.1.4.1.43.43.1.1.8.".$unit; my $oid_phsysentityfaultnum = ".1.3.6.1.4.1.43.43.1.1.9.".$unit; my $oid_phsysentityfault = ".1.3.6.1.4.1.43.43.1.1.10.".$unit; my %result = %{get_snmp_request($session, $oid_unitdesc)}; my $unitdesc = $result{$oid_unitdesc}; %result = %{get_snmp_request($session, $oid_unitstate)}; my $unitstate = $result{$oid_unitstate}; my %result1 = %{get_snmp_table($session, $oid_phsysentityname)}; my %result2 = %{get_snmp_table($session, $oid_phsysentitystate)}; my %result3 = %{get_snmp_table($session, $oid_phsysentityfaultnum)}; my %result4 = %{get_snmp_table($session, $oid_phsysentityfault)}; my $counter = 0; my @phsysentityname; my @phsysentitystate; my @phsysentityfaultnum; my @phsysentityfault; foreach my $oid(sort keys %result1) { $phsysentityname[$counter] = $result1{$oid}; $counter++; } $counter = 0; foreach my $oid(sort keys %result2) { $phsysentitystate[$counter] = $result2{$oid}; $counter++; } $counter = 0; foreach my $oid(sort keys %result3) { $phsysentityfaultnum[$counter] = $result3{$oid}; $counter++; } $counter = 0; foreach my $oid(sort keys %result4) { $phsysentityfault[$counter] = $result4{$oid}; $counter++; } close_snmp_session($session); my $string = $unitdesc." state is ".$unitstates{$unitstate}."
"; my $pre = ""; for(my $i =0; $i<$counter; $i++) { $string .= $phsysentityname[$i]." ".$entitystate{$phsysentitystate[$i]}; if($phsysentitystate[$i] == 5) { if($phsysentityname[$i] =~/fan/) { $pre = "fan"; } elsif($phsysentityname[$i] =~/temp/) { $pre = "temp"; } elsif($phsysentityname[$i] =~/PSU/) { $pre = "psu"; } else { $pre = "exp"; } $string .= "Error ".$entityfaultnum{$pre."_".$phsysentityfaultnum[$counter]}." (".$phsysentityfault[$counter]."}"; } $string .= "
"; } my $state = "OK"; if($string =~/uknw/) { $state = "UNKNOW"; } if($string =~/inactive|notpresent/) { $state = "WARNING"; } if($string =~/Error/) { $state = "CRITICAL"; } print $string."\n"; exit($status{$state});