zabbix批量删除监控项

利用python的requests json模块根据zabbix官方API文档进行批量删除zabbix监控项

zabbix 文档地址
https://www.zabbix.com/documentation/4.0/zh/manual

1.先获取zabbix的token,然后会返回一个token值

#!/usr/bin/python
import requests
import json

url="http://10.0.18.245/api_jsonrpc.php"
headers={"Content-Type":"application/json-rpc"}

#data={"jsonrpc":"2.0","method":"apiinfo.version","id":1,"auth":'null',"params":{}}
data={
    "jsonrpc":"2.0",
    "method":"user.login",
    "params":{
         "user":"Admin",
         "password":"zabbix"
          },
    "id":1,
}

r = requests.post(url,data = json.dumps(data),headers=headers)
print(r.json())

2.根据官方文档API请求头,在params中添加要删除的itemid

#!/usr/bin/python
import requests
import json

url="http://IP/api_jsonrpc.php"
headers={"Content-Type":"application/json"}

data={
    "jsonrpc": "2.0",
    "method": "item.delete",
    "params": [
        "30769",
        "30819",
        "36711",
        "36762",
        "36813",
        "36864",
        "36915",
        "36966",
        "37017",
        "37068",
        "37119",
        "37170",
        "37221",
        "37272",
        "37323",
    ],
    "auth": "0076f34d056e17687b482d7c18a6ae09",
    "id": 1
}

r = requests.post(url,data = json.dumps(data),headers=headers)
print(r.json())

你可能感兴趣的:(zabbix,zabbix,python,json,httpwebrequest,运维)