1 回答
TA贡献1744条经验 获得超4个赞
这将比较两个 json 文件/字典。我注意到这些值是字符串列表......这是故意的吗?
import json
def open_json(path):
with open(path, 'r') as file:
return json.load(file)
def check_thresholds(data, thresholds):
for k, v in thresholds.items():
# your logic/output here
# k[0] and v[0] because your values are lists of strings... should they be just int of float?
difference = int(data.get(k)[0]) - int(v[0])
if difference >= 0:
print(f'WARNING: {k} has exceeded the threshold by {difference}')
else:
print(f'OK: {k}')
def main():
# load the data into dictionaries
data = open_json('./rv.json')
thresholds = open_json('./rv2.json')
# if your data is a dictionary and not json files then use these
# data = {'node1.storePool_Owner': ['160'], 'node1.storePool_Deleg': ['0'], 'node2.storePool_LockState': ['0']}
# thresholds = {'node1.storePool_Owner': ['1024000'], 'node1.storePool_Deleg': ['1024000'], 'node2.storePool_LockState': ['1024000']}
# run the checks
check_thresholds(data, thresholds)
main()
输出(我修改了一些值以显示警告):
WARNING: node1.storePool_Owner has exceeded the threshold by 1000
OK: node1.storePool_Deleg
OK: node2.storePool_LockState
添加回答
举报