Ad Widget

Collapse

Need help with API

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • horakmar
    replied
    Instances

    Hello.
    I ran into the same problem. After some hours of investigating I think that the problem is in PHP object/instances. It seems like the compiler doesn't know function self::$instance->__login(), because it arises at runtime by self::__init() (both in function login).

    Also if I run ZabbixAPI::debugEnabled(TRUE), that debug state doesn't stay set (following functions have self::$instance->debug undefined).

    I'm sorry, I don't understand OOP in PHP much, so I'm only guessing.

    Martin

    Leave a comment:


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

    Leave a comment:


  • fjrial
    replied
    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.

    Leave a comment:


  • olex
    replied
    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?

    Leave a comment:


  • fjrial
    replied
    So next one is uncomment the line ZabbixAPI::debugEnabled(TRUE);

    Leave a comment:


  • olex
    replied
    If it is in administrative tools - yes, enable

    Leave a comment:


  • olex
    replied
    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?

    Leave a comment:


  • fjrial
    replied
    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.

    Leave a comment:


  • olex
    replied
    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?

    Leave a comment:


  • fjrial
    replied
    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.

    Leave a comment:


  • fjrial
    replied
    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.

    Leave a comment:


  • fjrial
    replied
    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.

    Leave a comment:


  • Aly
    replied
    Enable debug mode for jsonRPCClient and copy here requests sent by client and server answers.

    Leave a comment:


  • fjrial
    replied
    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.

    Leave a comment:


  • gpmidi
    replied
    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

    Leave a comment:

Working...