Ad Widget

Collapse

Python library for Zabbix API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PieterB
    Junior Member
    Zabbix Certified Specialist
    • Jul 2010
    • 25

    #46
    Originally posted by gescheit
    Why need yet another python module?
    Stable? zabbix_api very stable. All problems that i catched was linked with zabbix side.
    Documentation? Main documentations - zabbix wiki. I think don't need copy and paste it to module.
    Don't do meaningless forks. Would be better if you help with me "well-documented" and examples.
    One reason could be Python 3?
    Last edited by PieterB; 28-12-2011, 13:58.

    Comment

    • PieterB
      Junior Member
      Zabbix Certified Specialist
      • Jul 2010
      • 25

      #47
      I use the following code snippet to get a long(er) text value...

      Code:
      for item in zapi.item.get({'filter': { 'hostid' : k, 'key_':'test1[]'} , 'output' :'extend'}):
                      print "%s %s %s %s %s" % (item['hostid'], item['itemid'],item['description'], item['lastvalue'], item['templateid'])
                      dicto[k] = item['lastvalue']
               print dicto
      The problem: not all the data is fetched (+- 512) (everything shows in zabbix frontend)

      How can I solve this?

      Comment

      • gescheit
        Senior Member
        • Jul 2007
        • 156

        #48
        Originally posted by PieterB
        One reason could be Python 3?
        Check my last commit. I add python3 compliant

        Comment

        • gescheit
          Senior Member
          • Jul 2007
          • 156

          #49
          Originally posted by PieterB
          I use the following code snippet to get a long(er) text value...

          Code:
          for item in zapi.item.get({'filter': { 'hostid' : k, 'key_':'test1[]'} , 'output' :'extend'}):
                          print "%s %s %s %s %s" % (item['hostid'], item['itemid'],item['description'], item['lastvalue'], item['templateid'])
                          dicto[k] = item['lastvalue']
                   print dicto
          The problem: not all the data is fetched (+- 512) (everything shows in zabbix frontend)

          How can I solve this?
          version of zabbix API? I check this:
          f =zapi.item.get({'filter': {},'output' :'extend'})
          print len(f)
          and always get true count of items.

          Comment

          • PieterB
            Junior Member
            Zabbix Certified Specialist
            • Jul 2010
            • 25

            #50
            Zabbix API 1.3
            Your latest version of Python API wrapper, Zabbix 1.8.8


            Some output from len()
            Code:
            16
            69
            57
            86
            86
            91
            91
            91
            9
            9
            9
            9
            9
            4
            255
            255
            16
            16
            16
            57
            74
            57
            219
            91
            74
            Seems to be only the first 255 char are returned by lastvalue.....

            Comment

            • gescheit
              Senior Member
              • Jul 2007
              • 156

              #51
              Originally posted by PieterB
              Zabbix API 1.3
              Seems to be only the first 255 char are returned by lastvalue.....
              Lastvalue really store only 256 chars. Use history.get

              Comment

              • PieterB
                Junior Member
                Zabbix Certified Specialist
                • Jul 2010
                • 25

                #52
                Originally posted by gescheit
                Lastvalue really store only 256 chars. Use history.get
                Stupid me. Thx a lot!

                Comment

                • Yello
                  Senior Member
                  • Apr 2011
                  • 309

                  #53
                  Hi,
                  How do I reduce the verbosity of the api output?


                  Regards,
                  David

                  Comment

                  • gescheit
                    Senior Member
                    • Jul 2007
                    • 156

                    #54
                    Originally posted by Yello
                    Hi,
                    How do I reduce the verbosity of the api output?


                    Regards,
                    David
                    zapi = zabbix_api.ZabbixAPI(server = "http://localhost", log_level = 40)

                    Comment

                    • Yello
                      Senior Member
                      • Apr 2011
                      • 309

                      #55
                      Item bulk creation

                      Hi,
                      I think there may be a problem with the item.create method of the api. My code looks like this:

                      items = []
                      items = builditems(conf,scen,step,hostid)
                      zapi.item.create(items)

                      The builditems function generates a set of items and returns a list (items). When I pass this list to zapi I get this error:

                      Traceback (most recent call last):
                      File "./webgen.py", line 178, in <module>
                      zapi.item.create(items)
                      File "/home/user/api/zabbix_api.py", line 365, in method
                      return self.universal("item.%s" % name, opts[0])
                      File "/home/user/api/zabbix_api.py", line 79, in wrapper
                      return self.do_request(self.json_obj(method, opts))['result']
                      File "/home/user/api/zabbix_api.py", line 337, in do_request
                      return self.parent.do_request(req)
                      File "/home/user/api/zabbix_api.py", line 301, in do_request
                      raise ZabbixAPIException(msg, jobj['error']['code'])
                      TypeError: __init__() takes exactly 2 arguments (3 given)

                      However, if I force builditems to return only 1 set of item parameters then item creation works. Is there something else I need to do in order to bulk load items?


                      Regards,
                      David
                      Last edited by Yello; 04-01-2012, 18:03.

                      Comment

                      • gescheit
                        Senior Member
                        • Jul 2007
                        • 156

                        #56
                        Please, show the "item" variable.

                        Comment

                        • Yello
                          Senior Member
                          • Apr 2011
                          • 309

                          #57
                          Hi,
                          False alarm. I've resolved the issue. I had a problem with the key format of one of the items I was building which was making the api see it as a duplicate.


                          Regards,
                          David

                          Comment

                          • bcarpio
                            Member
                            • Jun 2008
                            • 96

                            #58
                            Error In Latest zabbix_api.py

                            [/var/tmp/api]# python test.py
                            Traceback (most recent call last):
                            File "test.py", line 1, in ?
                            from zabbix_api import ZabbixAPI
                            File "/tmp/api/zabbix_api.py", line 283
                            except ValueError as msg:
                            ^
                            SyntaxError: invalid syntax

                            Comment

                            • bcarpio
                              Member
                              • Jun 2008
                              • 96

                              #59
                              Old python version

                              Since I am running RHEL/CentOS 5.6 I needed to install python26 from EPEL.

                              Comment

                              • mcmyst
                                Member
                                • Feb 2012
                                • 72

                                #60
                                Hi,

                                Thank you for your job on this library !

                                I am discovering the functionnality of the zabbix API, I would like to be able to see all the details about an item, but I can't see how ?

                                I know how to list all items id about a particular host:
                                Code:
                                list_item = zapi.item.get({"filter":{"hostids":hostid}})
                                for item in list_item:
                                	if item['itemid'] == '26062':
                                		print item
                                Now that I have the item id, what is the way to describe it ?

                                Thank you.

                                Comment

                                Working...