From 6076d794e1bbf4fd23273cf9a8499fefb6e92da5 Mon Sep 17 00:00:00 2001 From: Cyberes Date: Thu, 6 Jul 2023 09:44:37 -0600 Subject: [PATCH] check_zfs_zpool: don't force table critical --- check_zfs_zpool.py | 9 ++++++--- checker/nagios.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/check_zfs_zpool.py b/check_zfs_zpool.py index 6fa9a79..2d9fbe8 100755 --- a/check_zfs_zpool.py +++ b/check_zfs_zpool.py @@ -8,6 +8,7 @@ import zfslib as zfs from checker import nagios from checker.markdown import list_to_markdown_table +from checker.nagios import state_to_txt from checker.units import filesize @@ -92,16 +93,18 @@ def check_vdev_devices(vdev_devices: list, critical_free, warning_free, critical states[device['device']] = state return critical, warning, states -def is_dash(string:str): + +def is_dash(string: str): return string == '-' + def get_vdev_info(zpool: str, vdev_type: str): output_zpool_logs = zpool_list(zpool, vdev_type) zpool_vdev_devices = [] for line in list(filter(None, output_zpool_logs.split('\n'))): data = list(filter(None, clean_device_list(line).split(' '))) zpool_vdev_devices.append({ - 'pool': False, # not (is_dash(data[2]) and is_dash(data[3]) and is_dash(data[6]) and is_dash(data[7])), + 'pool': False, # not (is_dash(data[2]) and is_dash(data[3]) and is_dash(data[6]) and is_dash(data[7])), # TODO: better pool detection 'device': data[0], @@ -204,7 +207,7 @@ def main(): filesize(pool_status['free'], spaces=False, formatter=False), float_to_percent(pool_status['fragmentation']), float_to_percent(pool_status['capacity']), - pool_status['health'], f"[{('ok' if exit_code == nagios.OK else 'critical').upper()}]") + pool_status['health'], f"[{state_to_txt(exit_code).upper()}]") ] for device in vdev_devices: if isinstance(device['frag'], float): diff --git a/checker/nagios.py b/checker/nagios.py index 974cea5..4701313 100644 --- a/checker/nagios.py +++ b/checker/nagios.py @@ -3,3 +3,14 @@ UNKNOWN = STATE_UNKNOWN = -1 OK = STATE_OK = 0 WARNING = STATE_WARN = 1 CRITICAL = STATE_CRIT = 2 + + +def state_to_txt(state: int) -> str: + if state == STATE_UNKNOWN: + return 'UNKNOWN' + elif state == STATE_OK: + return 'OK' + elif state == STATE_CRIT: + return 'CRITICAL' + elif state == STATE_WARN: + return 'WARNING'