From 633b6d3851e4627a69d8030b9fcbf5c208f0a729 Mon Sep 17 00:00:00 2001 From: Cyril Levis Date: Wed, 16 Nov 2022 14:43:35 +0100 Subject: [PATCH 1/2] fix: ignore more cache errors --- netbox_agent/raid/hp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox_agent/raid/hp.py b/netbox_agent/raid/hp.py index 610c958..a2d9971 100644 --- a/netbox_agent/raid/hp.py +++ b/netbox_agent/raid/hp.py @@ -36,7 +36,7 @@ def ssacli(sub_command): def _parse_ctrl_output(lines): controllers = {} current_ctrl = None - ignore_patterns = ['Note:', 'Error:', 'is not loaded', 'README'] + ignore_patterns = ['Note:', 'Error:', 'is not loaded', 'README', 'failure'] ignore_match = False for line in lines: for pattern in ignore_patterns: -- 2.47.1 From e96a50379b384bd6b5cffbb15c1484d1ca50f304 Mon Sep 17 00:00:00 2001 From: Cyril Levis Date: Wed, 16 Nov 2022 15:46:57 +0100 Subject: [PATCH 2/2] chore: refactor hp raid ignore errors handling --- netbox_agent/raid/hp.py | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/netbox_agent/raid/hp.py b/netbox_agent/raid/hp.py index a2d9971..5990009 100644 --- a/netbox_agent/raid/hp.py +++ b/netbox_agent/raid/hp.py @@ -33,17 +33,21 @@ def ssacli(sub_command): lines = list(filter(None, lines)) return lines +def _test_if_valid_line(line): + ignore_patterns = ['Note:', 'Error:', 'is not loaded', 'README', 'failure', 'cache'] + for pattern in ignore_patterns: + if not line or pattern in line: + return None + return line + def _parse_ctrl_output(lines): controllers = {} current_ctrl = None - ignore_patterns = ['Note:', 'Error:', 'is not loaded', 'README', 'failure'] - ignore_match = False + for line in lines: - for pattern in ignore_patterns: - if not line or pattern in line: - ignore_match = True - break - if ignore_match: + line = line.strip() + line = _test_if_valid_line(line) + if line is None: continue ctrl = REGEXP_CONTROLLER_HP.search(line) if ctrl is not None: @@ -51,7 +55,10 @@ def _parse_ctrl_output(lines): controllers[current_ctrl] = {'Slot': ctrl.group(2)} if 'Embedded' not in line: controllers[current_ctrl]['External'] = True + continue + if ': ' not in line: continue + attr, val = line.split(': ', 1) attr = attr.strip() val = val.strip() @@ -66,9 +73,8 @@ def _parse_pd_output(lines): for line in lines: line = line.strip() - if not line or line.startswith('Note:'): - continue - if 'cache' in line or 'reboot' in line: + line = _test_if_valid_line(line) + if line is None: continue # Parses the Array the drives are in if line.startswith('Array'): @@ -83,10 +89,13 @@ def _parse_pd_output(lines): if ': ' not in line: continue attr, val = line.split(': ', 1) + attr = attr.strip() + val = val.strip() drives.setdefault(current_drv, {})[attr] = val return drives + def _parse_ld_output(lines): drives = {} current_array = None @@ -94,7 +103,8 @@ def _parse_ld_output(lines): for line in lines: line = line.strip() - if not line or line.startswith('Note:'): + line = _test_if_valid_line(line) + if line is None: continue # Parses the Array the drives are in if line.startswith('Array'): -- 2.47.1