diff options
Diffstat (limited to 'contrib/check_temp_fsc')
-rw-r--r-- | contrib/check_temp_fsc | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/contrib/check_temp_fsc b/contrib/check_temp_fsc new file mode 100644 index 0000000..6cae859 --- /dev/null +++ b/contrib/check_temp_fsc | |||
@@ -0,0 +1,160 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # | ||
3 | # | ||
4 | # check_most.pl -i <ip address> -p <port> -c community -o <oid> [warn] [critical] | ||
5 | # | ||
6 | # NetSaint host script to get the disk usage from NT snmp | ||
7 | # | ||
8 | # Changes and Modifications | ||
9 | # ========================= | ||
10 | # 3-Aug-2000 - Xavier Dusart | ||
11 | # Created | ||
12 | # 2003 - Rainer Duffner | ||
13 | |||
14 | BEGIN { | ||
15 | if ($0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/) { | ||
16 | $runtimedir = $1; | ||
17 | $PROGNAME = $2; | ||
18 | } | ||
19 | } | ||
20 | |||
21 | |||
22 | |||
23 | require 5.004; | ||
24 | use POSIX; | ||
25 | #use strict; | ||
26 | use Getopt::Std ; | ||
27 | use BER; | ||
28 | require 'SNMP_Session.pm'; | ||
29 | use vars qw($opt_H $opt_p $opt_C $opt_s $opt_w $opt_c $opt_h $PROGNAME); | ||
30 | use lib $main::runtimedir; | ||
31 | use utils qw($TIMEOUT %ERRORS &print_revision &usage &support); | ||
32 | use snmputil qw(%FSC_LOCALE %FSC_TEMP_CONDITION); | ||
33 | |||
34 | delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Make %ENV safer | ||
35 | |||
36 | |||
37 | getopts('H:p:C:s:w:c:hV') ; | ||
38 | |||
39 | my $ip_address=undef ; | ||
40 | |||
41 | if ($opt_h) {&help();} | ||
42 | |||
43 | if ($opt_H =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z][-a-zA-Z0-9]*(\.[a-zA-Z][-a-zA | ||
44 | -Z0-9]*)*)$/) { | ||
45 | $ip_address = $opt_H ; | ||
46 | } | ||
47 | else { | ||
48 | usage(); | ||
49 | print "IP-Address format wrong\n"; | ||
50 | exit $ERRORS{'UNKNOWN'}; | ||
51 | } | ||
52 | |||
53 | #if ($opt_p =~ m/^[0-9] | ||
54 | |||
55 | my $port = $opt_p; | ||
56 | |||
57 | my $community = $opt_C; | ||
58 | |||
59 | my $sensor = $opt_s ; | ||
60 | |||
61 | #my $warning = $opt_w; | ||
62 | |||
63 | #my $critical = $opt_c; | ||
64 | |||
65 | |||
66 | 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 ); | ||
67 | # not used for the moment - gives no usable output | ||
68 | # if reused, enter at end of list to avoid renumbering ! | ||
69 | 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 ); | ||
70 | 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 ); | ||
71 | 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 ); | ||
72 | 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 ); | ||
73 | my $count=1 ; | ||
74 | my $label ; | ||
75 | my @r_array=(); | ||
76 | my $q ; | ||
77 | my $diff ; | ||
78 | $warning=$warning/100 ; | ||
79 | $crititcal=$critical/100 ; | ||
80 | |||
81 | |||
82 | # get temperature, temperature_threshold bfore shutdown | ||
83 | my $session=SNMP_Session->open ($ip_address, $community, $port) || die "couldn't open SNMP-session to host" ; | ||
84 | |||
85 | if ($session->get_request_response ($temperature_celsius_oid, $temperature_warning_oid, $temperature_critical_oid, $temperature_condition_oid, $temperature_locale_oid )) { | ||
86 | (my $bindings) = $session->decode_get_response ($session->{pdu_buffer}); | ||
87 | while ($bindings ne '') { | ||
88 | ($binding, $bindings) = &decode_sequence ($bindings) ; | ||
89 | ($oid,$value) = &decode_by_template ($binding,"%O%@"); | ||
90 | $r_array[$count]=&pretty_print($value); | ||
91 | $count++; | ||
92 | } | ||
93 | } else { | ||
94 | print "No response from agent\n"; | ||
95 | exit $ERRORS{'CRITICAL'}; | ||
96 | } | ||
97 | $result_celsius=$r_array[1]; | ||
98 | $result_warning=$r_array[2]; | ||
99 | $result_critical=$r_array[3]; | ||
100 | $result_condition=$r_array[4]; | ||
101 | $result_locale=$r_array[5]; | ||
102 | |||
103 | if ($result_celsius < 0) { | ||
104 | print "Result is negative - Sensor unavailable ?\n"; | ||
105 | exit $ERRORS{'UNKNOWN'}; | ||
106 | } | ||
107 | if ($result_warning==0) { | ||
108 | print "Division by zero \n"; | ||
109 | exit $ERRORS{'CRITICAL'}; | ||
110 | } | ||
111 | |||
112 | if ($result_critical==0) { | ||
113 | print "Division by zero \n"; | ||
114 | exit $ERRORS{'CRITICAL'}; | ||
115 | } | ||
116 | |||
117 | |||
118 | # $q=$result_celsius/$result_threshold ; | ||
119 | $diff=$result_critical-$result_celsius ; | ||
120 | |||
121 | |||
122 | if ( $result_celsius > $result_critical ) { | ||
123 | 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" ; | ||
124 | exit $ERRORS{'CRITICAL'} ; | ||
125 | } | ||
126 | elsif ( $result_celsius > $result_warning ) { | ||
127 | 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" ; | ||
128 | exit $ERRORS{'WARNING'} ; | ||
129 | } | ||
130 | else { | ||
131 | 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" ; | ||
132 | exit $ERRORS{'OK'} ; | ||
133 | } | ||
134 | |||
135 | |||
136 | sub print_usage () { | ||
137 | print "Usage: $PROGNAME -H <host> -p <port> -C <community> -s <sensornumber> \n"; | ||
138 | } | ||
139 | |||
140 | sub print_help () { | ||
141 | print_revision($PROGNAME,'$Revision$\n '); | ||
142 | print "Copyright (c) 2003 Rainer Duffner\n "; | ||
143 | print_usage(); | ||
144 | print "\n"; | ||
145 | print "<host> = IP-Address or DNS-Name of the W2K-Server\n"; | ||
146 | print "<port> = SNMP-Port (normaly 161)\n"; | ||
147 | print "<community> = SNMP v1 community\n"; | ||
148 | print "<drvnumber> = Sensornumber (1, 2, 3 etc.)\n"; | ||
149 | } | ||
150 | |||
151 | sub version () { | ||
152 | print_revision($PROGNAME,'$Revision$ '); | ||
153 | exit $ERRORS{'OK'}; | ||
154 | } | ||
155 | |||
156 | sub help () { | ||
157 | print_help(); | ||
158 | exit $ERRORS{'OK'}; | ||
159 | } | ||
160 | |||