Ad Widget

Collapse

Python library for Zabbix API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wakko
    Junior Member
    • Dec 2008
    • 19

    #1

    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:
    GitHub is where people build software. More than 150 million people use GitHub to discover, fork, and contribute to over 420 million projects.


    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.
  • jamied66
    Member
    • Sep 2008
    • 37

    #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

    • wakko
      Junior Member
      • Dec 2008
      • 19

      #3
      Here's a sample script:
      GitHub is where people build software. More than 150 million people use GitHub to discover, fork, and contribute to over 420 million projects.
      Last edited by wakko; 07-01-2010, 00:44.

      Comment

      • jamied66
        Member
        • Sep 2008
        • 37

        #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

        • wakko
          Junior Member
          • Dec 2008
          • 19

          #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

          • jamied66
            Member
            • Sep 2008
            • 37

            #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

            • nelsonab
              Senior Member
              Zabbix Certified SpecialistZabbix Certified Professional
              • Sep 2006
              • 1233

              #7
              Originally posted by wakko
              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

              • jamied66
                Member
                • Sep 2008
                • 37

                #8
                good to know! thanks!

                Comment

                • jamied66
                  Member
                  • Sep 2008
                  • 37

                  #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

                  • wakko
                    Junior Member
                    • Dec 2008
                    • 19

                    #10
                    Originally posted by jamied66
                    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

                    • jamied66
                      Member
                      • Sep 2008
                      • 37

                      #11
                      Originally posted by wakko
                      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

                      • wakko
                        Junior Member
                        • Dec 2008
                        • 19

                        #12
                        Originally posted by jamied66
                        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

                        • jamied66
                          Member
                          • Sep 2008
                          • 37

                          #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

                          • Aly
                            ZABBIX developer
                            • May 2007
                            • 1126

                            #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

                            • tekknokrat
                              Senior Member
                              • Sep 2008
                              • 140

                              #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

                              Working...