This repository was archived by the owner on Jul 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck_damocles.pl
More file actions
executable file
·474 lines (380 loc) · 11.6 KB
/
Copy pathcheck_damocles.pl
File metadata and controls
executable file
·474 lines (380 loc) · 11.6 KB
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
#!/usr/bin/perl -w
# ------------------------------------------------------------------------------
# check_damocles.pl - checks the HW group Damocles devices.
# Copyright (C) 2010 NETWAYS GmbH, www.netways.de
# Author: Michael Streb <michael.streb@netways.de>
# Author: Bernd Löhlein <bernd.loehlein@netways.de>
# Version: $Id: check_damocles.pl 1558 2010-02-17 13:07:57Z mstreb $
#
# This program is free software; you can redistribute it and/or
# modify it under the tepdu 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.
# $Id: check_damocles.pl 1558 2010-02-17 13:07:57Z mstreb $
# ------------------------------------------------------------------------------
# basic requirements
use strict;
use Getopt::Long;
use File::Basename;
use Pod::Usage;
use Net::SNMP;
use Data::Dumper;
# predeclared subs
use subs qw/print_help/;
# predeclared vars
use vars qw (
$PROGNAME
$VERSION
%states
%state_names
$opt_host
$opt_community
$opt_sensor
$opt_contact
$opt_output
$opt_warning
$opt_critical
$opt_help
$opt_man
$opt_version
$module
$device
$response
$output
@oids
);
# Main values
$PROGNAME = basename($0);
$VERSION = '1.1';
# Nagios exit states
%states = (
OK => 0,
WARNING => 1,
CRITICAL => 2,
UNKNOWN => 3
);
# Nagios state names
%state_names = (
0 => 'OK',
1 => 'WARNING',
2 => 'CRITICAL',
3 => 'UNKNOWN'
);
$opt_warning = "null";
$opt_critical = "null";
# SNMP
my $opt_community = "public";
my $snmp_version = "1";
#my $response;
# Get the options from cl
Getopt::Long::Configure('bundling');
GetOptions(
'h' => \$opt_help,
'help' => \$opt_help,
'H=s' => \$opt_host,
'C=s', => \$opt_community,
'S=n', => \$opt_sensor,
'I=n', => \$opt_contact,
'O=n', => \$opt_output,
'w=s' => \$opt_warning,
'c=s' => \$opt_critical,
'man' => \$opt_man,
'V' => \$opt_version
)
|| print_help( 1, 'Please check your options!' );
# If somebody wants to the help ...
if ($opt_help) {
print_help(1);
}
elsif ($opt_man) {
print_help(2);
}
elsif ($opt_version) {
print_help(-1);
}
# oids
my $deviceid = '.1.3.6.1.2.1.1.1.0';
my $enterprise = '.1.3.6.1.4.1.21796';
# Check if all needed options present.
unless ( $opt_host && ( $opt_sensor || $opt_contact || $opt_output ) ) {
print_help( 1, 'Not enough options specified!' );
}
else {
# Open SNMP Session
my ( $session, $error ) = Net::SNMP->session(
-hostname => $opt_host,
-community => $opt_community,
-port => 161,
-version => $snmp_version
);
# SNMP Session failed
if ( !defined($session) ) {
print $state_names{ ( $states{UNKNOWN} ) } . ": $error";
exit $states{UNKNOWN};
}
# request for sensor
if (defined $opt_sensor) {
my ($sensor_tree_id, $sensor_id);
# Sensor states
my %sensor_states = ();
# Sensor OID setting
# check for device type Poseidon/STE
$response = $session->get_request($deviceid);
$device = $response->{$deviceid};
if ($device =~ m/Poseidon/i) {
# Sensor states
%sensor_states = (
0 => 'invalid',
1 => 'normal',
2 => 'alarmstate',
3 => 'alarm',
);
$sensor_tree_id = $enterprise.".3.3.3.1.8";
} elsif ($device =~ m/Damocles/i) {
# Sensor states
%sensor_states = (
0 => 'invalid',
1 => 'normal',
2 => 'alarmstate',
3 => 'alarm',
);
$sensor_tree_id = $enterprise.".3.4.3.1.8";
} elsif ($device =~ m/STE/i) {
# Sensor states
%sensor_states = (
0 => 'invalid',
1 => 'normal',
2 => 'outofrangelo',
3 => 'outofrangehi',
4 => 'alarmlo',
5 => 'alarmhi',
);
$sensor_tree_id = $enterprise.".4.1.3.1.8";
} else {
print "ERROR: Device not supported\n";
$session->close();
exit $states{UNKNOWN};
}
# get the sensor ID
$response = $session->get_table($sensor_tree_id);
foreach my $sensor (keys %$response) {
if($response->{$sensor} eq $opt_sensor) {
$sensor =~ m/.?[\d\.]+(\d)$/;
$sensor_id = $1;
};
}
# check for numeric sensor id
if (!defined $sensor_id || $sensor_id !~ m/\d/ ) {
print "ERROR: Sensor ID not found\n";
$session->close();
exit $states{UNKNOWN};
}
# setting per device OIDs for sensor values
if ($device =~ m/Poseidon/i) {
push(@oids, $enterprise.'.3.3.3.1.2.'.$sensor_id); # POSEIDON-MIB::sensName
push(@oids, $enterprise.'.3.3.3.1.4.'.$sensor_id); # POSEIDON-MIB::sensState
push(@oids, $enterprise.'.3.3.3.1.5.'.$sensor_id); # POSEIDON-MIB::sensString
push(@oids, $enterprise.'.3.3.3.1.6.'.$sensor_id); # POSEIDON-MIB::sensValue
push(@oids, $enterprise.'.3.3.3.1.9.'.$sensor_id); # POSEIDON-MIB::sensUnit
push(@oids, $enterprise.'.3.3.99.1.2.1.6.'.$sensor_id); # POSEIDON-MIB::sensLimitMin
push(@oids, $enterprise.'.3.3.99.1.2.1.7.'.$sensor_id); # POSEIDON-MIB::sensLimitMax
} elsif ($device =~ m/Damocles/i) {
push(@oids, $enterprise.'.3.4.3.1.2.'.$sensor_id); # POSEIDON-MIB::sensName
push(@oids, $enterprise.'.3.4.3.1.4.'.$sensor_id); # POSEIDON-MIB::sensState
push(@oids, $enterprise.'.3.4.3.1.5.'.$sensor_id); # POSEIDON-MIB::sensString
push(@oids, $enterprise.'.3.4.3.1.6.'.$sensor_id); # POSEIDON-MIB::sensValue
push(@oids, $enterprise.'.3.4.3.1.9.'.$sensor_id); # POSEIDON-MIB::sensUnit
push(@oids, $enterprise.'.3.4.99.1.2.1.6.'.$sensor_id); # POSEIDON-MIB::sensLimitMin
push(@oids, $enterprise.'.3.4.99.1.2.1.7.'.$sensor_id); # POSEIDON-MIB::sensLimitMax
} elsif ($device =~ m/STE/i) {
push(@oids, $enterprise.'.4.1.3.1.2.'.$sensor_id); # POSEIDON-MIB::sensName
push(@oids, $enterprise.'.4.1.3.1.3.'.$sensor_id); # POSEIDON-MIB::sensState
push(@oids, $enterprise.'.4.1.3.1.4.'.$sensor_id); # POSEIDON-MIB::sensString
push(@oids, $enterprise.'.4.1.3.1.5.'.$sensor_id); # POSEIDON-MIB::sensValue
} else {
print "ERROR: device not supported";
$session->close();
exit $states{UNKNOWN};
}
# getting the sensor values from the device
$response = $session->get_request(-varbindlist => \@oids)
or die "ERROR while getting Sensor values";
# setting the output string
$output .= "Sensor: ".$response->{$oids[0]}.", ";
$output .= "State: ".$sensor_states{$response->{$oids[1]}}.", ";
$output .= "Value: ".$response->{$oids[2]};
$output .= "| $response->{$oids[0]}=".eval($response->{$oids[3]}/10).";";
# append thresholds to perfdata if device is Poseidon
if ($device =~ m/Poseidon/i) {
$output .= eval($response->{$oids[5]}/10).";";
$output .= eval($response->{$oids[6]}/10).";";
}
}
# request for dry contact
if (defined $opt_contact) {
# Input states
my %alarm_states = (
0 => 'normal',
1 => 'alarm',
);
my %input_values = (
0 => 'off',
1 => 'on',
);
my %alarm_setup = (
0 => 'inactive',
1 => 'activeOff',
2 => 'activeOn',
);
# get the contact values
push(@oids, $enterprise.'.3.4.1.1.3.'.$opt_contact); # POSEIDON-MIB::inpName
push(@oids, $enterprise.'.3.4.1.1.2.'.$opt_contact); # POSEIDON-MIB::inpValue
push(@oids, $enterprise.'.3.4.1.1.4.'.$opt_contact); # POSEIDON-MIB::inpAlarmSetup
push(@oids, $enterprise.'.3.4.1.1.5.'.$opt_contact); # POSEIDON-MIB::inpAlarmState
# getting the values from the device
$response = $session->get_request(-varbindlist => \@oids)
or print "ERROR: Sensor ID not found\n";
exit $states{UNKNOWN} if !defined $response;
# setting the output string
$output .= "Input: ".$response->{$oids[0]}.", ";
$output .= "AlarmState: ".$alarm_states{$response->{$oids[3]}}.", ";
$output .= "AlarmSetup: ".$alarm_setup{$response->{$oids[2]}}.", ";
$output .= "Value: ".$input_values{$response->{$oids[1]}};
}
if (defined $opt_output) {
# output states
my %output_values = (
0 => 'off',
1 => 'on',
);
# output types
my %output_types = (
0 => 'relay (off, on)',
1 => 'rts (-10V,+10V)',
2 => 'dtr (0V,+10V)',
);
# output mode
my %output_modes = (
0 => 'manual',
1 => 'autoAlarm',
2 => 'autoTriggerEq',
3 => 'autoTriggerHi',
4 => 'autoTriggerLo',
);
# get the contact values
push (@oids, $enterprise.'.3.4.2.1.2.'.$opt_output); # POSEIDON-MIB::outValue
push (@oids, $enterprise.'.3.4.2.1.3.'.$opt_output); # POSEIDON-MIB::outName
push (@oids, $enterprise.'.3.4.2.1.4.'.$opt_output); # POSEIDON-MIB::outType
push (@oids, $enterprise.'.3.4.2.1.5.'.$opt_output); # POSEIDON-MIB::outMode
# getting the values from the device
$response = $session->get_request(-varbindlist => \@oids)
or print "ERROR: Sensor ID not found\n";
exit $states{UNKNOWN} if !defined $response;
# setting the output string
$output .= "Output: ".$response->{$oids[1]}.", ";
$output .= "Type: ".$output_types{$response->{$oids[2]}}.", ";
$output .= "Mode: ".$output_modes{$response->{$oids[3]}}.", ";
$output .= "Value: ".$output_values{$response->{$oids[0]}};
}
# finally close SNMP session
$session->close();
# print the gathered data
print $output."\n";
# setting exit states
if (defined $opt_sensor) {
if ( $device =~ m/Poseidon/i ) {
if ($response->{$oids[1]} == 3) {
exit $states{CRITICAL};
} elsif ($response->{$oids[1]} == 2) {
exit $states{WARNING};
} elsif ($response->{$oids[1]} == 0) {
exit $states{UNKNOWN};
} else {
exit $states{OK};
}
} elsif ($device =~ m/STE/i ) {
if ($response->{$oids[1]} > 1) {
exit $states{CRITICAL};
} elsif ($response->{$oids[1]} == 0) {
exit $states{UNKNOWN};
} else {
exit $states{OK};
}
}
}
# check for dry contacts
if (defined $opt_contact) {
if ($response->{$oids[3]} == 1) {
exit $states{CRITICAL};
} else {
exit $states{OK};
}
}
}
# -------------------------
# THE SUBS:
# -------------------------
# print_help($level, $msg);
# prints some message and the POD DOC
sub print_help {
my ( $level, $msg ) = @_;
$level = 0 unless ($level);
if($level == -1) {
print "$PROGNAME - Version: $VERSION\n";
exit ( $states{UNKNOWN});
}
pod2usage(
{
-noperldoc => 1,
-message => $msg,
-verbose => $level
}
);
exit( $states{UNKNOWN} );
}
1;
__END__
=head1 NAME
check_damocles.pl - Checks the hwgroup damocles device for nagios
=head1 SYNOPSIS
check_damocles.pl -h
check_damocles.pl -H <host> ( -S <sensor id> | -I <input id> | -O <output id> )
=head1 DESCRIPTION
Bcheck_damocles.pl recieves the data from the hwgroup devices.
=head1 OPTIONS
=over 8
=item B<-h>
Display this helpmessage.
=item B<-H>
The hostname or ipaddress of the hwgroup device.
=item B<-C>
The snmp community of the hwgroup device.
=item B<-S>
The sensor to check
=item B<-I>
The dry contact to check
=item B<-O>
The relay output to check
=item B<--man>
Displays the complete perldoc manpage.
=back
=cut
=head1 THRESHOLD FORMATS
B<1.> start <= end
Thresholds have to be specified from the lower level end on e.g. -w 20 is meaning that a
warning error is occuring when the collected value is over 20.
=head1 VERSION
$Id: check_damocles.pl 1558 2010-02-17 13:07:57Z mstreb $
=head1 AUTHOR
NETWAYS GmbH, 2010, http://www.netways.de.
Written by Michael Streb <michael.streb@netways.de>, Bernd Löhlein <bernd.loehlein@netways.de>
Please report bugs at https://www.netways.org/projects/plugins