api添加主机组和主机zabbix_addgrouphost.py
import zabbix_base
# 获取token
token=zabbix_base.get_token()
# 添加主机组
groupname="python_add_group"
data = {
"jsonrpc": "2.0",
"method": "hostgroup.create",
"params": {
"name":groupname,
},
"auth":token,
"id": 1
}
result=zabbix_base.zabbix_api_common(data)
print(result)
# 添加主机
hostname="python_add_host"
hostip="192.168.3.222"
groupid="19" # 使用zabbix_group.py获取到主机组check_mysql的groupid为20
templateid="10342" # 模板check_mysql的id
data = {
"jsonrpc": "2.0",
"method": "host.create",
"params": {
"host": hostname,
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": hostip,
"dns": "",
"port": "10050"
}
],
"groups": [
{
"groupid": groupid
}
],
"templates": [
{
"templateid": templateid
}
]
},
"auth": token,
"id": 1
}
result=zabbix_base.zabbix_api_common(data)
print(result)