-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_apc-redundancy
executable file
·164 lines (124 loc) · 3.78 KB
/
check_apc-redundancy
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
#! /usr/local/bin/perl
#
# $Id$
# $HeadURL$
#
# nagios: -epn
#
#################################################
# Product: ATS - Automatic Transfer Switch #
# Manufacturer: APC #
# Model: AP7723 #
# #
# Retrive incoming redundancy, source A and B. #
# #
#################################################
#
use strict;
use lib "/local/nagios/lib";
use SU_Nagios qw ( exit_clean get_snmp_community );
use Net::SNMP;
use Getopt::Std;
use vars qw ($opt_h $opt_H $opt_v $opt_C $opt_w);
my $OID_BASE = "1.3.6.1.4.1.318.1.1.8.5.1.3.0";
# SNMP options
my $version = "1";
my $timeout = 2;
# The top secret community name (password)...
my $community = get_snmp_community ('snmp');
# Thresholds
my $critical_redundancy = -1;
# Our return status - we start with 0 (OK) and hope for the best
my $status = 0;
# Our return string with lots of interesting stuff in it
my $returnstr = "";
# The SNMP hostname and community to use for the query
my $hostname = "";
# Grab the command line options
getopts("h:H:v:C:w:");
# If we didn't get any options, show some help and quit
if ($opt_h){
usage ();
}
# Get the hostname, if it was given..
if (defined($opt_H)){
$hostname = $opt_H;
} else {
# We really need a hostname
usage();
}
if (defined($opt_v)) {
# Get the snmp version for the UPS or use the default
$version = $opt_v;
}
# Get the SNMP community
if (defined($opt_C)){
$community = $opt_C;
}
my ($snmp_session, $snmp_error) = Net::SNMP->session(
-community => $community,
-hostname => $hostname,
-version => $version,
-timeout => $timeout,
);
# Grab interesting details
check_device();
# Shut down the SNMP session
$snmp_session->close();
# Do not use numerical comparision to avoid failures with ePN in Nagios2. Sigh.
$status = 'UNKNOWN' if ("$status" eq '-1');
$status = 'OK' if ("$status" eq '0');
$status = 'CRITICAL' if ("$status" eq '2');
exit_clean ($status, $returnstr . "\n");
# Change the satus level
sub status {
my $newstatus = $_[0];
# If the new status is greater than the old status, change the old status
if ($newstatus != $status) {
$status = $newstatus;
}
}
# Grab a value from snmp
sub grab_snmp_value {
my $this_value = "";
# Try to grab the OID's value, if it exists
if (defined($snmp_session->get_request($OID_BASE))) {
foreach ($snmp_session->var_bind_names()) {
$this_value = $snmp_session->var_bind_list()->{$_};
}
}
# Return the value we got..
return $this_value;
}
# Grab lots of interesting info about the device
sub check_device {
my $snmp_ret_value;
$returnstr = '';
$snmp_ret_value = grab_snmp_value($OID_BASE);
if ($snmp_ret_value) {
if (($snmp_ret_value != -1) && ($snmp_ret_value == 1)) {
status(2); # Critial
$returnstr .= ($returnstr?", ":''). "No redundancy";
} elsif (($snmp_ret_value != 1) && ($snmp_ret_value == -1)) {
status(-1); # Unknown
$returnstr .= ($returnstr?", ":''). "No input data";
} elsif (($snmp_ret_value != 1) || ($snmp_ret_value != -1) && ($snmp_ret_value == 2)) {
status(0); # Normal, OK
$returnstr .= ($returnstr?", ":''). "Redundancy is normal: $snmp_ret_value";
}
}
}
# Usage information
#
sub usage {
print << "USAGE";
$0
Check a APC ATS\' incomming Redundancy via SNMP
Usage: $0 -H <hostname> -v <version> [-C <community>]
Options:
-H Hostname or IP address of the APC ATS.
-v SNMP version supported by the UPS (default is $version)
-C SNMP read community (default is public)
USAGE
exit_clean ('CRITICAL');
}