Ad Widget

Collapse

Need help with API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fjrial
    Senior Member
    • Feb 2010
    • 140

    #16
    Yes; I'm using http auth.

    I'm already following the zbx-2078 issue.

    But I couldn't get it work using the patch provided in the issue.

    Any other clue?

    Thanks

    Comment

    • gpmidi
      Member
      • Aug 2009
      • 62

      #17
      Orgional Zabbix Admin Password

      Try using the login option with the original Zabbix user's password. Also make sure you have the API enabled for the user you are using.
      -Paul

      Comment

      • fjrial
        Senior Member
        • Feb 2010
        • 140

        #18
        now trying with ldap

        I couldn't get to work with http, but as I'll need to use ldap authentication, I just configured zabbix to work against our ldap server.

        In the http fronted, if I try to login with our ldap accounts, and even with zabbix internal acounts, it works fine.

        But, again, no success with api login. I'm trying with an ldap account which in Zabbix belongs to group "Api Access" and even with an internal zabbix user that also belongs to group "Api access". Both users are enabled.

        Did someone connect to zabbix API through PHP? I'm using "jsonRPCClient".

        Thanks for your help.

        Comment

        • Aly
          ZABBIX developer
          • May 2007
          • 1126

          #19
          Enable debug mode for jsonRPCClient and copy here requests sent by client and server answers.
          Zabbix | ex GUI developer

          Comment

          • fjrial
            Senior Member
            • Feb 2010
            • 140

            #20
            Hi:

            I'm going to try with a perl client, because I think that it might be a problem because of the php client: this was in my error.log:

            Undefined variable: debug in /var/www/html/jsonRPCClient.php on line 145
            PHP Notice: Undefined index: id in /var/www/html/jsonRPCClient.php on line 151
            PHP Notice: Undefined index: id in /var/www/html/jsonRPCClient.php on line 152

            I'll post my results after trying with the perl client.

            thanks again.

            Comment

            • fjrial
              Senior Member
              • Feb 2010
              • 140

              #21
              Here again:

              Checked with perl client and logged successful as first try:
              Code:
              $VAR1 = bless( {
                               'error_class' => 'JSON::RPC::Common::Procedure::Return::Version_2_0::Error',
                               'version' => '2.0',
                               'id' => '1',
                               'result' => '0e6e3c5c97d364f12cae03653bc2b19b'
                             }, 'JSON::RPC::Common::Procedure::Return::Version_2_0' );
              So, anyone had sucess trying to login to API within a PHP Jason-RPC client?? if yes, which client?

              Thanks again.

              Comment

              • fjrial
                Senior Member
                • Feb 2010
                • 140

                #22
                zabbix-1-8-api-php-class-v1-0

                Just one minute ago I tried with Andrew Farley's API class and everything worked like a charm..



                And, at least for me, the jsonRPCClient that I mentioned before, don't work.

                Thanks to all for your help.

                Comment

                • olex
                  Junior Member
                  • Mar 2011
                  • 5

                  #23
                  Originally posted by fjrial
                  Just one minute ago I tried with Andrew Farley's API class and everything worked like a charm..



                  And, at least for me, the jsonRPCClient that I mentioned before, don't work.

                  Thanks to all for your help.
                  Maybe I don't know well what to do with this class.
                  Code:
                  <?php
                  require_once("ZabbixAPI.class.php");
                  
                  // This enables debugging, this is rather verbose but can help debug problems
                  //ZabbixAPI::debugEnabled(TRUE);
                  
                  // This logs into Zabbix, and returns false if it fails
                  ZabbixAPI::login('http://192.168.1.51/zabbix','olex','fjhfhjkjkffk')
                      or die('Unable to login: '.print_r(ZabbixAPI::getLastError(),true));
                  
                  // This gets the version of the zabbix server
                  $version = ZabbixAPI::fetch_string('apiinfo','version')
                      or die('Unable to get Zabbix Version: '.print_r(ZabbixAPI::getLastError(),true));
                  echo "Server running Zabbix API Version: $version\n<br>";
                  When I try to use example I have

                  Code:
                  php /usr/share/zabbix/example.php
                  PHP Fatal error:  Call to undefined method stdClass::__login() in /usr/share/zabbix/ZabbixAPI.class.php on line 99
                  I don't no, what kind of problem it is. Can anyone help me?

                  Comment

                  • fjrial
                    Senior Member
                    • Feb 2010
                    • 140

                    #24
                    Hi:

                    First, check that your user olex is member of the api access usergroup. Check that have api_access enabled.

                    Also, in order to work, I needed to uncomment the line
                    ZabbixAPI::debugEnabled(TRUE);

                    Give it a try and comment.
                    Cheers.

                    Comment

                    • olex
                      Junior Member
                      • Mar 2011
                      • 5

                      #25
                      Thanks for replay, I will do it and answer soon. My user is in api group, and where can I see if api_access enabled?

                      Comment

                      • olex
                        Junior Member
                        • Mar 2011
                        • 5

                        #26
                        If it is in administrative tools - yes, enable

                        Comment

                        • fjrial
                          Senior Member
                          • Feb 2010
                          • 140

                          #27
                          So next one is uncomment the line ZabbixAPI::debugEnabled(TRUE);

                          Comment

                          • olex
                            Junior Member
                            • Mar 2011
                            • 5

                            #28
                            It's very interesting - seems that with uncommented ZabbixAPI::debugEnabled(TRUE); everything all right -
                            Code:
                            Server running Zabbix API Version: 1.3
                            <br>User IDs found: 1,2,3,4
                            <br>Retrieved maximum of five hosts: Array
                            (
                                [0] => Array
                                    (
                                        [maintenances] => Array
                                            (
                                                [0] => Array
                                                    (
                                                        [maintenanceid] => 0
                                                    )
                            
                                            )
                            
                                        [hostid] => 10017
                                        [proxy_hostid] => 0
                                        [host] => Zabbix Server
                                        [dns] => 
                                        [useip] => 1
                                        [ip] => 127.0.0.1
                                        [port] => 10050
                                        [status] => 1
                                        [disable_until] => 0
                                        [error] => 
                                        [available] => 1
                                        [errors_from] => 0
                                        [lastaccess] => 0
                                        [inbytes] => 0
                                        [outbytes] => 0
                                        [useipmi] => 0
                                        [ipmi_port] => 623
                                        [ipmi_authtype] => 0
                                        [ipmi_privilege] => 2
                                        [ipmi_username] => 
                                        [ipmi_password] => 
                                        [ipmi_disable_until] => 0
                                        [ipmi_available] => 0
                                        [snmp_disable_until] => 0
                                        [snmp_available] => 0
                                        [maintenanceid] => 0
                                        [maintenance_status] => 0
                                        [maintenance_type] => 0
                                        [maintenance_from] => 0
                                        [ipmi_ip] => 
                                        [ipmi_errors_from] => 0
                                        [snmp_errors_from] => 0
                                        [ipmi_error] => 
                                        [snmp_error] => 
                                    )
                            ...
                            
                            <br>Updated userid 1 with refresh value of 1000!
                            But without uncommented line I have
                            Code:
                            PHP Fatal error:  Call to undefined method stdClass::__login() in /usr/share/zabbix/ZabbixAPI.class.php on line 99
                            Thanks for help, but WHY commented line about debugging may prevent the login? What is it?

                            Comment

                            • fjrial
                              Senior Member
                              • Feb 2010
                              • 140

                              #29
                              Originally posted by olex
                              Thanks for help, but WHY commented line about debugging may prevent the login? What is it?
                              That a question that I can not answer.. I don't know and I didn't take a look inside the code (didn't have the time, and as you may know, bosses only want results, they didn't care about libraries problems. For me this works, so I could continue developing third party integrations into zabbix)

                              Maybe we should ask Andrew Farley about this.. Tomorrow I'll ask him about this.. If I get an answer, I'll post it here.

                              Cheer.

                              Comment

                              • olex
                                Junior Member
                                • Mar 2011
                                • 5

                                #30
                                Ok ) Thanks a lot anyway - therefore I broke my brains about this for two days and nobody can help

                                Comment

                                Working...