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
|
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# | ____ _ _ __ __ _ __ |
# | / ___| |__ ___ ___| | __ | \/ | |/ / |
# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
# | | |___| | | | __/ (__| < | | | | . \ |
# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
# | |
# +------------------------------------------------------------------+
#
# This file will some day be part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
# Author: Daniel Karni <minodudd@gmail.com>
# EXAMPLE DATA FROM: Ablerex VT650 (vt650)
#<<<nut>>>
#vt650 battery.voltage: 14.10
#vt650 battery.voltage.high: -1.08
#vt650 battery.voltage.low: -0.87
#vt650 device.type: ups
#vt650 driver.name: blazer_usb
#vt650 driver.parameter.bus: 005
#vt650 driver.parameter.pollinterval: 2
#vt650 driver.parameter.port: auto
#vt650 driver.version: 2.6.4
#vt650 driver.version.internal: 0.08
#vt650 input.frequency: 49.9
#vt650 input.voltage: 235.6
#vt650 input.voltage.fault: 140.0
#vt650 output.voltage: 236.4
#vt650 ups.beeper.status: enabled
#vt650 ups.delay.shutdown: 30
#vt650 ups.delay.start: 180
#vt650 ups.load: 23
#vt650 ups.productid: 0000
#vt650 ups.status: OL
#vt650 ups.temperature: 30.0
#vt650 ups.type: offline / line interactive
#vt650 ups.vendorid: ffff
nut_temp_default_values = (35, 40)
nut_load_default_values = (70, 85)
nut_output_default_values = (245, 250)
nut_battery_default_levels = (10, 5)
nut_battery_charge_default_levels = (90, 85)
nut_battery_runtime_default_levels = (900, 600)
nut_input_voltage_fault_default_levels = (155, 160)
nut_input_default_levels = (245, 250)
nut_input_freq_default_levels = (51, 55)
# the inventory function (dummy)
def inventory_nut(check_type, info):
# begin with empty inventory
inventory = []
for line in info:
# loop over all output lines of the agent
if len(line) < 3:
#found a broken line (values are in the third column)
continue
if check_type == 'nut.device' and line[1] in [ 'device.type:', 'ups.productid:', 'ups.type:', 'ups.vendorid:',] and not (line[0], None) in inventory: inventory.append((line[0], None))
elif check_type == 'nut.driver' and line[1] in [ 'driver.name:', 'driver.parameter.bus:', 'driver.parameter.pollinterval:', 'driver.parameter.port:', 'driver.version:', 'driver.version.internal:',] and not (line[0], None) in inventory: inventory.append((line[0], None))
elif check_type == 'nut.input' and line[1] in [ 'input.frequency:', 'input.voltage:', 'input.voltage.fault:',] and not (line[0], None) in inventory: inventory.append((line[0], None))
elif check_type == 'nut.delay' and line[1] in [ 'ups.delay.shutdown:', 'ups.delay.start:',] and not (line[0], None) in inventory: inventory.append((line[0], None))
elif check_type == 'nut.input.freq' and line[1] == 'input.frequency:': inventory.append((line[0], None, 'nut_input_freq_default_levels'))
elif check_type == 'nut.input' and line[1] == 'input.voltage:': inventory.append((line[0], None, 'nut_input_default_levels'))
elif check_type == 'nut.input.fault' and line[1] == 'input.voltage.fault:': inventory.append((line[0], None, 'nut_input_voltage_fault_default_levels'))
elif check_type == 'nut.battery' and line[1] == 'battery.voltage:': inventory.append((line[0], None, 'nut_battery_default_levels'))
elif check_type == 'nut.battery.charge' and line[1] == 'battery.charge:': inventory.append((line[0], None, 'nut_battery_charge_default_levels'))
elif check_type == 'nut.battery.runtime' and line[1] == 'battery.runtime:': inventory.append((line[0], None, 'nut_battery_runtime_default_levels'))
elif check_type == 'nut.output' and line[1] == 'output.voltage:': inventory.append((line[0], None, 'nut_output_default_values'))
elif check_type == 'nut.beeper' and line[1] == 'ups.beeper.status:': inventory.append((line[0], None))
elif check_type == 'nut.load' and line[1] == 'ups.load:': inventory.append((line[0], None, 'nut_load_default_values'))
elif check_type == 'nut.temp' and line[1] == 'ups.temperature:': inventory.append((line[0], None, 'nut_temp_default_values'))
elif check_type == 'nut.status' and line[1] == 'ups.status:': inventory.append((line[0], None))
return inventory
def check_nut_value(item, params, info, lineLabel, factType, returnOutput):
warn, crit = params
for line in info:
if len(line) >= 3 and line[0] == item and line[1] == lineLabel+":":
lineData = float(line[2]);
perfdata = [ ( factType , lineData, warn, crit ) ];
if lineData >= crit:
return (2, ("CRIT - " + returnOutput) % lineData, perfdata)
elif lineData >= warn:
return (1, ("WARN - " + returnOutput) % lineData, perfdata)
else:
return (0, ("OK - " + returnOutput) % lineData, perfdata)
return (3, "UNKNOWN - %s not found in agent output for %s" % (lineLabel , item))
def check_nut_battery(item, params, info):
warn, crit = params
for line in info:
if len(line) >= 3 and line[0] == item and line[1] == "battery.voltage:":
voltage = float(line[2])
perfdata = [ ( "voltage", voltage, warn, crit ) ]
if voltage <= crit:
return (2, "CRIT - Battery Voltage is %0.2f V" % voltage, perfdata)
elif voltage <= warn:
return (1, "WARN - Battery Voltage is %0.2f V" % voltage, perfdata)
else:
return (0, "OK - Battery Voltage is %0.2f V" % voltage, perfdata)
return (3, "UNKNOWN - battery.voltage not found in agent output for %s" % item)
def check_nut_battery_charge(item, params, info):
warn, crit = params
for line in info:
if len(line) >= 3 and line[0] == item and line[1] == "battery.charge:":
charge = float(line[2])
perfdata = [ ( "charge", charge, warn, crit ) ]
if charge <= crit:
return (2, "CRIT - Battery Charge is %0.2f %%" % charge, perfdata)
elif charge <= warn:
return (1, "WARN - Battery Charge is %0.2f %%" % charge, perfdata)
else:
return (0, "OK - Battery Charge is %0.2f %%" % charge, perfdata)
return (3, "UNKNOWN - battery.charge not found in agent output for %s" % item)
def check_nut_battery_runtime(item, params, info):
warn, crit = params
for line in info:
if len(line) >= 3 and line[0] == item and line[1] == "battery.runtime:":
runtime_s = int(line[2])
runtime = float(line[2]) / 60
perfdata = [ ( "runtime", runtime, warn, crit ) ]
if runtime_s <= crit:
return (2, "CRIT - Battery Runtime is %0.2f min" % runtime, perfdata)
elif runtime_s <= warn:
return (1, "WARN - Battery Runtime is %0.2f min" % runtime, perfdata)
else:
return (0, "OK - Battery Runtime is %0.2f min" % runtime, perfdata)
return (3, "UNKNOWN - battery.runtime not found in agent output for %s" % item)
### String collection checks
def check_nut_device(item, params, info):
output = []
for line in info:
if len(line) < 3 or line[0] != item:
continue
value = line[2]
field = line[1]
if field in [ 'device.type:',
'ups.productid:',
'ups.type:',
'ups.vendorid:',]:
for val, lab, txt in [
(value, 'device.type:', 'Device Type'),
(value, 'ups.productid:', 'Product ID'),
(value, 'ups.type:', 'UPS Type'),
(value, 'ups.vendorid:', 'Vendor ID'),
]:
if field == lab:
output.append('%s: %s' % (txt, val))
if not output:
return (3, 'UNKNOWN - Found no info in nut outout')
return (0, "OK - Device Details: %s" % (', '.join(output)))
def check_nut_driver(item, params, info):
output = []
for line in info:
if len(line) < 3 or line[0] != item:
continue
value = line[2]
field = line[1]
if field in [ 'driver.name:',
'driver.parameter.bus:',
'driver.parameter.pollinterval:',
'driver.parameter.port:',
'driver.version:',
'driver.version.internal:',]:
for val, lab, txt in [
(value, 'driver.name:', 'Name'),
(value, 'driver.parameter.bus:', 'Parameter Bus'),
(value, 'driver.parameter.pollinterval:', 'Poll Interval'),
(value, 'driver.parameter.port:', 'Port'),
(value, 'driver.version:', 'Version'),
(value, 'driver.version.internal:', 'Internal Version'),
]:
if field == lab:
output.append('%s: %s' % (txt, val))
if not output:
return (3, 'UNKNOWN - Found no info in nut outout')
return (0, "OK - Driver Details: %s" % (', '.join(output)))
def check_nut_delay(item, params, info):
output = []
for line in info:
if len(line) < 3 or line[0] != item:
continue
value = line[2]
field = line[1]
if field in [ 'ups.delay.shutdown:',
'ups.delay.start:',]:
for val, lab, txt in [
(value, 'ups.delay.shutdown:', 'Shutdown Delay'),
(value, 'ups.delay.start:', 'Start Delay'),
]:
if field == lab:
output.append('%s: %s' % (txt, val))
if not output:
return (3, 'UNKNOWN - Found no info in nut outout')
return (0, "OK - Device Details: %s" % (', '.join(output)))
### String comparison checks
def check_nut_beeper(item, params, info):
for line in info:
if len(line) < 3 or line[0] != item:
continue
value = line[2]
if line[1] == 'ups.beeper.status:':
if value == 'enabled':
return (0, "OK - UPS Beeper Status is enabled")
elif value == 'disabled':
return (1, "WARN - UPS Beeper Status is disabled")
return (3, "UNKNOWN - UPS Beeper Status cannot be determined for %s" % item)
def check_nut_status(item, params, info):
for line in info:
if len(line) < 3 or line[0] != item:
continue
values = line[2:]
if line[1] == 'ups.status:':
if values[0] == 'OL':
if len(values) > 1:
if values[1] == 'RB':
return (1, "WARN - UPS Status is Onlince / Replace Battery (OL RB)")
return (1, "WARN - UPS Status has unknown extra fields: %s" % (", ".join(values[1:])))
return (0, "OK - UPS Status is Online (OL)")
elif values[0] == 'OB':
return (1, "WARN - UPS Status is On Battery (OB)")
elif values[0] == 'LB':
return (2, "CRIT - UPS Status is Low Battery (LB)")
return (3, "UNKNOWN - UPS Status cannot be determined for %s" % item)
# declare the check to Check_MK
check_info["nut.battery"] = (check_nut_battery, 'NUT %s Battery Voltage', 1, lambda info: inventory_nut("nut.battery", info))
check_info["nut.battery.charge"] = (check_nut_battery_charge, 'NUT %s Battery Charge', 1, lambda info: inventory_nut("nut.battery.charge", info))
check_info["nut.battery.runtime"] = (check_nut_battery_runtime, 'NUT %s Battery Runtime', 1, lambda info: inventory_nut("nut.battery.runtime", info))
check_info["nut.device"] = (check_nut_device, 'NUT %s Device Details', 0, lambda info: inventory_nut("nut.device", info))
check_info["nut.driver"] = (check_nut_driver, 'NUT %s Driver Details', 0, lambda info: inventory_nut("nut.driver", info))
check_info["nut.input"] = (lambda item, params, info: check_nut_value(item, params, info,"input.voltage", "voltage", "Input Voltage is %0.2f V"), 'NUT %s Input Voltage', 1, lambda info: inventory_nut("nut.input", info))
check_info["nut.input.freq"] = (lambda item, params, info: check_nut_value(item, params, info,"input.frequency", "frequency", "Input Frequency is %0.2f Hz"), 'NUT %s Input Frequency', 1, lambda info: inventory_nut("nut.input.freq", info))
check_info["nut.input.fault"] = (lambda item, params, info: check_nut_value(item, params, info,"input.voltage.fault", "voltage", "Input Voltage fault is %0.2f V"), 'NUT %s Input Voltage Fault', 1, lambda info: inventory_nut("nut.input.fault", info))
check_info["nut.output"] = (lambda item, params, info: check_nut_value(item, params, info,"output.voltage", "voltage", "Output Voltage is %0.2f V"), 'NUT %s Output Voltage', 1, lambda info: inventory_nut("nut.output", info))
check_info["nut.load"] = (lambda item, params, info: check_nut_value(item, params, info,"ups.load", "load", "Load is %d %%"), 'NUT %s Load Percentage', 1, lambda info: inventory_nut("nut.load", info))
check_info["nut.temp"] = (lambda item, params, info: check_nut_value(item, params, info,"ups.temperature", "temp", "Temperature is %0.1f C"), 'NUT %s Temperature', 1, lambda info: inventory_nut("nut.temp", info))
check_info["nut.beeper"] = (check_nut_beeper, 'NUT %s Beeper Status', 0, lambda info: inventory_nut("nut.beeper", info))
check_info["nut.delay"] = (check_nut_delay, 'NUT %s Delay settings', 0, lambda info: inventory_nut("nut.delay", info))
check_info["nut.status"] = (check_nut_status, 'NUT %s Status', 0, lambda info: inventory_nut("nut.status", info))
|