diff options
author | Christian Pointner <equinox@helsinki.at> | 2015-09-09 19:49:20 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2015-09-09 19:49:20 (GMT) |
commit | e2b336a282671e7dd058f04a497a16a490bf0645 (patch) | |
tree | d9b0e7900e754f25843267aea3e989ae021a0cd4 /checks/nut | |
parent | 5d0bfa24b8c9c607d6c7dad172bfe74f6d26064d (diff) |
added check for battery charge/runtime
Diffstat (limited to 'checks/nut')
-rw-r--r-- | checks/nut | 361 |
1 files changed, 201 insertions, 160 deletions
@@ -46,207 +46,248 @@ 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 = (1200, 900) 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.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 + # 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 + 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 ) ]; + 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)) + 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:": + 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 ) ] - voltage = float(line[2]) - perfdata = [ ( "voltage", voltage, warn, crit ) ] - - if voltage <= crit: - return (2, "CRIT - Battery Voltage is %0.2fv" % voltage, perfdata) - elif voltage <= warn: - return (1, "WARN - Battery Voltage is %0.2fv" % voltage, perfdata) - else: - return (0, "OK - Battery Voltage is %0.2fv" % voltage, perfdata) - return (3, "UNKNOWN - battery.voltage not found in agent output for %s" % item) + 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 = float(line[2]) / 60 + perfdata = [ ( "runtime", runtime, warn, crit ) ] + + if runtime <= crit: + return (2, "CRIT - Battery Runtime is %0.2f min" % runtime, perfdata) + elif runtime <= 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))) - - + 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))) + 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))) - + 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) + 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 + for line in info: + if len(line) < 3 or line[0] != item: + continue + + value = line[2] + if line[1] == 'ups.status:': + if value == 'OL': + return (0, "OK - UPS Status is Online (OL)") + elif value == 'OB': + return (1, "WARN - UPS Status is On Battery (OB)") + elif value == 'LB': + return (2, "CRIT - UPS Status is Low Battery (LB)") + return (3, "UNKNOWN - UPS Status cannot be determined for %s" % item) - value = line[2] - if line[1] == 'ups.status:': - if value == 'OL': - return (0, "OK - UPS Status is Online (OL)") - elif value == 'OB': - return (1, "WARN - UPS Status is On Battery (OB)") - elif value == '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.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.2fv"), '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.2fHz"), '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.2fv"), '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.2fv"), '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.1fC"), '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)) +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)) |