check_pve_guest_metrics: adjust input data

This commit is contained in:
Cyberes 2023-09-09 12:23:34 -06:00
parent 6c5c6ea7cb
commit 3d6742384f
1 changed files with 13 additions and 1 deletions

View File

@ -55,6 +55,15 @@ def main():
print('UNKNOWN: Failed to parse --levels JSON:', e) print('UNKNOWN: Failed to parse --levels JSON:', e)
sys.exit(nagios.UNKNOWN) sys.exit(nagios.UNKNOWN)
for k, v in metrics_levels.items():
metrics_levels[k]['min'] = metrics_levels[k].get('min')
if isinstance(metrics_levels[k]['min'], float):
metrics_levels[k]['min'] = int(metrics_levels[k]['min'])
if isinstance(metrics_levels[k]['warn'], float):
metrics_levels[k]['warn'] = int(metrics_levels[k]['warn'])
if isinstance(metrics_levels[k]['crit'], float):
metrics_levels[k]['crit'] = int(metrics_levels[k]['crit'])
try: try:
args.node = json.loads(args.node) args.node = json.loads(args.node)
pve_node = args.node[0] pve_node = args.node[0]
@ -171,7 +180,10 @@ def main():
for metric, data in check_data.items(): for metric, data in check_data.items():
output_str = output_str + f"{metric} {data['value_str']}, " output_str = output_str + f"{metric} {data['value_str']}, "
if not check_data[metric]['nan']: if not check_data[metric]['nan']:
perf_data.append(f"'{metric}'={data['value']};{metrics_levels[metric]['warn']};{metrics_levels[metric]['crit']};;") if metrics_levels[metric]['min'] is None:
perf_data.append(f"'{metric}'={data['value']};{metrics_levels[metric]['warn']};{metrics_levels[metric]['crit']};;")
else:
perf_data.append(f"'{metric}'={data['value']};{metrics_levels[metric]['warn']};{metrics_levels[metric]['crit']};{metrics_levels[metric]['min']};")
print(output_str.strip(', ').strip(), end=('\n' if args.table else '')) print(output_str.strip(', ').strip(), end=('\n' if args.table else ''))