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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
diff -Nru nagiosplug/plugins-scripts/check_snmp_mgeups.pl nagiosplug-check_snmp_mgeups/plugins-scripts/check_snmp_mgeups.pl
--- nagiosplug/plugins-scripts/check_snmp_mgeups.pl 1970-01-01 01:00:00.000000000 +0100
+++ nagiosplug-check_snmp_mgeups/plugins-scripts/check_snmp_mgeups.pl 2005-09-21 13:51:12.000000000 +0200
@@ -0,0 +1,271 @@
+#!/usr/bin/perl
+
+#-----------------------------------------------------------------
+#Copyright 2005 Ignacio Barrientos <chipi@criptonita.com>
+#
+#This perl script query an UM_LINK unit via SNMP and grab some
+#useful information applied to determine the status of the UPS
+#to send it to Nagios.
+#
+#Thanks to José Beites, who gave me access to a MGE COMET S31 UPS
+#and UM-LINK unit.
+#
+#Thanks to check_snmp_apcups.pl
+#
+#This program is free software; you can redistribute it or modify
+#it under the terms of the GNU General Public License
+#-----------------------------------------------------------------
+
+# READ CAREFULLY BEFORE USE THIS SCRIPT:
+#
+# Please execute the script before use it with Nagios to test
+# if the oid's are OK, a message will be printed if there are
+# some problems with the oid's configuration.
+#
+# Thank you.
+
+
+use Net::SNMP;
+use Getopt::Std;
+
+$script_name = "check_snmp_mgeups";
+$script_version = "0.1";
+
+## CONNECTION STUFF ##
+$ipaddress = ""; # there is not default ip address, sorry
+$version = 1; # SNMP version, old UM_LINK hw works with version 1!!.
+$timeout = 2; # SNMP query timeout
+$defaultcommunity = "public"; # Default community string
+
+$warn_batt_level = 20; # battery level (%) that set a WARNING status.
+$crit_batt_level = 10; # battery level (%) that set a CRITICAL status.
+$warn_temp = 30; # temperature (degrees) that set a WARNING status.
+$warn_overload = 70; # output overload (%) that set WARNING status.
+
+##################################################
+## ##
+## DONT CHANGE NOTHING UNDER THIS LINE ##
+## ##
+##################################################
+
+## INTERESTING DEFINES ##
+my $OK = 0;
+my $WARNING = 1;
+my $CRITICAL = 2;
+
+## RETURN INFO VARIABLES ##
+$status = $OK;
+$returnstring = "";
+
+## OID LIST ##
+$oid_ups_model = ".1.3.6.1.4.1.705.1.1.1.0";
+
+$oid_internal_temp = ".1.3.6.1.4.1.705.1.5.7.0"; # degrees
+
+$oid_battery_porcentage = ".1.3.6.1.4.1.705.1.5.2.0";
+$oid_battery_fault = ".1.3.6.1.4.1.705.1.5.9.0"; # 1 yes, 2 no
+
+$oid_input_outage = ".1.3.6.1.4.1.705.1.6.4.0"; # 1: ok, 2: voltage out tolerance, 3: freq out tolerance, 4: no voltage.
+
+$oid_output_overload = ".1.3.6.1.4.1.705.1.7.2.1.4.1"; # %
+$oid_output_on_bypass = ".1.3.6.1.4.1.705.1.7.3.0"; # 1: yes, 2: no
+
+## NOT USED ##
+# $oid_battery_voltage = ".1.3.6.1.4.1.705.1.5.5.0"; # dV
+# $oid_input_voltage = ".1.3.6.1.4.1.705.1.6.2.1.2.1"; # dV
+# $oid_output_voltage = ".1.3.6.1.4.1.705.1.7.2.1.2.1"; # dV
+
+$oid_generic = $oid_ups_model;
+
+## PERSONALIZED DATA VARIABLES ##
+$temp = 0;
+
+$batt_level = 0;
+$batt_fault = 0;
+
+$in_outage = 0;
+
+$out_overload = 0;
+$out_bypass = 0;
+
+## FETCHING ARGS STUFF ##
+if (@ARGV < 1) {
+ print "\nERROR: Too few arguments\n";
+ usage();
+}
+
+getopts("h:H:C:w:c:");
+
+if ($opt_h)
+{
+ usage();
+ exit(0);
+}
+
+$ipaddress = $opt_H;
+
+if ($opt_C)
+{
+ $defaultcommunity = $opt_C;
+}
+
+## MAKING SNMP CONNECTION ##
+my ($s, $e) = Net::SNMP->session(
+ -community => $defaultcommunity,
+ -hostname => $ipaddress,
+ -version => $version,
+ -timeout => $timeout,
+);
+
+## TESTING SNMP CONNECTION WITH A GENERIC QUERY ##
+if (!defined($s->get_request($oid_generic)))
+{
+ $returnstring = "SNMP server not responding, host down?";
+ $status = $CRITICAL;
+}
+else
+{
+ ## DOING ALL WORK ##
+ main();
+}
+
+## CONNECTION TO /DEV/NULL ##
+$s->close();
+
+## STUDYING THE OUTPUT ##
+if ($status == $OK)
+{
+ $returnstring = "- No problems.";
+ print "Status is OK $returnstring\n";
+}
+elsif ($status == $WARNING)
+{
+ print "Status is a WARNING level $returnstring\n";
+}
+elsif ($status == $CRITICAL)
+{
+ print "Status is CRITICAL $returnstring\n";
+}
+
+## GOOD BYE ##
+exit $status;
+
+##
+## getinfo: make a snmp query with OID (arg0) and put it in arg1.
+
+sub getinfo
+{
+ if(!defined($s->get_request(@_[0])))
+ {
+ print "OID ";
+ print @_[0];
+ print " not exists, and can't be checked, skipping\n";
+ $_[1] = undef;
+ return;
+ }
+
+ foreach ($s->var_bind_names()) {
+ $_[1] = $s->var_bind_list()->{$_};
+ }
+}
+
+##
+## main: all queries and sets
+
+sub main
+{
+
+ ## GETTING DATA ##
+
+ getinfo($oid_internal_temp,$temp);
+ getinfo($oid_battery_porcentage,$batt_level);
+ getinfo($oid_battery_fault,$batt_fault);
+ getinfo($oid_input_outage,$in_outage);
+ getinfo($oid_output_overload,$out_overload);
+ getinfo($oid_output_on_bypass,$out_bypass);
+
+ ## STUDYING STATUS LEVEL LOOKING SOME ISSUES ##
+
+ ## THINGS CAN CHANGE STATUS TO: WARNING ##
+
+ if( defined($batt_level) && ($batt_level < $warn_batt_level) )
+ {
+ $status = $WARNING;
+ $returnstring = " - Battery level is under ";
+ $returnstring = "$returnstring$warn_batt_level";
+ $returnstring = "$returnstring%.";
+ }
+
+ if( defined($temp) && ($temp > $warn_temp) )
+ {
+ $status = $WARNING;
+ $returnstring = "$returnstring - Max temperature exceeded";
+ }
+
+ if( defined($out_overload) && ($out_overload > $warn_overload) )
+ {
+ $status = $WARNING;
+ $returnstring = "$returnstring - Output overloaded";
+ }
+
+ ## THINGS CAN CHANGE STATUS TO: CRITICAL ##
+
+ if( defined($batt_level) && ($batt_level < $crit_batt_level) )
+ {
+ $status = $CRITICAL;
+ $returnstring = " - Battery level is under ";
+ $returnstring = "$returnstring$crit_batt_level";
+ $returnstring = "$returnstring%.";
+ }
+
+ if( defined($batt_fault) && ($batt_fault eq 1) )
+ {
+ $status = $CRITICAL;
+ $returnstring = "$returnstring - Battery fail";
+ }
+
+ if( defined($in_outage) && (! $in_outage eq 1) )
+ {
+ $status = $CRITICAL;
+ $returnstring = "$returnstring - AC input fail";
+ }
+
+ if( defined($out_bypass) && ($out_bypass eq 1) )
+ {
+ $status = $CRITICAL;
+ $returnstring = "$returnstring - System in BY PASS mode";
+ }
+
+}
+
+##
+## usage: self explaining
+
+sub usage {
+ print << "USAGE";
+
+-----------------------------------------------------------------
+$script_name v$script_version
+
+Monitors MGE UPS via SNMP v1.
+
+Usage: $script_name -H <hostname> [-C <community>]
+
+Options: -H Hostname or IP address
+ -C Community (default is public)
+
+-----------------------------------------------------------------
+Copyright 2005 Ignacio Barrientos <chipi\@criptonita.com>
+
+Thanks to José Beites, who gave me access to a MGE COMET S31 UPS
+and UM-LINK unit.
+
+Thanks to check_snmp_apcups.pl
+
+This program is free software; you can redistribute it or modify
+it under the terms of the GNU General Public License
+-----------------------------------------------------------------
+
+USAGE
+ exit 1;
+}
diff -Nru nagiosplug/plugins-scripts/Makefile.am nagiosplug-check_snmp_mgeups/plugins-scripts/Makefile.am
--- nagiosplug/plugins-scripts/Makefile.am 2003-07-02 17:01:22.000000000 +0200
+++ nagiosplug-check_snmp_mgeups/plugins-scripts/Makefile.am 2005-09-21 13:56:57.000000000 +0200
@@ -7,12 +7,12 @@
libexec_SCRIPTS = check_breeze check_disk_smb check_flexlm check_ircd \
check_log check_ntp check_oracle check_rpc check_sensors check_wave \
check_ifstatus check_ifoperstatus check_mailq check_file_age \
- utils.sh utils.pm
+ check_snmp_mgeups utils.sh utils.pm
EXTRA_DIST=check_breeze.pl check_disk_smb.pl check_flexlm.pl check_ircd.pl \
check_log.sh check_ntp.pl check_oracle.sh check_rpc.pl check_sensors.sh \
check_ifstatus.pl check_ifoperstatus.pl check_wave.pl check_mailq.pl check_file_age.pl \
- utils.sh.in utils.pm.in t
+ check_snmp_mgeups.pl utils.sh.in utils.pm.in t
TESTS_ENVIRONMENT=perl -I $(top_builddir) -I $(top_srcdir)
diff -Nru nagiosplug/THANKS.in nagiosplug-check_snmp_mgeups/THANKS.in
--- nagiosplug/THANKS.in 2005-09-19 12:58:24.000000000 +0200
+++ nagiosplug-check_snmp_mgeups/THANKS.in 2005-09-21 13:55:43.000000000 +0200
@@ -166,3 +166,4 @@
Sascha Runschke
Ronald Tin
Chester Hosey
+Ignacio Barrientos
|