zabbix如果通过API接口添加MAP主机

zabbix如果通过API接口添加MAP主机

格式需要怎么写?

已经能通过API生产MAP。


import requests
import json

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

# 用户名和密码
username = "your_zabbix_username"
password = "your_zabbix_password"

# 认证请求
auth_data = {
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {
        "user": username,
        "password": password
    },
    "id": 1,
    "auth": None
}

response = requests.post(url, headers=headers, data=json.dumps(auth_data))
auth_token = response.json()["result"]

# 添加地图主机
map_data = {
    "jsonrpc": "2.0",
    "method": "map.addhost",
    "params": {
        "sysmapid": 1,
        "hostid": 12345,
        "elements": [
            {
                "elementtype": 0,
                "elementid": 12345,
                "x": 100,
                "y": 100
            }
        ]
    },
    "auth": auth_token,
    "id": 1
}

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