check_nut: add units

This commit is contained in:
Cyberes 2023-12-19 22:50:29 -07:00
parent 7c559a689a
commit 6744e1a802
1 changed files with 11 additions and 1 deletions

View File

@ -44,6 +44,14 @@ VALUE_COMPARISONS = {
'input_voltage': 'le', 'input_voltage': 'le',
'output_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): def parse_ups_status(status: str):
@ -103,6 +111,8 @@ def main(args):
if len(lines) and 'data stale' in lines[0].lower(): 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) print_icinga2_check_status(f'Failed to get UPS status: data stale', nagios.STATE_CRIT)
sys.exit(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) print_icinga2_check_status(f'Failed to get UPS status: {e}', nagios.STATE_UNKNOWN)
sys.exit(nagios.STATE_UNKNOWN) sys.exit(nagios.STATE_UNKNOWN)
@ -155,7 +165,7 @@ def main(args):
perf_data = {} perf_data = {}
for k, v in ups_stats.items(): for k, v in ups_stats.items():
name = k.replace('.', '_') 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. # Set the perfdata values based on the levels.
if perf_data.get('battery_charge'): if perf_data.get('battery_charge'):