Exemple #1
0
#!/usr/bin/env python
#coding:utf8
'''
Created on 2016年 08月 30日 星期二 11:23:23 CST
'''

from core import ZabbixAPI, zbx_conf

server = zbx_conf.get_conf("server")
username = zbx_conf.get_conf("username")
password = zbx_conf.get_conf("password")

if __name__ == "__main__":
    zapi = ZabbixAPI(server, username, password)

    try:
        hostinfo = zapi.trigger.get({
            "output": ["description", "lastchange", "triggerid"],
            "filter": {
                "value": 1
            },
            "selectHosts": ["hostid", "name"]
        })
        print hostinfo
    except:
        print "host not exist: %s" % server
    if not options.password:
        options.password = getpass()

    return options, args


def errmsg(msg):
    sys.stderr.write(msg + "\n")
    sys.exit(-1)


if __name__ == "__main__":
    options, args = get_options()

    zapi = ZabbixAPI(options.server, options.username, options.password)

    description = options.description
    expression = options.expression
    priority = options.priority
    filename = options.filename

    if filename:
        with open(filename, "r") as f:
            content = f.readlines()
            for i in content:
                l = i.split("    ")
                description = l[0].rstrip()
                expression = l[1].rstrip()
                print description, '\t', expression
                try: