diff options
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/check_fan_cpq_present | 133 | ||||
-rw-r--r-- | contrib/check_fan_fsc_present | 135 | ||||
-rw-r--r-- | contrib/check_mysqlslave.pl | 174 | ||||
-rw-r--r-- | contrib/check_temp_cpq | 162 | ||||
-rw-r--r-- | contrib/check_temp_fsc | 160 |
5 files changed, 764 insertions, 0 deletions
diff --git a/contrib/check_fan_cpq_present b/contrib/check_fan_cpq_present new file mode 100644 index 00000000..476a0c36 --- /dev/null +++ b/contrib/check_fan_cpq_present @@ -0,0 +1,133 @@ +#!/usr/bin/perl +# +# +# check_most.pl -i <ip address> -p <port> -c community -o <oid> [warn] [critical] +# +# NetSaint host script to get the disk usage from NT snmp +# +# Changes and Modifications +# ========================= +# 3-Aug-2000 - Xavier Dusart +# Created +# 2003 - Rainer Duffner + +BEGIN { + if ($0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/) { + $runtimedir = $1; + $PROGNAME = $2; + } +} + + + +require 5.004; +use POSIX; +#use strict; +use Getopt::Std ; +use BER; +require 'SNMP_Session.pm'; +use vars qw($opt_H $opt_p $opt_C $opt_f $opt_h $PROGNAME); +use lib $main::runtimedir; +use utils qw($TIMEOUT %ERRORS &print_revision &usage &support); +use snmputil qw(%CPQ_LOCALE %CPQ_FAN_PRESENT %CPQ_FAN_OVERALL_COND %CPQ_FAN_SPEED); + +delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Make %ENV safer + +getopts('H:p:C:f:hV') ; + +my $ip_address=undef ; + +if ($opt_h) {&help();} + +if ($opt_H =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z][-a-zA-Z0-9]*(\.[a-zA-Z][-a-zA +-Z0-9]*)*)$/) { + $ip_address = $opt_H ; + } +else { + usage(); + print "IP-Address format wrong\n"; + exit $ERRORS{'UNKNOWN'}; + } + +#if ($opt_p =~ m/^[0-9] + +my $port = $opt_p; + +my $community = $opt_C; + +my $fan = $opt_f ; + +#my $err_counter=0 ; +#my $err_status=""; + + my $fan_locale_oid = encode_oid (1,3,6,1,4,1,232,6,2,6,7,1,3,0,$fan ); +# not used for the moment - gives no usable output +# if reused, enter at end of list to avoid renumbering ! + my $fan_present_oid = encode_oid (1,3,6,1,4,1,232,6,2,6,7,1,4,0,$fan ); + my $fan_speed_oid = encode_oid (1,3,6,1,4,1,232,6,2,6,7,1,6,0,$fan ); + my $fan_condition_oid = encode_oid (1,3,6,1,4,1,232,6,2,6,7,1,9,0,$fan ); + my $count=1 ; + my $label ; + my @r_array=(); + my $q ; + my $diff ; + $warning=$warning/100 ; + $crititcal=$critical/100 ; + + +# get temperature, temperature_threshold bfore shutdown + my $session=SNMP_Session->open ($ip_address, $community, $port) || die "couldn't open SNMP-session to host" ; + + if ($session->get_request_response ($fan_present_oid, $fan_locale_oid, $fan_speed_oid, $fan_condition_oid )) { + (my $bindings) = $session->decode_get_response ($session->{pdu_buffer}); + while ($bindings ne '') { + ($binding, $bindings) = &decode_sequence ($bindings) ; + ($oid,$value) = &decode_by_template ($binding,"%O%@"); + $r_array[$count]=&pretty_print($value); + $count++; + } + } else { + print "No response from agent\n"; + exit $ERRORS{'CRITICAL'}; + } + $result_fan_present= $r_array[1]; + $result_fan_locale= $r_array[2]; + $result_fan_speed= $r_array[3]; + $result_fan_condition=$r_array[4]; + + + if ( $result_fan_present != 3 || $result_fan_speed !=2 ) { + print "Fan ". $fan . " ".$CPQ_LOCALE{$result_fan_locale}. " (".$result_fan_locale.") - Critical: Fan ".$CPQ_FAN_PRESENT{$result_fan_present}.". Speed: ". $CPQ_FAN_SPEED{$result_fan_speed}.". Overall condition: ". $CPQ_FAN_OVERALL_COND{$result_fan_condition} ."\n" ; + exit $ERRORS{'CRITICAL'} ; + } + else { + print "Fan " .$fan . " ".$CPQ_LOCALE{$result_fan_locale}. " (".$result_fan_locale.") - OK: Fan ".$CPQ_FAN_PRESENT{$result_fan_present}.". Speed: ". $CPQ_FAN_SPEED{$result_fan_speed}.". Overall condition: ". $CPQ_FAN_OVERALL_COND{$result_fan_condition} ."\n" ; + exit $ERRORS{'OK'} ; + } + + +sub print_usage () { + print "Usage: $PROGNAME -H <host> -p <port> -C <community> -f <fannumber>\n"; + } + +sub print_help () { + print_revision($PROGNAME,'$Revision$\n '); + print "Copyright (c) 2003 Rainer Duffner\n "; + print_usage(); + print "\n"; + print "<host> = IP-Address or DNS-Name of the W2K-Server\n"; + print "<port> = SNMP-Port (normaly 161)\n"; + print "<community> = SNMP v1 community\n"; + print "<fannumber> = Fannumber (1, 2, 3 etc.)\n"; + } + +sub version () { + print_revision($PROGNAME,'$Revision$ '); + exit $ERRORS{'OK'}; +} + +sub help () { + print_help(); + exit $ERRORS{'OK'}; +} + diff --git a/contrib/check_fan_fsc_present b/contrib/check_fan_fsc_present new file mode 100644 index 00000000..5bddb87c --- /dev/null +++ b/contrib/check_fan_fsc_present @@ -0,0 +1,135 @@ +#!/usr/bin/perl +# +# +# check_most.pl -i <ip address> -p <port> -c community -o <oid> [warn] [critical] +# +# NetSaint host script to get the disk usage from NT snmp +# +# Changes and Modifications +# ========================= +# 3-Aug-2000 - Xavier Dusart +# Created +# 2003 - Rainer Duffner + +BEGIN { + if ($0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/) { + $runtimedir = $1; + $PROGNAME = $2; + } +} + + + +require 5.004; +use POSIX; +#use strict; +use Getopt::Std ; +use BER; +require 'SNMP_Session.pm'; +use vars qw($opt_H $opt_p $opt_C $opt_f $opt_h $PROGNAME); +use lib $main::runtimedir; +use utils qw($TIMEOUT %ERRORS &print_revision &usage &support); +use snmputil qw(%FSC_LOCALE %FSC_FAN_STATUS); + +delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Make %ENV safer + +getopts('H:p:C:f:hV') ; + +my $ip_address=undef ; + +if ($opt_h) {&help();} + +if ($opt_H =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z][-a-zA-Z0-9]*(\.[a-zA-Z][-a-zA +-Z0-9]*)*)$/) { + $ip_address = $opt_H ; + } +else { + usage(); + print "IP-Address format wrong\n"; + exit $ERRORS{'UNKNOWN'}; + } + +#if ($opt_p =~ m/^[0-9] + +my $port = $opt_p; + +my $community = $opt_C; + +my $fan = $opt_f ; + +#my $err_counter=0 ; +#my $err_status=""; + + my $fan_locale_oid = encode_oid (1,3,6,1,4,1,231,2,10,2,2,5,2,2,1,4,0,$fan-1 ); +# not used for the moment - gives no usable output +# if reused, enter at end of list to avoid renumbering ! + my $fan_cur_speed_oid = encode_oid (1,3,6,1,4,1,231,2,10,2,2,5,2,2,1,8,0,$fan-1 ); + my $fan_nom_max_speed_oid = encode_oid (1,3,6,1,4,1,231,2,10,2,2,5,2,2,1,9,0,$fan-1 ); + my $fan_cur_max_speed_oid = encode_oid (1,3,6,1,4,1,231,2,10,2,2,5,2,2,1,10,0,$fan-1 ); + my $fan_condition_oid = encode_oid (1,3,6,1,4,1,231,2,10,2,2,5,2,2,1,3,0,$fan-1 ); + my $count=1 ; + my $label ; + my @r_array=(); + my $q ; + my $diff ; + $warning=$warning/100 ; + $crititcal=$critical/100 ; + + +# get temperature, temperature_threshold bfore shutdown + my $session=SNMP_Session->open ($ip_address, $community, $port) || die "couldn't open SNMP-session to host" ; + + if ($session->get_request_response ($fan_locale_oid, $fan_cur_speed_oid, $fan_nom_max_speed_oid, $fan_cur_max_speed_oid, $fan_condition_oid )) { + (my $bindings) = $session->decode_get_response ($session->{pdu_buffer}); + while ($bindings ne '') { + ($binding, $bindings) = &decode_sequence ($bindings) ; + ($oid,$value) = &decode_by_template ($binding,"%O%@"); + $r_array[$count]=&pretty_print($value); + $count++; + } + } else { + print "No response from agent\n"; + exit $ERRORS{'CRITICAL'}; + } + $result_fan_locale= $r_array[1]; + $result_fan_cur_speed= $r_array[2]; + $result_fan_nom_max_speed= $r_array[3]; + $result_fan_cur_max_speed= $r_array[4]; + $result_fan_condition=$r_array[5]; + + + if ( $result_fan_condition != "3" ) { + print "Fan ". $fan . " ".$FSC_LOCALE{$result_fan_locale}. " (".$result_fan_locale.") - Critical: Cur./Nom./Cur-Max-Speed: ". $result_fan_cur_speed."/". $result_fan_nom_max_speed."/".$result_fan_cur_max_speed.". Overall condition: ". $FSC_FAN_STATUS{$result_fan_condition} ."\n" ; + exit $ERRORS{'CRITICAL'} ; + } + else { + print "Fan " .$fan . " ".$FSC_LOCALE{$result_fan_locale}. " (".$result_fan_locale.") - OK: Cur./Nom./Cur-Max-Speed: ". $result_fan_cur_speed."/". $result_fan_nom_max_speed."/".$result_fan_cur_max_speed.". Overall condition: ". $FSC_FAN_STATUS{$result_fan_condition} ."\n" ; + exit $ERRORS{'OK'} ; + } + + +sub print_usage () { + print "Usage: $PROGNAME -H <host> -p <port> -C <community> -f <fannumber>\n"; + } + +sub print_help () { + print_revision($PROGNAME,'$Revision$\n '); + print "Copyright (c) 2003 Rainer Duffner\n "; + print_usage(); + print "\n"; + print "<host> = IP-Address or DNS-Name of the W2K-Server\n"; + print "<port> = SNMP-Port (normaly 161)\n"; + print "<community> = SNMP v1 community\n"; + print "<fannumber> = Fannumber (1, 2, 3 etc.)\n"; + } + +sub version () { + print_revision($PROGNAME,'$Revision$ '); + exit $ERRORS{'OK'}; +} + +sub help () { + print_help(); + exit $ERRORS{'OK'}; +} + diff --git a/contrib/check_mysqlslave.pl b/contrib/check_mysqlslave.pl new file mode 100644 index 00000000..ab7af89f --- /dev/null +++ b/contrib/check_mysqlslave.pl @@ -0,0 +1,174 @@ +#!/usr/bin/perl -w +# +# check_mysqlslave.pl - nagios plugin +# +# +# Copyright 2002 Mario Witte +# +# 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-1307, USA. +# +# Credits: +# - Thanks to Christoph Kron <ck@zet.net> for check_ifstatus.pl +# I used check_ifstatus.pl as a layout when writing this +# +# Report bugs to: chengfu@users.sourceforge.net +# +# 20.09.2002 Version 0.1 + + +use strict; +use lib "/usr/local/nagios/libexec"; +use utils qw($TIMEOUT %ERRORS &print_revision &support); + +use DBI; +use DBD::mysql; +use Getopt::Long; +Getopt::Long::Configure('bundling'); + +# Predeclare some variables +my $PROGNAME = 'check_mysqlslave'; +my $REVISION = '0.1'; +my $status; +my $state = 'UNKNOWN'; +my $opt_V; +my $opt_h; +my $port = 3306; +my $hostname; +my $user = 'root'; +my $pass = ''; +my $driver; +my $dbh; +my $query; +my $result; +my $data; + +# Just in case of problems, let's not hang Nagios +$SIG{'ALRM'} = sub { + print ("ERROR: No response from $hostname (alarm timeout)\n"); + exit $ERRORS{"UNKNOWN"}; +}; +alarm($TIMEOUT); + +$status = GetOptions( + "V" => \$opt_V, "version" => \$opt_V, + "h" => \$opt_h, "help" => \$opt_h, + "p=i" => \$port, "port=i" => \$port, + "H=s" => \$hostname, "hostname=s" => \$hostname, + "u=s" => \$user, "user=s" => \$user, + "P=s" => \$pass, "pass=s" => \$pass, + ); + + +if ($status == 0) { + print_help() ; + exit $ERRORS{'OK'}; +} + +if ($opt_V) { + print_revision($PROGNAME,'$Revision$REVISION .' $ '); + exit $ERRORS{'OK'}; +} + +if ($opt_h) { + print_help(); + exit $ERRORS{'OK'}; +} + +if (! utils::is_hostname($hostname)){ + usage(); + exit $ERRORS{"UNKNOWN"}; +} + + +$driver = 'DBI:mysql::'. $hostname; + +eval { + $dbh = DBI->connect($driver, $user, $pass, { RaiseError => 1, PrintError => 0}); +}; +if ($@) { + $status = $@; + if ($status =~ /^.*failed:\ (.+)\ at\ $0/i) { $status = $1; } + $state='CRITICAL'; + print $state .': Connect failed: '."$status\n"; + exit ($ERRORS{$state}); +} + +eval { + $query = 'SHOW SLAVE STATUS'; + $result = $dbh->prepare($query); + $result->execute; + $data = $result->fetchrow_hashref(); + $result->finish(); + $dbh->disconnect(); +}; +if ($@) { + $status = $@; + $status =~ s/\n/ /g; + if ($status =~ /^DB[ID].*(failed|prepare):\ (.+)\ at\ $0/i) { $status = $2; } + $state = 'CRITICAL'; + print $state .': Couldn\'t check slave: '."$status\n"; + exit($ERRORS{$state}); +} + +if ($data->{'Slave_Running'} eq 'Yes') { + $status = 'Replicating from '. $data->{'Master_Host'}; + $state = 'OK'; + print $state .': '. $status ."\n"; + exit($ERRORS{$state}); +} elsif ($data->{'Slave_Running'} eq 'No') { + if (length($data->{'Last_error'}) > 0) { + $status = 'Slave stopped with error message'; + $state = 'CRITICAL'; + print $state .': '. $status ."\n"; + exit($ERRORS{$state}); + } else { + $status = 'Slave stopped without errors'; + $state = 'WARNING'; + print $state .': '. $status ."\n"; + exit($ERRORS{$state}); + } +} else { + $status = 'Unknown slave status: (Running: '. $data->{'Slave_Running'} .')'; + $state = 'UNKNOWN'; + print $state .': '. $status ."\n"; + exit($ERRORS{$state}); +} + +sub usage { + printf "\nMissing arguments!\n"; + printf "\n"; + printf "check_mysqlslave -H <hostname> [-p <port> -u <username> -P <password>]\n"; + printf "Copyright 2002 Mario Witte\n"; + printf "\n\n"; + support(); + exit $ERRORS{"UNKNOWN"}; +} + +sub print_help { + printf "check_mysqlslave plugin for Nagios checks \n"; + printf "if the replication on a backup mysql-server\n"; + printf "is up and running\n"; + printf "\nUsage:\n"; + printf " -H (--hostname) Hostname to query\n"; + printf " -p (--port) mysql port (default: 3306)\n"; + printf " -u (--user) username for accessing mysql host\n"; + printf " (default: root)\n"; + printf " -P (--pass) password for accessing mysql host\n"; + printf " (default: '')\n"; + printf " -V (--version) Plugin version\n"; + printf " -h (--help) usage help \n\n"; + print_revision($PROGNAME, '$Revision$REVISION .' $'); + +} diff --git a/contrib/check_temp_cpq b/contrib/check_temp_cpq new file mode 100644 index 00000000..14b06a2b --- /dev/null +++ b/contrib/check_temp_cpq @@ -0,0 +1,162 @@ +#!/usr/bin/perl +# +# +# check_most.pl -i <ip address> -p <port> -c community -o <oid> [warn] [critical] +# +# NetSaint host script to get the disk usage from NT snmp +# +# Changes and Modifications +# ========================= +# 3-Aug-2000 - Xavier Dusart +# Created +# 2003 - Rainer Duffner +# Note: CPQ starts numbering sensors etc. with "1" + +BEGIN { + if ($0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/) { + $runtimedir = $1; + $PROGNAME = $2; + } +} + + + +require 5.004; +use POSIX; +#use strict; +use Getopt::Std ; +use BER; +require 'SNMP_Session.pm'; +use vars qw($opt_H $opt_p $opt_C $opt_s $opt_w $opt_c $opt_h $PROGNAME); +use lib $main::runtimedir; +use utils qw($TIMEOUT %ERRORS &print_revision &usage &support ); + +use snmputil qw(%CPQ_LOCALE %CPQ_FAN_PRESENT %CPQ_FAN_OVERALL_COND %CPQ_FAN_SPEED); + +delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Make %ENV safer + + +getopts('H:p:C:s:w:c:hV') ; + +my $ip_address=undef ; + +if ($opt_h) {&help();} + +if ($opt_H =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z][-a-zA-Z0-9]*(\.[a-zA-Z][-a-zA +-Z0-9]*)*)$/) { + $ip_address = $opt_H ; + } +else { + usage(); + print "IP-Address format wrong\n"; + exit $ERRORS{'UNKNOWN'}; + } + +#if ($opt_p =~ m/^[0-9] + +my $port = $opt_p; + +my $community = $opt_C; + +my $sensor = $opt_s ; + +my $warning = $opt_w; + +my $critical = $opt_c; + + + my $temperature_locale_oid = encode_oid (1,3,6,1,4,1,232,6,2,6,8,1,3,0,$sensor ); +# not used for the moment - gives no usable output +# if reused, enter at end of list to avoid renumbering ! + my $temperature_celsius_oid = encode_oid (1,3,6,1,4,1,232,6,2,6,8,1,4,0,$sensor ); + my $temperature_threshold_oid = encode_oid (1,3,6,1,4,1,232,6,2,6,8,1,5,0,$sensor ); + my $temperature_condition_oid = encode_oid (1,3,6,1,4,1,232,6,2,6,8,1,6,0,$sensor ); + my $count=1 ; + my $label ; + my @r_array=(); + my $q ; + my $diff ; + $warning=$warning/100 ; + $crititcal=$critical/100 ; + + +# get temperature, temperature_threshold bfore shutdown + my $session=SNMP_Session->open ($ip_address, $community, $port) || die "couldn't open SNMP-session to host" ; + + if ($session->get_request_response ($temperature_celsius_oid, $temperature_threshold_oid, $temperature_condition_oid, $temperature_locale_oid )) { + (my $bindings) = $session->decode_get_response ($session->{pdu_buffer}); + while ($bindings ne '') { + ($binding, $bindings) = &decode_sequence ($bindings) ; + ($oid,$value) = &decode_by_template ($binding,"%O%@"); + $r_array[$count]=&pretty_print($value); + $count++; + } + } else { + print "No response from agent\n"; + exit $ERRORS{'CRITICAL'}; + } + $result_celsius=$r_array[1]; + $result_threshold=$r_array[2]; + $result_condition=$r_array[3]; + $result_locale=$r_array[4]; + + if ($result_celsius < 0) { + print "Result is negative - Sensor unavailable ?\n"; + exit $ERRORS{'UNKNOWN'}; + } + if ($result_threshold==0) { + print "Division by zero \n"; + exit $ERRORS{'CRITICAL'}; + } + + if ($result_condition=="2") { + $result_condition="OK"; + } + else { + $result_condition=$result_condition." (other)"; + } + $q=$result_celsius/$result_threshold ; + $diff=$result_threshold-$result_celsius ; + + + if ( $q > $critical ) { + print "Sensor ". $sensor . " (".$CPQ_LOCALE{$result_locale}.") - Critical: ".$result_celsius." °C - Threshold: ".$result_threshold." °C - Left before shutdown: ".$diff."°C - Overall condition: ". $result_condition ."\n" ; + exit $ERRORS{'CRITICAL'} ; + } + elsif ( $q > $warning ) { + print "Sensor ". $sensor . " (".$CPQ_LOCALE{$result_locale}.") - Warning: ".$result_celsius." °C - Threshold: ".$result_threshold." °C - Left before shutdown: ".$diff."°C - Overall condition: ". $result_condition ."\n" ; + exit $ERRORS{'WARNING'} ; + } + else { + print "Sensor " .$sensor. " (".$CPQ_LOCALE{$result_locale}.") - OK: ".$result_celsius." °C - Threshold: ".$result_threshold." °C - Left before shutdown: ".$diff."°C - Overall condition: ". $result_condition ."\n" ; + exit $ERRORS{'OK'} ; + } + + +sub print_usage () { + print "Usage: $PROGNAME -H <host> -p <port> -C <community> -s <sensornumber> [-w <warn>] [-c <crit>]\n"; + } + +sub print_help () { + print_revision($PROGNAME,'$Revision$\n '); + print "Copyright (c) 2003 Rainer Duffner\n "; + print_usage(); + print "\n"; + print "<host> = IP-Address or DNS-Name of the W2K-Server\n"; + print "<port> = SNMP-Port (normaly 161)\n"; + print "<community> = SNMP v1 community\n"; + print "<sensornumber> = Sensornumber (1, 2, 3 etc.)\n"; + print "<warn> = report warning when more than <warn> % of the temperature is reached defaults to 80\n"; + print "<crit> = report critical when more than <crit> % of the temperature is reached defaults to 90\n"; + } + +sub version () { + print_revision($PROGNAME,'$Revision$ '); + exit $ERRORS{'OK'}; +} + +sub help () { + print_help(); + exit $ERRORS{'OK'}; +} + diff --git a/contrib/check_temp_fsc b/contrib/check_temp_fsc new file mode 100644 index 00000000..6cae859c --- /dev/null +++ b/contrib/check_temp_fsc @@ -0,0 +1,160 @@ +#!/usr/bin/perl +# +# +# check_most.pl -i <ip address> -p <port> -c community -o <oid> [warn] [critical] +# +# NetSaint host script to get the disk usage from NT snmp +# +# Changes and Modifications +# ========================= +# 3-Aug-2000 - Xavier Dusart +# Created +# 2003 - Rainer Duffner + +BEGIN { + if ($0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/) { + $runtimedir = $1; + $PROGNAME = $2; + } +} + + + +require 5.004; +use POSIX; +#use strict; +use Getopt::Std ; +use BER; +require 'SNMP_Session.pm'; +use vars qw($opt_H $opt_p $opt_C $opt_s $opt_w $opt_c $opt_h $PROGNAME); +use lib $main::runtimedir; +use utils qw($TIMEOUT %ERRORS &print_revision &usage &support); +use snmputil qw(%FSC_LOCALE %FSC_TEMP_CONDITION); + +delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Make %ENV safer + + +getopts('H:p:C:s:w:c:hV') ; + +my $ip_address=undef ; + +if ($opt_h) {&help();} + +if ($opt_H =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z][-a-zA-Z0-9]*(\.[a-zA-Z][-a-zA +-Z0-9]*)*)$/) { + $ip_address = $opt_H ; + } +else { + usage(); + print "IP-Address format wrong\n"; + exit $ERRORS{'UNKNOWN'}; + } + +#if ($opt_p =~ m/^[0-9] + +my $port = $opt_p; + +my $community = $opt_C; + +my $sensor = $opt_s ; + +#my $warning = $opt_w; + +#my $critical = $opt_c; + + + my $temperature_locale_oid = encode_oid (1,3,6,1,4,1,231,2,10,2,2,5,2,1,1,4,0,$sensor-1 ); +# not used for the moment - gives no usable output +# if reused, enter at end of list to avoid renumbering ! + my $temperature_celsius_oid = encode_oid (1,3,6,1,4,1,231,2,10,2,2,5,2,1,1,11,0,$sensor-1 ); + my $temperature_warning_oid = encode_oid (1,3,6,1,4,1,231,2,10,2,2,5,2,1,1,6,0,$sensor-1 ); + my $temperature_critical_oid =encode_oid (1,3,6,1,4,1,231,2,10,2,2,5,2,1,1,8,0,$sensor-1 ); + my $temperature_condition_oid = encode_oid (1,3,6,1,4,1,231,2,10,2,2,5,2,1,1,3,0,$sensor-1 ); + my $count=1 ; + my $label ; + my @r_array=(); + my $q ; + my $diff ; + $warning=$warning/100 ; + $crititcal=$critical/100 ; + + +# get temperature, temperature_threshold bfore shutdown + my $session=SNMP_Session->open ($ip_address, $community, $port) || die "couldn't open SNMP-session to host" ; + + if ($session->get_request_response ($temperature_celsius_oid, $temperature_warning_oid, $temperature_critical_oid, $temperature_condition_oid, $temperature_locale_oid )) { + (my $bindings) = $session->decode_get_response ($session->{pdu_buffer}); + while ($bindings ne '') { + ($binding, $bindings) = &decode_sequence ($bindings) ; + ($oid,$value) = &decode_by_template ($binding,"%O%@"); + $r_array[$count]=&pretty_print($value); + $count++; + } + } else { + print "No response from agent\n"; + exit $ERRORS{'CRITICAL'}; + } + $result_celsius=$r_array[1]; + $result_warning=$r_array[2]; + $result_critical=$r_array[3]; + $result_condition=$r_array[4]; + $result_locale=$r_array[5]; + + if ($result_celsius < 0) { + print "Result is negative - Sensor unavailable ?\n"; + exit $ERRORS{'UNKNOWN'}; + } + if ($result_warning==0) { + print "Division by zero \n"; + exit $ERRORS{'CRITICAL'}; + } + + if ($result_critical==0) { + print "Division by zero \n"; + exit $ERRORS{'CRITICAL'}; + } + + +# $q=$result_celsius/$result_threshold ; + $diff=$result_critical-$result_celsius ; + + + if ( $result_celsius > $result_critical ) { + print "Sensor ". $sensor . " (".$FSC_LOCALE{$result_locale}.") - Critical: ".$result_celsius." °C - Crit-Threshold:".$result_critical." °C - Left before shutdown:".$diff."°C - Overall condition: ". $FSC_TEMP_CONDITION{$result_condition} ."\n" ; + exit $ERRORS{'CRITICAL'} ; + } + elsif ( $result_celsius > $result_warning ) { + print "Sensor ". $sensor . " (".$FSC_LOCALE{$result_locale}.") - Warning: ".$result_celsius." °C - Crit-Threshold:".$result_warning." °C - Left before shutdown:".$diff."°C - Overall condition: ". $FSC_TEMP_CONDITION{$result_condition}."\n" ; + exit $ERRORS{'WARNING'} ; + } + else { + print "Sensor " .$sensor. " (".$FSC_LOCALE{$result_locale}.") - OK: ".$result_celsius." °C - Warn-Threshold:".$result_warning." °C - Left before shutdown:".$diff."°C - Overall condition: ". $FSC_TEMP_CONDITION{$result_condition} ."\n" ; + exit $ERRORS{'OK'} ; + } + + +sub print_usage () { + print "Usage: $PROGNAME -H <host> -p <port> -C <community> -s <sensornumber> \n"; + } + +sub print_help () { + print_revision($PROGNAME,'$Revision$\n '); + print "Copyright (c) 2003 Rainer Duffner\n "; + print_usage(); + print "\n"; + print "<host> = IP-Address or DNS-Name of the W2K-Server\n"; + print "<port> = SNMP-Port (normaly 161)\n"; + print "<community> = SNMP v1 community\n"; + print "<drvnumber> = Sensornumber (1, 2, 3 etc.)\n"; + } + +sub version () { + print_revision($PROGNAME,'$Revision$ '); + exit $ERRORS{'OK'}; +} + +sub help () { + print_help(); + exit $ERRORS{'OK'}; +} + |