• python获取zabbix主机列表


    import requests
    import json
    
    headers = {
        'Content-Type': 'application/json'
    }
    
    class GetZabbix:
        def __init__(self):
            #用户信息
            self.username = "******"
            self.password = "******"
            self.url = "http://192.168.1.*/zabbix/api_jsonrpc.php"
            self.token = self.getToken()
    
        def getToken(self):
            data = {
                "jsonrpc": "2.0",
                "method": "user.login",
                "params": {
                    "user": self.username,
                    "password": self.password
                },
                "id": 1,
                "auth": None
            }
            r = requests.post(url=self.url, headers=headers, data=json.dumps(data))
            token = json.loads(r.content).get("result")
            return token
    
        def getHosts(self):
            data = {
                "jsonrpc": "2.0",
                "method": "host.get",
                "params": {
                    "output": [
                        "hostid",
                        "host"
                    ],
                    "selectInterfaces": [
                        "interfaceid",
                        "ip"
                    ]
                },
                "id": 2,
                "auth": self.token
            }
            r = requests.post(url=self.url, headers=headers, data=json.dumps(data))
            # print(r.content)
            res = json.loads(r.text)
            return res
  • 相关阅读:
    Oracle 更改DBID
    Oracle 修改字段长度
    Oracle 索引
    Oracle在无法打开数据库的状态下获取DBID
    Oracle 备份脚本
    Linux crontab计划任务
    Oracle restore和recovery的区别
    Django基础
    面向对象(一)
    socket
  • 原文地址:https://www.cnblogs.com/ttyypjt/p/12692039.html
Copyright © 2020-2023  润新知