Python library for Zabbix API

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Python library for Zabbix API

    Hello all -

    I wanted to share my work with the rest of you.

    I've ported Andrew Nelson's Zabbix API interface over to Python.

    The file is located on my github account, here:
    http://github.com/wakko666/scripts/b.../zabbix_api.py

    There are some minor differences between my version and Andrew's that add extended functionality, but otherwise it's a direct port of the base features.

    #2
    great!

    Hey wakko! Great start!

    Could you put up a few usage examples to get us started, possibly? I'm primarily a Django guy and have never written a full-on API (some simple XMLRPC ones a while back, but not very complex), but I'd love to help.

    Thanks again for sharing the work!

    Comment


      #3
      Here's a sample script:
      http://github.com/wakko666/scripts/b...ix_rpc_test.py
      Last edited by wakko; 07-01-2010, 00:44.

      Comment


        #4
        Code:
        ZabbixAPIException: Error -32602: Invalid params., Action does not exists
        This error indicates this action isn't available yet in the API (in this case host.getId, and have run into it with item.getById), is that correct?

        Comment


          #5
          That error's correct. Andrew's Ruby API has the same problem.

          The API docs claim that getById exists, but the code appears to tell a different story. I only see the get() method in the php.

          I have a feeling it's on the todo list for a future release.

          For now, to work around the incomplete API, you can do something like this:

          zapi.host.get({ 'monitored_hosts' : True, 'extendoutput' : True })

          The extendoutput will return more information about the host objects than just the id number.


          More info here: http://www.zabbix.com/documentation/...jects/host#get

          Comment


            #6
            yeah. you can also use something like
            a = zapi.host.get({'hostids': ('10051'), 'extendoutput': True})

            if you want just a single host (the array can be increased of course as well)

            Comment


              #7
              Originally posted by wakko View Post
              That error's correct. Andrew's Ruby API has the same problem.

              The API docs claim that getById exists, but the code appears to tell a different story. I only see the get() method in the php.

              I have a feeling it's on the todo list for a future release.

              For now, to work around the incomplete API, you can do something like this:

              zapi.host.get({ 'monitored_hosts' : True, 'extendoutput' : True })

              The extendoutput will return more information about the host objects than just the id number.


              More info here: http://www.zabbix.com/documentation/...jects/host#get
              GetById was removed just before 1.8 was released.
              RHCE, author of zbxapi
              Ansible, the missing piece (Zabconf 2017): https://www.youtube.com/watch?v=R5T9NidjjDE
              Zabbix and SNMP on Linux (Zabconf 2015): https://www.youtube.com/watch?v=98PEHpLFVHM

              Comment


                #8
                good to know! thanks!

                Comment


                  #9
                  It looks like the host.getId function isn't in the source code, either.

                  That could have saved a TON of time for (at least)me, and I'm sure others. Is it planning on making a comeback?

                  Comment


                    #10
                    Originally posted by jamied66 View Post
                    It looks like the host.getId function isn't in the source code, either.

                    That could have saved a TON of time for (at least)me, and I'm sure others. Is it planning on making a comeback?
                    Sounds like I might just want to update my library to implement the logic to provide those functions.

                    Comment


                      #11
                      Originally posted by wakko View Post
                      Sounds like I might just want to update my library to implement the logic to provide those functions.
                      a host.get({'pattern' : somevar ... would be a pretty powerful tool, I'd think...

                      I'd be happy to help. Now that you've shown me the path.

                      Comment


                        #12
                        Originally posted by jamied66 View Post
                        I'd be happy to help. Now that you've shown me the path.
                        Sure, anyone is welcome to help. Clone my git repo, and send patches or pull requests via PM.

                        Comment


                          #13
                          Code:
                          >>> from tomsweb.zabbix.api import zabbix_api
                          >>> _zapi = zabbix_api(server="zabbix.mgcorp.net", debug_level=6)
                          DEBUG(6) : url: http://zabbix.mgcorp.net/api_jsonrpc.php
                          >>> _zapi.login('xxxx', 'xxxx')
                          >>> _info = _zapi.host.get({'hostids' : (10151), 'extendoutput' : True })
                          >>> for a in _info:
                          ...   status = a['status']
                          ...
                          >>> status
                          u'0'
                          
                          >>> from tomsweb.zabbix.api import zabbix_api
                          >>> _zapi = zabbix_api(server="zabbix.mgcorp.net", debug_level=6)
                          DEBUG(6) : url: http://zabbix.mgcorp.net/api_jsonrpc.php
                          >>> _zapi.login('xxxx', 'xxxx')
                          >>> _info = _zapi.host.get({'hostids' : (10127), 'extendoutput' : True })
                          >>> for a in _info:
                          ...   status = a['status']
                          ...
                          >>> status
                          u'0'
                          the first example is a halted system. the 2nd example is an active system. I'm assuming 'status' from the host class simply indicates whether or not a system is monitored? And not whether or not its up?

                          Comment


                            #14
                            ****.getByID won't comeback, there is no point to keep it..
                            It's the same as someobject.get('someobjectids': (someobjectid), 'extendoutput': 1);
                            Zabbix | ex GUI developer

                            Comment


                              #15
                              I tried the script with the rpc_test script.
                              When connecting I get this message:

                              Code:
                              Error -32602: Invalid params., Action (checkauth) does not exist
                              Zabbix Release 1.8.1

                              Comment

                              Announcement

                              Collapse
                              No announcement yet.
                              Working...
                              X