zabbixapi-php icon indicating copy to clipboard operation
zabbixapi-php copied to clipboard

Zabbix Token with SSL options

Open roberthau1981 opened this issue 1 year ago • 1 comments

<?php
require_once("../src/ZabbixApi.php");

use IntelliTrend\Zabbix\ZabbixApi;
use IntelliTrend\Zabbix\ZabbixApiException;

print "Zabbix API Example\n";
print " Connect to API, ignore certificate/hostname and get number of hosts\n";
print "=====================================================\n";

$zabUrl ='https://blah/zabbix';
$zabToken = '123456';

$zbx = new ZabbixApi();
try {
        // disable verification of certificate and hostname
        $options = array('sslVerifyPeer' => false, 'sslVerifyHost' => false);
        $zbx->login($zabUrl, $zabToken,$options); <---- This looks like it only wants a password because of the $options.
        $result = $zbx->getApiVersion();
        print "Remote Zabbix API Version:$result\n";
        // Get number of host available to this useraccount
        $result = $zbx->call('host.get',array("countOutput" => true));
        print "Number of Hosts:$result\n";
} catch (ZabbixApiException $e) {
        print "==== Zabbix API Exception ===\n";
        print 'Errorcode: '.$e->getCode()."\n";
        print 'ErrorMessage: '.$e->getMessage()."\n";
        exit;
} catch (Exception $e) {
        print "==== Exception ===\n";
        print 'Errorcode: '.$e->getCode()."\n";
        print 'ErrorMessage: '.$e->getMessage()."\n";
        exit;
}



Zabbix API Example
 Connect to API, ignore certificate/hostname and get number of hosts
=====================================================
Remote Zabbix API Version:6.0.22
==== Zabbix API Exception ===
Errorcode: -32602
ErrorMessage: Invalid params. [Invalid parameter "/password": a character string is expected.]

roberthau1981 avatar Nov 01 '23 12:11 roberthau1981