diff --git a/check_nut.py b/check_nut.py index 9da1eb6..00fe2bf 100644 --- a/check_nut.py +++ b/check_nut.py @@ -44,6 +44,14 @@ VALUE_COMPARISONS = { 'input_voltage': 'le', 'output_voltage': 'le' } +VALUE_UNITS = { + 'load': '%', + 'battery_charge': 'V', + 'battery_runtime': 's', + 'battery_voltage': 'V', + 'input_voltage': 'V', + 'output_voltage': 'V' +} def parse_ups_status(status: str): @@ -103,6 +111,8 @@ def main(args): if len(lines) and 'data stale' in lines[0].lower(): print_icinga2_check_status(f'Failed to get UPS status: data stale', nagios.STATE_CRIT) sys.exit(nagios.STATE_CRIT) + else: + print_icinga2_check_status(f'Failed to get UPS status: {output}', nagios.STATE_UNKNOWN) print_icinga2_check_status(f'Failed to get UPS status: {e}', nagios.STATE_UNKNOWN) sys.exit(nagios.STATE_UNKNOWN) @@ -155,7 +165,7 @@ def main(args): perf_data = {} for k, v in ups_stats.items(): name = k.replace('.', '_') - perf_data[name] = {'value': try_float(v), 'warn': None, 'crit': None, 'min': 0} + perf_data[name] = {'value': try_float(v), 'warn': None, 'crit': None, 'min': 0, 'unit': VALUE_UNITS.get(name)} # Set the perfdata values based on the levels. if perf_data.get('battery_charge'):