Ad Widget

Collapse

Python Zabbix 2.2 API help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vincentj
    Junior Member
    • Jan 2014
    • 2

    #1

    Python Zabbix 2.2 API help

    Hi! I'm new to Zabbix and am trying to get it to play nice with my existing python infrastructure. Using the pyzabbix module written by luckecyca, I am attempting to get host information from my zabbix server.

    However, in the simplest case, I cannot get the api to give me details about the hosts, only hostid. Same for hostgroup, only groupid. What I do is this:

    Code:
    #!/usr/bin/python -u
    
    from pyzabbix import ZabbixAPI
    
    zapi = ZabbixAPI("http://1.2.3.4/zabbix")
    zapi.login("user", "passwd")
    print "Connected to Zabbix API Version %s" % zapi.api_version()
    
    for h in zapi.host.get(extendoutput=True):
            print h
    
    for hg in zapi.hostgroup.get(extendoutput=True):
            print hg
    Output is as follows:
    Code:
    u'hostid': u'10105'}
    {u'hostid': u'10106'}
    {u'hostid': u'10107'}
    {u'hostid': u'10084'}
    {u'groupid': u'9'}
    {u'groupid': u'8'}
    {u'groupid': u'5'}
    {u'groupid': u'7'}
    {u'groupid': u'2'}
    {u'groupid': u'1'}
    {u'groupid': u'6'}
    {u'groupid': u'4'}
    These are very small json snippets. I cannot access any of the other parameters of the host or hostgroup objects.

    Am I missing something fundamental here? Do I need to be using a different API tool in python to access Zabbix 2.2?

    Thank you in advance.
  • vincentj
    Junior Member
    • Jan 2014
    • 2

    #2
    I solved it! It's an incompatibility between 2.0 and 2.2. To use pyzabbix, instead of using the argument extendoutput=True, use output='extend' instead.

    Thus, working code would like something like this (in my example above):
    Code:
    for h in zapi.host.get(output='extend'):
        print h
    Solution was found here.

    Comment

    • Malarvizhi
      Junior Member
      • Jan 2018
      • 8

      #3
      Unable to connect to Zabbix API via pyzabbix

      Hi,
      I m unable to connect to Zabbix API through pyzabbix. Getting below error while trying to login.
      Code Used :
      from pyzabbix import ZabbixAPI
      zapi = ZabbixAPI("http://1.2.3.4/zabbix")
      zapi.login("user", "passwd")

      Error Message :
      File "<stdin>", line 1, in <module>
      File "build/bdist.linux-x86_64/egg/pyzabbix/__init__.py", line 70, in login
      File "build/bdist.linux-x86_64/egg/pyzabbix/__init__.py", line 157, in fn
      File "build/bdist.linux-x86_64/egg/pyzabbix/__init__.py", line 109, in do_request
      File "/usr/lib/python2.7/site-packages/requests/models.py", line 834, in raise_for_status
      raise HTTPError(http_error_msg, response=self)
      requests.exceptions.HTTPError: 403 Client Error: Forbidden

      Comment

      Working...