美文网首页
通过zabbix api 查看templateid。

通过zabbix api 查看templateid。

作者: Al_不期而遇 | 来源:发表于2019-02-13 09:13 被阅读1次

    考虑后面需要通过api的方式添加主机、那么我们要获取需要模板的ID。

    这里我新建zabbix_api_template.py内容如下

    # -*- coding: UTF-8 -*-

    import urllib2,json,cookielib,urllib

    from urllib2 import Request, urlopen, URLError, HTTPError

    global auth_code,zabbix_url,zabbix_header

    zabbix_url="http://192.168.1.101/zabbix/api_jsonrpc.php"

    zabbix_header = {"Content-Type":"application/json"}

    zabbix_user  = "Admin"

    zabbix_pass  = "zabbix"

    auth_code    = ""

    auth_data = json.dumps({

        "jsonrpc":"2.0",

        "method":"user.login",

        "params":

                {

                "user":Admin,

                "password":zabbix

                },

        "id":0

        })

    request = urllib2.Request(zabbix_url,auth_data)

    for key in zabbix_header:

        request.add_header(key,zabbix_header[key])

    try:

        result = urllib2.urlopen(request)

    except HTTPError, e:

        print 'The server couldn\'t fulfill the request, Error code: ', e.code

    except URLError, e:

        print 'We failed to reach a server.Reason: ', e.reason

    else:

        response=json.loads(result.read())

        #print response

        result.close()

    if  'result'  in  response:

        auth_code=response['result']

    else:

        print  response['error']['data']

    def Http_access(data):

        request = urllib2.Request(zabbix_url,data)

        for key in zabbix_header:

            request.add_header(key,zabbix_header[key])

        result = urllib2.urlopen(request)

        response = json.loads(result.read())

        # print result.read()

        # print response

        result.close() 

        if len(response['result']) > 0:

            return response['result']

    def Http_access(data):

        request = urllib2.Request(zabbix_url,data)

        for key in zabbix_header:

            request.add_header(key,zabbix_header[key])

        result = urllib2.urlopen(request)

        response = json.loads(result.read())

        # print result.read()

        #print response

        result.close() 

        if len(response['result']) > 0:

            return response['result']

    def get_template():

        template_data = json.dumps({

            "jsonrpc": "2.0",

            "method": "template.get",

            "params": {

                "output": "extend"

            },

            "auth": auth_code,

            "id": 1

        })

        return template_data

    templatedata = get_template()

    for template in Http_access(templatedata):

        print template['templateid'],template['host']

    python zabbix_api_template.py输出结果

    10001 Template OS Linux

    10047 Template App Zabbix Server

    10048 Template App Zabbix Proxy

    10050 Template App Zabbix Agent

    10074 Template OS OpenBSD

    10075 Template OS FreeBSD

    10076 Template OS AIX

    10077 Template OS HP-UX

    10078 Template OS Solaris

    10079 Template OS Mac OS X

    10081 Template OS Windows

    10093 Template App FTP Service

    10094 Template App HTTP Service

    10095 Template App HTTPS Service

    10096 Template App IMAP Service

    10097 Template App LDAP Service

    10098 Template App NNTP Service

    10099 Template App NTP Service

    10100 Template App POP Service

    10101 Template App SMTP Service

    10102 Template App SSH Service

    10103 Template App Telnet Service

    10168 Template App Apache Tomcat JMX

    10169 Template App Generic Java JMX

    10170 Template DB MySQL

    10171 Template Server Intel SR1530 IPMI

    10172 Template Server Intel SR1630 IPMI

    10173 Template VM VMware

    10174 Template VM VMware Guest

    10175 Template VM VMware Hypervisor

    10182 Template Module EtherLike-MIB SNMPv1

    10183 Template Module EtherLike-MIB SNMPv2

    10184 Template Module HOST-RESOURCES-MIB SNMPv1

    10185 Template Module HOST-RESOURCES-MIB SNMPv2

    10186 Template Module ICMP Ping

    10187 Template Module Interfaces Simple SNMPv1

    10188 Template Module Interfaces Simple SNMPv2

    10189 Template Module Interfaces SNMPv1

    10190 Template Module Interfaces SNMPv2

    10192 Template Module Interfaces Windows SNMPv2

    10203 Template Module Generic SNMPv1

    10204 Template Module Generic SNMPv2

    10207 Template Net Alcatel Timetra TiMOS SNMPv2

    10208 Template Net Brocade FC SNMPv2

    10209 Template Module Brocade_Foundry Performance SNMPv2

    10210 Template Net Brocade_Foundry Nonstackable SNMPv2

    10211 Template Net Brocade_Foundry Stackable SNMPv2

    10212 Template Module Cisco CISCO-MEMORY-POOL-MIB SNMPv2

    10213 Template Module Cisco CISCO-PROCESS-MIB SNMPv2

    10215 Template Module Cisco OLD-CISCO-CPU-MIB SNMPv2

    10216 Template Module Cisco Inventory SNMPv2

    10217 Template Module Cisco CISCO-ENVMON-MIB SNMPv2

    10218 Template Net Cisco IOS SNMPv2

    10220 Template Net Cisco IOS prior to 12.0_3_T SNMPv2

    10221 Template Net Dell Force S-Series SNMPv2

    10222 Template Net D-Link DES 7200 SNMPv2

    10223 Template Net D-Link DES_DGS Switch SNMPv2

    10224 Template Net Extreme EXOS SNMPv2

    10225 Template Net Network Generic Device SNMPv1

    10226 Template Net Network Generic Device SNMPv2

    10227 Template Net HP Comware HH3C SNMPv2

    10229 Template Net Huawei VRP SNMPv2

    10230 Template Net Intel_Qlogic Infiniband SNMPv2

    10231 Template Net Juniper SNMPv2

    10233 Template Net Mikrotik SNMPv2

    10234 Template Net Netgear Fastpath SNMPv2

    10235 Template Net QTech QSW SNMPv2

    10236 Template Net TP-LINK SNMPv2

    10237 Template Net Ubiquiti AirOS SNMPv1

    10248 Template OS Linux SNMPv2

    10249 Template OS Windows SNMPv2

    10250 Template Net HP Enterprise Switch SNMPv2

    10251 Template Net Mellanox SNMPv2

    10252 Template Module Cisco CISCO-PROCESS-MIB IOS versions 12.0_3_T-12.2_3.5 SNMPv2

    10253 Template Net Cisco IOS versions 12.0_3_T-12.2_3.5 SNMPv2

    10254 Template App Citrix

    10255 Template Cisco CPU Memory

    10256 Template DCS DB

    10257 Template DCS UNIX

    10258 DHCP server Template

    10259 dvd_Template_NetScaler_9

    10260 EITI Template Hyper-v Replication

    10267 Templates Email health for itil

    10268 Template EMC Navisphere

    10269 Template Exchange Client Access Server Performance Monitoring

    10270 Template Exchange Client Access Server

    10271 Template_F5_SNMP

    10272 Template_HP_SNMP_Autodiscovery

    10273 Template HUAWEI  CPU Memory

    10274 Template ICMP Ping For Itil wifi rpi

    10275 Template Lync 2013 Front End Server

    10276 MES MES Template Windows 2008 R2 Server

    10277 Template_Oracle

    10278 Template IBM - IMM2 SNMP

    10279 Template ICMP Ping For Itil

    10280 Template Microsoft Exchange Server 2010

    10281 Template OS Windows For ITIL Health

    10282 Template Radware Alteon

    10283 Template SNMP Interfaces for ITIL

    10284 Template-SNMP-iDRAC-7-8

    10285 Template Wifi

    10286 Template Windows Log

    10287 Template Windows 2008 R2 DNS Server Performance Monitoring

    10288 Template Windows 2008 R2 DNS Server

    10289 Template Windows 2008 R2 Domain Controller Performance Monitor

    10290 Template Windows 2008 R2 Domain Controller

    10291 Template Windows 2008 R2 Server Performance Monitoring

    10292 Template Windows 2008 R2 Server

    10302 Template Module Cisco CISCO-PROCESS-MIB IOS later to 12.0_3_T and prior to 12.2_3.5 SNMPv2

    10303 Template Net Cisco IOS later to 12.0_3_T and prior to 12.2_3.5 SNMPv2

    10311 Template OS Linux For Itil

    10315 Template Docker Auto Discovery

    10317 Template SNMP Interfaces Health

    相关文章

      网友评论

          本文标题:通过zabbix api 查看templateid。

          本文链接:https://www.haomeiwen.com/subject/hvkreqtx.html