Projet

Général

Profil

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

root / plugins / ups / apc__snmp_ @ e5ce7492

Historique | Voir | Annoter | Télécharger (8,63 ko)

1 0e45b0b8 Andriy Yakovlev
#!/usr/bin/perl
2
#
3
# Copyright (C) 2008 Gorlow Maxim [Sheridan]
4
# Copyright (C) 2009 Andrey Yakovlev [Freedom]
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; version 2 dated June,
9
# 1991.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
#
20
21
#	apc_host_snmp_volt - IO voltage (volt)
22
#	apc_host_snmp_freq - IO frequency (hz)
23
#	apc_host_snmp_status - UPS status (online, off....)
24
#	apc_host_snmp_temp - Temperature (c)
25
#	apc_host_snmp_load - UPS and Battery load (%)
26
#	apc_host_snmp_curr - Current (ampers)
27
28
29
30
31
#
32
#%# family=snmpauto
33
#
34
35
use strict;
36
no strict 'refs';
37
38
my $host      = $ENV{host}      || undef;
39
my $community = $ENV{community} || "public";
40
my $type      = "volt";
41
my $response;
42
43
if ($0 =~ /^(?:|.*\/)apc_([^_]*)_snmp_(.+)$/)
44
{
45
    $host = $1 until ($1 eq "");
46
    $type = $2;
47
    if ($host =~ /^([^:]+):(\d+)$/)
48
    {
49
			$host = $1;
50
7			#$port = $2;
51
    }
52
}
53
elsif (!defined($host)) {
54
	die "# Error: couldn't understand what I'm supposed to monitor."; }
55
56
my @snmpParam = ($community,$host);
57
my @oidsList;
58
my @modelList = ('1.3.6.1.4.1.318.1.1.1.1.1.1.0','1.3.6.1.4.1.318.1.1.1.1.2.3.0','1.3.6.1.4.1.318.1.1.1.2.2.3.0');
59
60
if ($type eq "volt")
61
{
62
    @oidsList =    ('1.3.6.1.4.1.318.1.1.1.4.2.1.0',
63
		    '1.3.6.1.4.1.318.1.1.1.3.2.1.0',
64
		    '1.3.6.1.4.1.318.1.1.1.3.2.2.0',
65
		    '1.3.6.1.4.1.318.1.1.1.3.2.3.0');
66
}
67
elsif ($type eq "freq")
68
{
69
		@oidsList = ['upsAdvOutputFrequency'],
70
		    ['upsAdvInputFrequency'];
71
}
72
elsif ($type eq "status")
73
{
74
    @oidsList =  ('1.3.6.1.4.1.318.1.1.1.4.1.1.0 ');
75
}
76
elsif ($type eq "temp")
77
{
78
    @oidsList = 	('1.3.6.1.4.1.318.1.1.1.2.2.2.0',
79
			 '1.3.6.1.4.1.318.1.1.10.2.3.2.1.4.1');
80
}
81
elsif ($type eq "load")
82
{
83
    @oidsList =	    ('1.3.6.1.4.1.318.1.1.1.4.2.3.0',
84
		'1.3.6.1.4.1.318.1.1.1.2.2.1.0');
85
}
86
elsif ($type eq "curr")
87
{
88
    @oidsList = ('upsAdvOutputCurrent');
89
}
90
#if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")																																																																										
91
#{}
92
93
if ($ARGV[0] and $ARGV[0] eq "config")
94
{
95
96
    my $model;
97
    my $vLabel;
98
    my $hLabel;
99
    my $graph_args;
100
   
101
    if ($type eq "volt")
102
    {
103
		$vLabel = "Voltage";
104
		$hLabel = "IO Voltage";
105
		print "graph_order out in inmax inmin\n";
106
		print "in.label Input\n";
107
		print "in.type GAUGE\n";
108
		print "in.info Input voltage.\n";
109
		print "in.colour FFCC99\n";
110
		print "in.draw AREA\n";
111
		print "out.label Output\n";
112
		print "out.type GAUGE\n";
113
		print "out.info Output voltage.\n";
114
		print "out.colour 009BCC\n";
115
		print "out.draw AREA\n";
116
		print "inmax.label Input max\n";
117
		print "inmax.type GAUGE\n";
118
		print "inmax.info Input voltage maximum.\n";
119
		print "inmax.colour FF0033\n";
120
		print "inmax.draw LINE1\n";
121
		print "inmin.label Input min\n";
122
		print "inmin.type GAUGE\n";
123
		print "inmin.info Input voltage minimum.\n";
124
		print "inmin.colour 66FF00\n";
125
		print "inmin.draw LINE1\n";
126
	
127
    }
128
    elsif ($type eq "freq")
129
    {
130
		$vLabel = "Frequency";
131
		$hLabel = "IO Frequency";
132
		print "graph_order in out\n";
133
		print "out.label Output\n";
134
		print "out.type GAUGE\n";
135
		print "out.info Output frequency.\n";
136
		print "out.draw LINE2\n";
137
		print "in.label Input\n";
138
		print "in.type GAUGE\n";
139
		print "in.info Input frequency.\n";
140
		print "in.draw LINE2\n";
141
    }
142
    elsif ($type eq "status")
143
    {
144
		$vLabel = "Status";
145
		$hLabel = "Status";
146
		print "state.label Status\n";
147
		print "state.type GAUGE\n";
148
		print "state.draw AREA\n";
149
		print "state.min 1\n";
150
		print "state.max 12\n";
151
		print "unknown.label Unknown\n";
152
		print "unknown.type GAUGE\n";
153
		print "unknown.draw LINE3\n";
154
		print "onLine.label Online\n";
155
		print "onLine.type GAUGE\n";
156
		print "onLine.draw LINE4\n";
157
		print "onLine.min 0\n";
158
		print "onLine.max 1\n";
159
		print "onLine.warning 1:\n";
160
		print "onBattery.label On Battery\n";
161
		print "onBattery.type GAUGE\n";
162
		print "onBattery.draw LINE4\n";
163
		print "onBattery.min 0\n";
164
		print "onBattery.max 1\n";
165
		print "softwareBypass.label Software Bypass\n";
166
		print "softwareBypass.type GAUGE\n";
167
		print "softwareBypass.draw LINE3\n";
168
		print "off.label Off\n";
169
		print "off.type GAUGE\n";
170
		print "off.draw LINE3\n";
171
		print "rebooting.label Rebooting\n";
172
		print "rebooting.type GAUGE\n";
173
		print "rebooting.draw LINE3\n";
174
		print "switchedBypass.label Switched Bypass\n";
175
		print "switchedBypass.type GAUGE\n";
176
		print "switchedBypass.draw LINE3\n";
177
		print "hardwareFailureBypass.label HW Failure Bypass\n";
178
		print "hardwareFailureBypass.type GAUGE\n";
179
		print "hardwareFailureBypass.draw LINE3\n";
180
    }
181
    elsif ($type eq "temp")
182
    {
183
		$vLabel = "Temperature, C";
184
		$hLabel = "Temperature";
185
		$graph_args = "--upper-limit 35 -l 15";
186
		print "graph_order batt sens1\n";
187
		print "batt.label Battery temperature\n";
188
		print "batt.type GAUGE\n";
189
		print "batt.info Battery temperature.\n";
190
		print "batt.draw LINE2\n";
191
		print "batt.warning 15:30\n";
192
		print "sens1.label Sensor temperature\n";
193
		print "sens1.type GAUGE\n";
194
		print "sens1.info Sensor temperature.\n";
195
		print "sens1.draw LINE2\n";
196
		print "sens1.warning 15:30\n";
197
		print "sens1.critical 10:40\n";
198
   }
199
    elsif ($type eq "load")
200
    {
201
		$vLabel = "Percent";
202
		$hLabel = "UPS load and Batt. capacity ";
203
		$graph_args = "--upper-limit 110 -l 0";  # --rigid
204
		print "graph_order load bcap\n";
205
		print "load.label UPS load\n";
206
		print "load.type GAUGE\n";
207
		print "load.info UPS load.\n";
208
		print "load.draw AREA\n";
209
		print "load.warning 85\n";
210
		print "load.critical 95\n";
211
		print "bcap.label Battery capacity\n";
212
		print "bcap.type GAUGE\n";
213
		print "bcap.info Battery capacity.\n";
214
		print "bcap.draw LINE2\n";
215
		print "bcap.warning 20:\n";
216
		print "bcap.critical 10:\n";
217
    }
218
    elsif ($type eq "curr")
219
    {
220
		$vLabel = "Ampers";
221
		$hLabel = "Current";
222
		print "out.label Output\n";
223
		print "out.type GAUGE\n";
224
		print "out.info Output current\n";
225
		print "out.draw LINE2\n";
226
    }
227
228
		## common part
229
    print "host_name $host\n" unless $host eq 'localhost';
230
    my @response = getSnmpValueArr (\@snmpParam,\@modelList);
231
    $response[0] =~ s/[\" ]//g;        # Ditch the quotes.
232
    $response[1] =~ s/[\" ]//g;
233
    my $rest = $response[2] /6000;
234
    $model = "$response[0] [$response[1]] ";
235
    print "graph_title $hLabel, $response[0]\n";
236
    print "graph_args --base 1000 $graph_args\n";
237
    print "graph_vlabel $vLabel\n";
238
    print "graph_category Ups\n";
239
    print "graph_info This graph shows the $hLabel ($vLabel) of $model <br> Onbattery remaining runtime <b>$rest</b> minutes.\n";
240
241
    #all ok
242
    exit 0;				    
243
}
244
245
# Get results
246
my @response = getSnmpValueArr (\@snmpParam,\@oidsList);
247
248
if ($type eq "volt")
249
{
250
    print "out.value $response[0]\n";
251
    print "in.value $response[1]\n";
252
    print "inmax.value $response[2]\n";
253
    print "inmin.value $response[3]\n";
254
}
255
elsif ($type eq "freq")
256
{
257
    print "out.value $response[0]\n";
258
    print "in.value $response[1]\n";
259
}
260
elsif ($type eq "status")
261
{
262
    my $unknown				= $response[0]==1  || 0;
263
    my $onLine				= $response[0]==2  || 0;
264
    my $onBattery			= $response[0]==3  || 0;
265
    my $softwareBypass			= $response[0]==6  || 0;
266
    my $off				= $response[0]==7  || 0;
267
    my $rebooting			= $response[0]==8  || 0;
268
    my $switchedBypass			= $response[0]==9  || 0;
269
    my $hardwareFailureBypass		= $response[0]==10 || 0;
270
    
271
    print "state.value $response[0]\n";
272
    print "unknown.value $unknown\n";
273
    print "onLine.value $onLine\n";
274
    print "onBattery.value $onBattery\n";
275
    print "softwareBypass.value $softwareBypass\n";
276
    print "off.value $off\n";
277
    print "rebooting.value $rebooting\n";
278
    print "switchedBypass.value $switchedBypass\n";
279
    print "hardwareFailureBypass.value $hardwareFailureBypass\n";
280
}
281
elsif ($type eq "temp")
282
{
283
    print "batt.value $response[0]\n";
284
    print "sens1.value $response[1]\n";
285
}
286
elsif ($type eq "load")
287
{
288
    print "load.value $response[0]\n";
289
    print "bcap.value $response[1]\n";
290
}
291
elsif ($type eq "curr")
292
{
293
    print "out.value $response[0]\n";
294
}
295
296
sub getSnmpValueArr 
297
{
298
	my ($param, $oidlist ) = @_; 
299
	my @result;
300
301
	foreach my $oid (@$oidlist) {
302
		 push ( @result, getSnmpValue($param,$oid) );
303
  }
304
 chomp @result;
305
 return @result;
306
}
307
308
#
309
# (\(community,IP),OID)
310
sub getSnmpValue
311
{
312
	    my ($param, $oid) = @_;
313
	    my ($comm, $ip) = @$param;
314
			return `/usr/local/bin/bsnmpget -n -o quiet -s ${comm}\@${ip} -v 1 $oid`;
315
}
316
__END__