Ad Widget

Collapse

1.7 api

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nelsonab
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Sep 2006
    • 1233

    #1

    1.7 api

    I don't know if this is a bug or not, but is there a specific reason for the call to phpinfo() on line 22 of the file api/rpc/class.czbxrpc.php?

    I've been trying to wrap my head around how the API works (some comments about how a basic call works would be great if someone could please add it) and the data returned by the phpinfo() is a real nuisance to work around.

    This is in the current trunk code.
    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

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

    #2
    IT WORKS!!!!

    After a few hours of hacking to understand how the API works I think I'm getting a grasp of it. What was not clear was that the parameters were a hash of values, once I figured that out and got rid of phpinfo() things went a lot quicker. It would have been very helpful if someone had put a sample JSON statement in one of the main API files, something like this would have helped a tremendous amount:
    Code:
    {"jsonrpc": "2.0", "method":"item.getID", "params":{"hostid":10017, "key_":"vm.memory.size[free]"}, "id":1, "auth":"nelsonab"}
    So far I have a very simple C# application talking to Zabbix. By simple I mean the application does a bare minimum of JSON construction.
    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

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

      #3
      More Thoughts....

      I'm finally getting up to speed with what the comments are actually telling me, the trick was getting to that point, fortunately there is a wealth of information in the comments when you understand them. :-)

      Maybe I'm just doing it wrong or it just does not exist, but there should be the ability to return everything, or a subset therein. For instance it would be useful to return all hosts, all host groups, all graphs, all items and so forth. I try the following and get an empty result set (yes the host ID is valid):
      Code:
      "method":"item.get", "params":{"with_items":true, "hostids":[10017]}
      Must I fully populate the params? If that is the case then I don't see a way to get a result set of everything, and I would consider that to be a needed rev 1 feature. I can understand that a result set of everything will be big, and I think an default result set limit is appropriate.
      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

      • Aly
        ZABBIX developer
        • May 2007
        • 1126

        #4
        1. Ofcourse, phpinfo() shouldn't be there
        2. Do you authenticate to API like:
        Code:
        {'jsonrpc': '2.0', 
        'method': 'user.authenticate',
        'params': {'user': 'admin', 'password': 'password'},
        'id': 1
        }
        3. get an answer with 'result' auth hash?
        4. Add 'auth' param to all your requests?
        Code:
        'jsonrpc': '2.0',
        'method': 'host.add',
        'params': {'hostid': '10017', 'host': 'TEST'},
        'auth': 'auth_hash',
        'id': 2
        5. No need to set all params, you can set none... all params will be set by default. In that case you should get all your groups, hosts, items ... e.t.c. (with access check)
        Zabbix | ex GUI developer

        Comment

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

          #5
          Originally posted by Aly
          3. get an answer with 'result' auth hash?
          4. Add 'auth' param to all your requests?
          Code:
          'jsonrpc': '2.0',
          'method': 'host.add',
          'params': {'hostid': '10017', 'host': 'TEST'},
          'auth': 'auth_hash',
          'id': 2
          5. No need to set all params, you can set none... all params will be set by default. In that case you should get all your groups, hosts, items ... e.t.c. (with access check)
          Ahhh... that was not very clear when I was going through the code, and that makes sense now that you explain it.
          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

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

            #6
            I must be missing something because I cannot get the functions item.get and host.get to work. User.get works just fine. There are no errors.

            Here's what I'm doing:
            Code:
            Sending: 
            {"jsonrpc": "2.0", 
            "method":"item.get", 
            "params":{"hostids":[10017]}, 
            "auth":"e8817623eb31e64f66fb78b6edb78372", 
            "id":7}
            
            Response: {"jsonrpc":"2.0","result":[],"id":7}
            __
            As you can see I just get an empty result set. What I want to do is get a list of all hosts or a list of all items associated with a host or hosts.
            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

            • Alexei
              Founder, CEO
              Zabbix Certified Trainer
              Zabbix Certified SpecialistZabbix Certified Professional
              • Sep 2004
              • 5654

              #7
              There must be documentation on the API already available on-line. I will check it tomorrow. Keep trying!
              Alexei Vladishev
              Creator of Zabbix, Product manager
              New York | Tokyo | Riga
              My Twitter

              Comment

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

                #8
                That would be great, it's been a somewhat uphill battle to understand what's supposed to happen and what's really happening.

                If I may make a request, in the class.* files at the start of every function is a comment block discussing the parameters required. This is a fantastic start, but if a few words could be added for some or all of the parameters as to what is expected.

                For example user.get, what is the purpose of the userids parameter? I thought I wanted to get all userids, why would I want to supply a list of user ids? There are a few places where some of the parameters are not self-evident.

                I am very excited to see some traction with testing the API. I'm working on building a windows App to allow people to test and play with the API in a basic way.
                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

                • Alexei
                  Founder, CEO
                  Zabbix Certified Trainer
                  Zabbix Certified SpecialistZabbix Certified Professional
                  • Sep 2004
                  • 5654

                  #9
                  Originally posted by nelsonab
                  For example user.get, what is the purpose of the userids parameter?
                  I believe all get() methods support getting of multiple objects by their IDs. So, you can supply array of IDs in order to get information about several users using only one API call.
                  Alexei Vladishev
                  Creator of Zabbix, Product manager
                  New York | Tokyo | Riga
                  My Twitter

                  Comment

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

                    #10
                    Originally posted by Alexei
                    I believe all get() methods support getting of multiple objects by their IDs. So, you can supply array of IDs in order to get information about several users using only one API call.
                    Ahh, that's what I thought, but I wasn't sure.
                    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

                    • maxence
                      Junior Member
                      • Mar 2007
                      • 5

                      #11
                      Sample of Json RPC client to the Zabbix API

                      Hi all,

                      Is someone have a workable sample of client API ?
                      That make hours that I try to access to it...

                      Below my testing code :
                      Code:
                      <HTML>
                      <script type="text/javascript">
                      
                      var the_object;
                      var http_request = new XMLHttpRequest();
                      var jsonrpc = {'jsonrpc': '2.0','method': 'user.authenticate','params': {'user': 'admin', 'password': 'password'},'id': 1};
                      http_request.open( "POST", '/zabbix/api_jsonrpc.php', true );
                      http_request.setRequestHeader('Content-Type', 'application/json-rpc');
                      http_request.send(jsonrpc);
                      http_request.onreadystatechange = function () {
                          if ( http_request.readyState == 4 ) {
                              if ( http_request.status == 200 ) {
                                  the_object = eval( "(" + http_request.responseText + ")" );
                                      document.getElementById("zone").innerHTML = http_request.responseText;
                              } else {
                                  alert( "There was a problem with the URL." );
                              }
                              http_request = null;
                          }
                      };
                      
                      </script>
                      <div id="zone"></div>
                      </HTML>
                      any hint ?

                      Thanks

                      Comment

                      • richlv
                        Senior Member
                        Zabbix Certified Trainer
                        Zabbix Certified SpecialistZabbix Certified Professional
                        • Oct 2005
                        • 3112

                        #12
                        i'd suggest taking a look at zabcon, zabbix console client that uses api.
                        more information at http://www.zabbix.com/wiki/
                        Zabbix 3.0 Network Monitoring book

                        Comment

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

                          #13
                          Originally posted by maxence
                          Hi all,

                          Is someone have a workable sample of client API ?
                          That make hours that I try to access to it...
                          The wiki will eventually take you to the Ruby API library I'm currently working on. Feel free to check it out and comment on it.

                          Quick overview on how to use it

                          1) Instantiate an object server=SbxAPI.new(url,debuglevel)
                          2) log into server, server.login(user,password)
                          3) use api, server.object.action(options) aka server.user.get(options)

                          The options are not very well documented yet, but they follow the comments in the Zabbix source closely.

                          The trac site I have setup for Zabcon allows you to browse the soruce and you can see in there kinda how things are happening.

                          Feedback is greatly appreciated!
                          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

                          Working...