|
1 | 1 | import re |
2 | 2 | from datetime import datetime |
3 | 3 | from collections import defaultdict |
4 | | -from json import loads |
| 4 | +from json import loads, JSONDecodeError |
5 | 5 | from typing import Dict |
6 | 6 | import numpy as np |
7 | 7 |
|
@@ -993,13 +993,32 @@ def _clean_panos_data(self, processed_data, _): |
993 | 993 |
|
994 | 994 | # mtu values are collected separatly |
995 | 995 | 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 | + |
996 | 1003 | # fix json so that it can be parsed |
997 | | - d = _mtu_data.split(": ", 1)[1].replace("'", "\"") |
| 1004 | + d = json_blob.replace("'", "\"") |
998 | 1005 | d = re.sub( |
999 | 1006 | r"([a-fA-F0-9]{2}(:[a-fA-F0-9]{2}){5})", r'"\1"', d) |
1000 | 1007 | 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 | + |
1003 | 1022 | for ifname, value in j.items(): |
1004 | 1023 | mtu_data[ifname] = value["mtu"] |
1005 | 1024 | continue |
|
0 commit comments