Ad Widget

Collapse

Problem with API in zabbix 1.8.2

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jason
    Senior Member
    • Nov 2007
    • 430

    #1

    Problem with API in zabbix 1.8.2

    Previously in 1.8.0 and 1.8.1 using the php functions from http://andrewfarley.com/php/zabbix-1...php-class-v1-0 I managed to :

    use Template GetObjects to get a templateid ($tempid) for a named template
    use the templateid on host get to get a list of all hosts with that template specifying 'select_items' =>1, 'sortfield' ='host','templateids' =>$tempid

    However, when I try doing the same thing on 1.8.2 I can get the templateID correctly, but when I try a host get to get a list of hosts all I get returned is the zabbix server itself. Has anything changed that would explain this?

    the api_user in zabbix is a superadmin so should have all the access needed.
  • Aly
    ZABBIX developer
    • May 2007
    • 1126

    #2
    Sorry not quite understand, may be you could give us JSON requests/responses?!
    Zabbix | ex GUI developer

    Comment

    • Jason
      Senior Member
      • Nov 2007
      • 430

      #3
      My mistake... The problem is in GetObjects. When I request the template ID for a specific name I get an array returned of all templates and not just the one I requested.

      Since I'm using the PHP lib to pull data back and forth I don't think I can easily extract the full rpc call, but what I have is..

      POST
      [10015] => {"auth":"536fcdf0d2fc4b7c15cd25993143c4bf","method ":"template.getObjects","id":1,"params":{"template ":"Template_BackupExec"},"jsonrpc":"2.0"}

      and the response on 1.8.2 is (not all shown here to keep within limits)

      Got response from API: ({"jsonrpc":"2.0","result":{"100100000010001":{"ho stid":"100100000010001","proxy_hostid":"0","host": "Template_Linux","dns":"","useip":"0","ip":"","por t":"10050","status":"3","disable_until":"0","error ":"","available":"0","errors_from":"0","lastaccess ":"0","inbytes":"0","outbytes":"0","useipmi":"0"," ipmi_port":"623","ipmi_authtype":"0","ipmi_privile ge":"2","ipmi_username":"","ipmi_password":"","ipm i_disable_until":"0","ipmi_available":"0","snmp_di sable_until":"0","snmp_available":"0","maintenance id":"0","maintenance_status":"0","maintenance_type ":"0","maintenance_from":"0","ipmi_ip":"127.0.0.1" ,"ipmi_errors_from":"0","snmp_errors_from":"0","ip mi_error":"","snmp_error":"","templateid":"1001000 00010001"},"100100000010002":{"hostid":"1001000000 10002","proxy_hostid":"0","host":"Template_Windows ","dns":"","useip":"0","ip":"","port":"10050","sta tus":"3","disable_until":"0","error":"","available ":"0","errors_from":"0","lastaccess":"0","inbytes" :"0","outbytes":"0","useipmi":"0","ipmi_port":"623 ","ipmi_authtype":"0","ipmi_privilege":"2","ipmi_u sername":"","ipmi_password":"","ipmi_disable_until ":"0","ipmi_available":"0","snmp_disable_until":"0 ","snmp_available":"0","maintenanceid":"0","mainte nance_status":"0","maintenance_type":"0","maintena nce_from":"0","ipmi_ip":"127.0.0.1","ipmi_errors_f rom":"0","snmp_errors_from":"0","ipmi_error":"","s nmp_error":"","templateid":"100100000010002"},"100 100000010003":{"hostid":"100100000010003","proxy_h ostid":"0","host":"Template_App_MySQL","dns":"","u seip":"0","ip":"","port":"10050","status":"3","dis able_until":"0","error":"","available":"0","errors _from":"0","lastaccess":"0","inbytes":"0","outbyte s":"0","useipmi":"0","ipmi_port":"623","ipmi_autht ype":"0","ipmi_privilege":"2","ipmi_username":""," ipmi_password":"","ipmi_disable_until":"0","ipmi_a vailable":"0","snmp_disable_until":"0","snmp_avail able":"0","maintenanceid":"0","maintenance_status" :"0","maintenance_type":"0","maintenance_from":"0" ,"ipmi_ip":"127.0.0.1","ipmi_errors_from":"0","snm p_errors_from":"0","ipmi_error":"","snmp_error":"" ,"templateid":"100100000010003"},"100100000010007" :{"hostid":"100100000010007","proxy_hostid":"0","h ost":"Template_SNMPv2_Device","dns":"","useip":"0" ,"ip":"","port":"10050","status":"3","disable_unti l":"0","error":"","available":"0","errors_from":"0 ","lastaccess":"0","inbytes":"0","outbytes":"0","u seipmi":"0","ipmi_port":"623","ipmi_authtype":"0", "ipmi_privilege":"2","ipmi_username":"","ipmi_pass word":"","ipmi_disable_until":"0","ipmi_available" :"0","snmp_disable_until":"0","snmp_available":"0" ,"maintenanceid":"0","maintenance_status":"0","mai ntenance_type":"0","maintenance_from":"0","ipmi_ip ":"127.0.0.1","ipmi_errors_from":"0","snmp_errors_ from":"0","ipmi_error":"","snmp_error":"","templat eid":"100100000010007"},"100100000010008":{"hostid ":"100100000010008","proxy_hostid":"0","host":"Tem plate_FreeBSD","dns":"Template_FreeBSD","useip":"0 ","ip":"","port":"10050","status":"3","disable_unt il":"0","error":"","available":"0","errors_from":" 0","lastaccess":"0","inbytes":"0","outbytes":"0"," useipmi":"0","ipmi_port":"623","ipmi_authtype":"0" ,"ipmi_privilege":"2","ipmi_username":"","ipmi_pas sword":"","ipmi_disable_until":"0","ipmi_available ":"0","snmp_disable_until":"0","snmp_available":"0 ","maintenanceid":"0","maintenance_status":"0","ma intenance_type":"0","maintenance_from":"0","ipmi_i p":"127.0.0.1","ipmi_errors_from":"0","snmp_errors _from":"0","ipmi_error":"","snmp_error":"","templa teid":"100100000010008"},"100100000010009":
      [snipped to shorten]
      {"hostid":"100100000010099","proxy_hostid":"0","ho st":"Template_PandaAV","dns":"","useip":"0","ip":" 0.0.0.0","port":"10050","status":"3","disable_unti l":"0","error":"","available":"0","errors_from":"0 ","lastaccess":"0","inbytes":"0","outbytes":"0","u seipmi":"0","ipmi_port":"623","ipmi_authtype":"0", "ipmi_privilege":"2","ipmi_username":"","ipmi_pass word":"","ipmi_disable_until":"0","ipmi_available" :"0","snmp_disable_until":"0","snmp_available":"0" ,"maintenanceid":"0","maintenance_status":"0","mai ntenance_type":"0","maintenance_from":"0","ipmi_ip ":"127.0.0.1","ipmi_errors_from":"0","snmp_errors_ from":"0","ipmi_error":"","snmp_error":"","templat eid":"100100000010099"},"100100000010101":{"hostid ":"100100000010101","proxy_hostid":"0","host":"Tem plate_BackupExec","dns":"","useip":"0","ip":"0.0.0 .0","port":"10050","status":"3","disable_until":"0 ","error":"","available":"0","errors_from":"0","la staccess":"0","inbytes":"0","outbytes":"0","useipm i":"0","ipmi_port":"623","ipmi_authtype":"-1","ipmi_privilege":"2","ipmi_username":"","ipmi_p assword":"","ipmi_disable_until":"0","ipmi_availab le":"0","snmp_disable_until":"0","snmp_available": "0","maintenanceid":"0","maintenance_status":"0"," maintenance_type":"0","maintenance_from":"0","ipmi _ip":"127.0.0.1","ipmi_errors_from":"0","snmp_erro rs_from":"0","ipmi_error":"","snmp_error":"","temp lateid":"100100000010101"},"100100000010102": [snipped to shorten]

      which is an array containing all the templates and not what I thought it should do.

      the same result on 1.8.1 and 1.8.0 is..

      Got response from API: ({"jsonrpc":"2.0","result":{"100100000010101":{"ho stid":"100100000010101","proxy_hostid":"0","host": "Template_BackupExec","dns":"","useip":"0","ip":"0 .0.0.0","port":"10050","status":"3","disable_until ":"0","error":"","available":"0","errors_from":"0" ,"lastaccess":"0","inbytes":"0","outbytes":"0","us eipmi":"0","ipmi_port":"623","ipmi_authtype":"-1","ipmi_privilege":"2","ipmi_username":"","ipmi_p assword":"","ipmi_disable_until":"0","ipmi_availab le":"0","snmp_disable_until":"0","snmp_available": "0","maintenanceid":"0","maintenance_status":"0"," maintenance_type":"0","maintenance_from":"0","ipmi _ip":"127.0.0.1","ipmi_errors_from":"0","snmp_erro rs_from":"0","ipmi_error":"","snmp_error":"","temp lateid":"100100000010101"}},"id":1})

      Here you can see it just returns the template I asked for with the correct ID.

      Comment

      • Aly
        ZABBIX developer
        • May 2007
        • 1126

        #4
        You should call: Template.get({"filter": {"host": "Template_BackupExec"}})
        Zabbix | ex GUI developer

        Comment

        • Jason
          Senior Member
          • Nov 2007
          • 430

          #5
          Ok, That works nicely thankyou. Is there any updated docs on the API as this seems to be a change from previous versions?

          The host filtering seems to have changed as well...

          if I call with

          {"auth":"3e3f19bac3651b8dbc63b8042dfafee1","method ":"item.get","id":1,"params":{"extendoutput":1,"fi lter":1,"host":"somehost","key":"BE_job"},"jsonrpc ":"2.0"}

          then I get a full list of items for somehost rather than those filtered by key (I have tried both key and key_

          Is there a way of doing this?

          Comment

          • Aly
            ZABBIX developer
            • May 2007
            • 1126

            #6
            {"auth":"3e3f19bac3651b8dbc63b8042dfafee1","met hod ":"item.get","id":1,"params":{"output": "extend", "filter":{"host":"somehost","key_":"BE_job"}},"jso nrpc ":"2.0"}
            Zabbix | ex GUI developer

            Comment

            • Jason
              Senior Member
              • Nov 2007
              • 430

              #7
              Thankyou again. That has done the job nicely!

              If I wanted to match just part of a key would the above do it or only match the entirety of a key? Other places I'd like to be able to see, for example, if the start of the key is BE_job?

              Comment

              • Aly
                ZABBIX developer
                • May 2007
                • 1126

                #8
                {"auth":"3e3f19bac3651b8dbc63b8042dfafee1","met hod ":"item.get","id":1,"params":{"output": "extend", "filter":{"host":"somehost"}, "patternKey": "BE_job"},"jso nrpc ":"2.0"}
                Zabbix | ex GUI developer

                Comment

                • Jason
                  Senior Member
                  • Nov 2007
                  • 430

                  #9
                  Cheers for that.

                  Are there plans to update the documentation online about this?

                  Comment

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

                    #10
                    Originally posted by Jason
                    Cheers for that.

                    Are there plans to update the documentation online about this?
                    I would also suggest a change doc for each version of the API. Right now there is no way to tell what has and has not been fixed/broken/changed between versions without testing, which is quite annoying. Even if the change doc is as simple as a list of functions which have been modified, something is better than what there is now. Then we can work on making that something better... :-)
                    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

                    • Jason
                      Senior Member
                      • Nov 2007
                      • 430

                      #11
                      I don't mind working on something that already exists, but there isn't an easy way of finding out what you can do currently. The API documentation currently on the doc site is so out of date and the commands it suggests are just plain wrong compared with the current version.

                      Comment

                      Working...