Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / snmp / snmp__ups_ @ e5ce7492

Historique | Voir | Annoter | Télécharger (9,29 ko)

1
#!/usr/bin/perl
2
#
3
# Copyright (C) 2008 Gorlow Maxim [Sheridan]
4
#
5
# This program is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU General Public License
7
# as published by the Free Software Foundation; version 2 dated June,
8
# 1991.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
#
19

    
20
#	ups_host_volt - IO voltage (volt)
21
#	ups_host_freq - IO frequency (hz)
22
#	ups_host_status - UPS status (online, off....)
23
#	ups_host_temp - Temperature (c)
24
#	ups_host_battcap - Battery capacity (%)
25
#	ups_host_load - UPS load (%)
26
#	ups_host_curr - Current (ampers)
27

    
28

    
29

    
30

    
31
#
32
#%# family=snmpauto
33
#
34

    
35
use strict;
36
use SNMP '5.0.2.pre1' || die("Cannot load module\n");
37
$ENV{'MIBS'}="ALL";
38

    
39
my $host      = $ENV{host}      || undef;
40
my $community = $ENV{community} || "public";
41
my $type      = "volt";
42
my $response;
43

    
44
if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_ups_(.+)$/)
45
{
46
    $host = $1;
47
    $type = $2;
48
    if ($host =~ /^([^:]+):(\d+)$/)
49
    {
50
	$host = $1;
51
	$type = $2;
52
    }
53
}
54
elsif (!defined($host)) {
55
	die "# Error: couldn't understand what I'm supposed to monitor."; }
56

    
57

    
58
my $session = new SNMP::Session   (
59
				    DestHost => $host,
60
				    Community => $community,
61
	        		    Version => 1
62
				  );
63
my $oidsList;
64
my $modelList = new SNMP::VarList(['upsBasicIdentModel'],['upsAdvIdentSerialNumber']);
65
if ($type eq "volt")
66
{
67
    $oidsList = new SNMP::VarList (
68
		    ['upsAdvOutputVoltage'],
69
		    ['upsAdvInputLineVoltage'],
70
		    ['upsAdvInputMaxLineVoltage'],
71
		    ['upsAdvInputMinLineVoltage']
72
		);
73
}
74
elsif ($type eq "freq")
75
{
76
    $oidsList = new SNMP::VarList (
77
		    ['upsAdvOutputFrequency'],
78
		    ['upsAdvInputFrequency']
79
		);
80
}
81
elsif ($type eq "status")
82
{
83
    $oidsList = new SNMP::VarList (
84
		    ['upsBasicOutputStatus']
85
		);
86
}
87
elsif ($type eq "temp")
88
{
89
    $oidsList = new SNMP::VarList (
90
		    ['upsAdvBatteryTemperature']
91
		);
92
}
93
elsif ($type eq "battcap")
94
{
95
    $oidsList = new SNMP::VarList (
96
		    ['upsAdvBatteryCapacity']
97
		);
98
}
99
elsif ($type eq "load")
100
{
101
    $oidsList = new SNMP::VarList (
102
		    ['upsAdvOutputLoad']
103
		);
104
}
105
elsif ($type eq "curr")
106
{
107
    $oidsList = new SNMP::VarList (
108
		    ['upsAdvOutputCurrent']
109
		);
110
}
111
#if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")																																																																										
112
#{}
113

    
114
if ($ARGV[0] and $ARGV[0] eq "config")
115
{
116

    
117
    my $model;
118
    my $vLabel;
119
    my $hLabel;
120
    if ($type eq "volt")
121
    {
122
	$vLabel = "Voltage";
123
	$hLabel = "IO Voltage";
124
    }
125
    elsif ($type eq "freq") 
126
    {
127
	$vLabel = "Frequency";
128
	$hLabel = "IO Frequency";
129
    }
130
    elsif ($type eq "status")
131
    {
132
	$vLabel = "Status";
133
	$hLabel = "Status";
134
    }
135
    elsif ($type eq "temp")
136
    {
137
	$vLabel = "Temperature, C";
138
	$hLabel = "Temperature";
139
    }
140
    elsif ($type eq "battcap")
141
    {
142
	$vLabel = "Percent";
143
	$hLabel = "Batt. capacity";
144
    }
145
    elsif ($type eq "load")
146
    {
147
	$vLabel = "Percent";
148
	$hLabel = "UPS load";
149
    }
150
    elsif ($type eq "curr")
151
    {
152
	$vLabel = "Ampers";
153
	$hLabel = "Current";
154
    }
155
    print "host_name $host\n" unless $host eq 'localhost';
156
    my @response = $session->getnext($modelList);
157
    $response[0] =~ s/[\" ]//g;        # Ditch the quotes.
158
    $response[1] =~ s/[\" ]//g;
159
    $model = "$response[0] [$response[1]]";
160
    print "graph_title $hLabel, $model\n";
161
    print "graph_args --base 1000\n";
162
    print "graph_vlabel $vLabel\n";
163
    print "graph_category system\n";
164
    print "graph_info This graph shows the $hLabel ($vLabel) of $model\n";
165
    if ($type eq "volt")
166
    {
167
	print "graph_order in out inmax inmin\n";
168
	print "in.label Input\n";
169
        print "in.type GAUGE\n";
170
        print "in.info Input voltage.\n";
171
	print "in.colour FFCC99\n";
172
	print "in.draw AREA\n";
173
	print "out.label Output\n";
174
        print "out.type GAUGE\n";
175
        print "out.info Output voltage.\n";
176
	print "out.colour 009BCC\n";
177
	print "out.draw AREA\n";
178
	print "inmax.label Input max\n";
179
        print "inmax.type GAUGE\n";
180
        print "inmax.info Input voltage maximum.\n";
181
	print "inmax.colour FF0033\n";
182
	print "inmax.draw LINE1\n";
183
	print "inmin.label Input min\n";
184
        print "inmin.type GAUGE\n";
185
        print "inmin.info Input voltage minimum.\n";
186
	print "inmin.colour 66FF00\n";
187
	print "inmin.draw LINE1\n";
188
	
189
    }
190
    elsif ($type eq "freq")
191
    {
192
	print "graph_order in out\n";
193
	print "out.label Output\n";
194
        print "out.type GAUGE\n";
195
	print "out.info Output frequency.\n";
196
	print "out.draw LINE2\n";
197
	print "in.label Input\n";
198
        print "in.type GAUGE\n";
199
        print "in.info Input frequency.\n";
200
	print "in.draw LINE2\n";
201
    }
202
    elsif ($type eq "status")
203
    {
204
	print "state.label Status\n";
205
	print "state.type GAUGE\n";
206
	print "state.draw AREA\n";
207
        print "state.min 1\n";
208
        print "state.max 12\n";
209
	print "unknown.label Unknown\n";
210
	print "unknown.type GAUGE\n";
211
	print "unknown.draw LINE3\n";
212
	print "onLine.label Online\n";
213
	print "onLine.type GAUGE\n";
214
	print "onLine.draw LINE3\n";
215
        print "onBattery.label On Battery\n";
216
	print "onBattery.type GAUGE\n";
217
	print "onBattery.draw LINE3\n";
218
	print "onSmartBoost.label On Smart Boost\n";
219
	print "onSmartBoost.type GAUGE\n";
220
	print "onSmartBoost.draw LINE3\n";
221
	print "timedSleeping.label Timed Sleeping\n";
222
	print "timedSleeping.type GAUGE\n";
223
	print "timedSleeping.draw LINE3\n";
224
	print "softwareBypass.label Software Bypass\n";
225
	print "softwareBypass.type GAUGE\n";
226
	print "softwareBypass.draw LINE3\n";
227
	print "off.label Off\n";
228
	print "off.type GAUGE\n";
229
	print "off.draw LINE3\n";
230
	print "rebooting.label Rebooting\n";
231
	print "rebooting.type GAUGE\n";
232
	print "rebooting.draw LINE3\n";
233
	print "switchedBypass.label Switched Bypass\n";
234
	print "switchedBypass.type GAUGE\n";
235
	print "switchedBypass.draw LINE3\n";
236
	print "hardwareFailureBypass.label HW Failure Bypass\n";
237
	print "hardwareFailureBypass.type GAUGE\n";
238
	print "hardwareFailureBypass.draw LINE3\n";
239
	print "sleepingUntilPowerReturn.label Sleep Until Power Return\n";
240
	print "sleepingUntilPowerReturn.type GAUGE\n";
241
	print "sleepingUntilPowerReturn.draw LINE3\n";
242
	print "onSmartTrim.label On Smart Trim\n";
243
	print "onSmartTrim.type GAUGE\n";
244
	print "onSmartTrim.draw LINE3\n";
245
    }
246
    elsif ($type eq "temp")
247
    {
248
	print "batt.label Battery temperature\n";
249
        print "batt.type GAUGE\n";
250
	print "batt.info Battery temperature.\n";
251
	print "batt.draw LINE2\n";
252
    }
253
    elsif ($type eq "battcap")
254
    {
255
	print "bcap.label Battery capacity\n";
256
        print "bcap.type GAUGE\n";
257
	print "bcap.info Battery capacity.\n";
258
	print "bcap.draw AREA\n";
259
	print "bcap.warning 30\n";
260
	print "bcap.critical 15\n";
261
    }
262
    elsif ($type eq "load")
263
    {
264
	print "load.label UPS load\n";
265
        print "load.type GAUGE\n";
266
	print "load.info UPS load.\n";
267
	print "load.draw AREA\n";
268
	print "load.warning 95\n";
269
	print "load.critical 100\n";
270
    }
271
    elsif ($type eq "curr")
272
    {
273
	print "out.label Output\n";
274
        print "out.type GAUGE\n";
275
	print "out.info Output current\n";
276
	print "out.draw LINE2\n";
277
    }
278
    exit 0;				    
279
}
280

    
281

    
282

    
283
my @response = $session->getnext($oidsList);
284
if ($type eq "volt")
285
{
286
    print "out.value $response[0]\n";
287
    print "in.value $response[1]\n";
288
    print "inmax.value $response[2]\n";
289
    print "inmin.value $response[3]\n";
290
}
291
elsif ($type eq "freq")
292
{
293
    print "out.value $response[0]\n";
294
    print "in.value $response[1]\n";
295
}
296
elsif ($type eq "status")
297
{
298
    my $unknown				= $response[0]==1  || "U";
299
    my $onLine				= $response[0]==2  || "U";
300
    my $onBattery			= $response[0]==3  || "U";
301
    my $onSmartBoost			= $response[0]==4  || "U";
302
    my $timedSleeping			= $response[0]==5  || "U";
303
    my $softwareBypass			= $response[0]==6  || "U";
304
    my $off				= $response[0]==7  || "U";
305
    my $rebooting			= $response[0]==8  || "U";
306
    my $switchedBypass			= $response[0]==9  || "U";
307
    my $hardwareFailureBypass		= $response[0]==10 || "U";
308
    my $sleepingUntilPowerReturn	= $response[0]==11 || "U";
309
    my $onSmartTrim			= $response[0]==12 || "U";
310
    
311
    print "state.value $response[0]\n";
312
    print "unknown.value $unknown\n";
313
    print "onLine.value $onLine\n";
314
    print "onBattery.value $onBattery\n";
315
    print "onSmartBoost.value $onSmartBoost\n";
316
    print "timedSleeping.value $timedSleeping\n";
317
    print "softwareBypass.value $softwareBypass\n";
318
    print "off.value $off\n";
319
    print "rebooting.value $rebooting\n";
320
    print "switchedBypass.value $switchedBypass\n";
321
    print "hardwareFailureBypass.value $hardwareFailureBypass\n";
322
    print "sleepingUntilPowerReturn.value $sleepingUntilPowerReturn\n";
323
    print "onSmartTrim.value $onSmartTrim\n";
324
}
325
elsif ($type eq "temp")
326
{
327
    print "batt.value $response[0]\n";
328
}
329
elsif ($type eq "battcap")
330
{
331
    print "bcap.value $response[0]\n";
332
}
333
elsif ($type eq "load")
334
{
335
    print "load.value $response[0]\n";
336
}
337
elsif ($type eq "curr")
338
{
339
    print "out.value $response[0]\n";
340
}
341

    
342
__END__
343
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")
344
{
345
	print "number  1.3.6.1.2.1.2.1.0\n";
346
	print "index   1.3.6.1.2.1.2.2.1.1.\n";
347
	print "require 1.3.6.1.2.1.2.2.1.3. ^(6|23)\$\n"; # Type
348
	print "require 1.3.6.1.2.1.2.2.1.5. [1-9]\n"; # Speed
349
	exit 0;
350
}