Skip to content

Commit d62fcfd

Browse files
author
SuzieQ Bot
committed
Handle PAN-OS poller cleaning edge cases
Signed-off-by: SuzieQ Bot <bot@suzieq>
1 parent 584b22a commit d62fcfd

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

suzieq/poller/worker/services/arpnd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def _clean_panos_data(self, processed_data, _):
117117
# ARP entries are shown with status as merely a letter while
118118
# ND entries are shown with the status as a self-respecting word.
119119
# sigh
120-
state = entry.get("state", "").lower()
120+
state = (entry.get("state") or "").lower()
121121
if state in ["s", "static"]:
122122
entry["state"] = "permanent"
123123
elif state in ["c", "e", "stale", "reachable"]:

suzieq/poller/worker/services/interfaces.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22
from datetime import datetime
33
from collections import defaultdict
4-
from json import loads
4+
from json import loads, JSONDecodeError
55
from typing import Dict
66
import numpy as np
77

@@ -993,13 +993,32 @@ def _clean_panos_data(self, processed_data, _):
993993

994994
# mtu values are collected separatly
995995
if _mtu_data:
996+
try:
997+
_, json_blob = _mtu_data.split(": ", 1)
998+
except ValueError:
999+
self.logger.warning(
1000+
"Unexpected panos MTU data format: %s", _mtu_data)
1001+
continue
1002+
9961003
# fix json so that it can be parsed
997-
d = _mtu_data.split(": ", 1)[1].replace("'", "\"")
1004+
d = json_blob.replace("'", "\"")
9981005
d = re.sub(
9991006
r"([a-fA-F0-9]{2}(:[a-fA-F0-9]{2}){5})", r'"\1"', d)
10001007
d = re.sub(r"(\"[\w0-9\.\/]+\": \{\s\},\s)", r"", d)
1001-
d = re.sub(r"(,\s\})", r" }", d)
1002-
j = loads(d)
1008+
d = re.sub(r"(,\s\})", r" }", d).strip()
1009+
1010+
if not d:
1011+
self.logger.warning(
1012+
"Empty panos MTU data after cleanup: %s", _mtu_data)
1013+
continue
1014+
1015+
try:
1016+
j = loads(d)
1017+
except JSONDecodeError: # pragma: no cover - defensive
1018+
self.logger.warning(
1019+
"Unable to parse panos MTU data: %s", d)
1020+
continue
1021+
10031022
for ifname, value in j.items():
10041023
mtu_data[ifname] = value["mtu"]
10051024
continue

0 commit comments

Comments
 (0)