Skip to content

Commit b1be9da

Browse files
committed
[monitor][fix] Handle missing or invalid JSON data
1 parent c043134 commit b1be9da

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

scripts/monitor/target_json.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ def loadMdsServer():
3838
mdsServers = []
3939
label = lablesValue(None, "mds")
4040
if ret == 0 :
41-
data = json.loads(output)
41+
try:
42+
data = json.loads(output)
43+
except json.JSONDecodeError:
44+
return unitValue(label, mdsServers)
4245
result = data["result"]
4346
for mdsInfo in result["mdses"]:
4447
location = mdsInfo["location"]
@@ -52,6 +55,8 @@ def loadClient():
5255
if ret == 0 :
5356
data = json.loads(output)
5457
result = data["result"]
58+
if "fsInfos" not in result:
59+
return unitValue(label, clients)
5560
for fsinfo in result["fsInfos"]:
5661
mountPoints = fsinfo.get("mountPoints")
5762
if mountPoints is None:
@@ -65,8 +70,13 @@ def loadRemoteCacheServer():
6570
cacheServers = []
6671
label = lablesValue(None, "remotecache")
6772
if ret == 0 :
68-
data = json.loads(output)
73+
try:
74+
data = json.loads(output)
75+
except json.JSONDecodeError:
76+
return unitValue(label, cacheServers)
6977
result = data["result"]
78+
if "members" not in result:
79+
return unitValue(label, cacheServers)
7080
for cacheMember in result["members"]:
7181
cacheServers.append(ipPort2Addr(cacheMember["ip"],cacheMember["port"]))
7282
return unitValue(label, cacheServers)

0 commit comments

Comments
 (0)