使用 python 和 LLD Zabbix 发现顶级内存进程的序列键创建 JSON
Create JSON using python with sequence key for LLD Zabbix discovery top mem process
我尝试使用 python 和 LLD Zabbix 发现顶级内存进程的序列键创建 JSON
#!/usr/bin/python
import subprocess
import json
s = subprocess.Popen(["ps axho comm --sort -rss | head -5"], shell=True, stdout=subprocess.PIPE).stdout
service_states = s.read().splitlines()
count = 0
data = {"data":{}}
for i in service_states:
count += 1
key = "{#TOPMEMNAME" + str(count) + "}"
data["data"][key] = i
json_data = json.dumps(data)
print(json_data)
Get JSON 不接受 Zabbix(代码下方):
{
"data": {
"{#TOPMEMNAME2}": "node",
"{#TOPMEMNAME1}": "mongod",
"{#TOPMEMNAME4}": "ffmpeg",
"{#TOPMEMNAME3}": "kubelet",
"{#TOPMEMNAME5}": "dockerd"
}
}
下面是 Zabbix 接受的代码 JSON。
{
"data": [{
"{#TOPMEMNAME1}": "mongod"
},
{
"{#TOPMEMNAME2}": "node"
},
{
"{#TOPMEMNAME3}": "kubelet"
},
{
"{#TOPMEMNAME4}": "ffmpeg"
},
{
"{#TOPMEMNAME5}": "dockerd"
}
]
}
如何更改 python 获取 JSON zabbix 接受的代码?
data = {"data":{}}
# should be changed to the line below
data = {"data":[]}
data["data"][key] = i
# should be changed to the line below
data["data"].append({key:i})
我尝试使用 python 和 LLD Zabbix 发现顶级内存进程的序列键创建 JSON
#!/usr/bin/python
import subprocess
import json
s = subprocess.Popen(["ps axho comm --sort -rss | head -5"], shell=True, stdout=subprocess.PIPE).stdout
service_states = s.read().splitlines()
count = 0
data = {"data":{}}
for i in service_states:
count += 1
key = "{#TOPMEMNAME" + str(count) + "}"
data["data"][key] = i
json_data = json.dumps(data)
print(json_data)
Get JSON 不接受 Zabbix(代码下方):
{
"data": {
"{#TOPMEMNAME2}": "node",
"{#TOPMEMNAME1}": "mongod",
"{#TOPMEMNAME4}": "ffmpeg",
"{#TOPMEMNAME3}": "kubelet",
"{#TOPMEMNAME5}": "dockerd"
}
}
下面是 Zabbix 接受的代码 JSON。
{
"data": [{
"{#TOPMEMNAME1}": "mongod"
},
{
"{#TOPMEMNAME2}": "node"
},
{
"{#TOPMEMNAME3}": "kubelet"
},
{
"{#TOPMEMNAME4}": "ffmpeg"
},
{
"{#TOPMEMNAME5}": "dockerd"
}
]
}
如何更改 python 获取 JSON zabbix 接受的代码?
data = {"data":{}}
# should be changed to the line below
data = {"data":[]}
data["data"][key] = i
# should be changed to the line below
data["data"].append({key:i})