Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

general question #9

Open
michabbb opened this issue Jul 14, 2022 · 3 comments
Open

general question #9

michabbb opened this issue Jul 14, 2022 · 3 comments

Comments

@michabbb
Copy link

hi, is it possible to update checks in zabbix with this client? I would like to replace Nagios passive checks, where the client pushes the new state to the server.

thanks!

@intellitrend-team
Copy link
Collaborator

It's generally not possible to write any metrics via the Zabbix API, which is what this library is using. For that purpose, a PHP library that implements the Zabbix trapper/sender protocol should be used instead, like https://github.com/zarplata/zabbix-sender-php, for example. Alternatively, PHP can also send data by calling the zabbix_sender process.

@azzus78
Copy link

azzus78 commented Sep 19, 2023

hello, before testing implemented your code I testing with POSTMAN my Zabbix API was result success with ouput json

Then i tried your code same as like simple.php file to access my Zabbix APPI ,here my code :

`require_once("ZabbixApi.php");

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

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

$zabUrl ='https://my.zabbixurl.com/api_jsonrpc.php';
$zabUser = 'myuser';
$zabPassword = 'mypassword';

$zbx = new ZabbixApi();
try {

$zbx->login($zabUrl, $zabUser, $zabPassword);
//this is similar to: $result = $zbx->call('apiinfo.version');
$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;
}`

Result :

Zabbix API Example Connect to API, check certificate/hostname and get number of hosts ===================================================== ==== Zabbix API Exception === Errorcode: 404 ErrorMessage: Request failed with HTTP-Code:404, sslVerifyResult:0.

Whats wrong with my code ?

But I expriment with code using curl :

`$url = "https://my.zabbixurl.com/api_jsonrpc.php";

$headers = array(
"Content-Type: application/json-rpc",
);

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$data = <<<DATA
{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "myuser",
"password": "mypassword"
},
"id": 1
}

DATA;

curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

$resp = curl_exec($curl);
curl_close($curl);

echo $resp;`

Thats code successfull output json same as like i tried with POSTMAN

What is different between your class code because I want use your class ? Please give me some suggestion to handle the issues ?

@azzus78
Copy link

azzus78 commented Sep 19, 2023

hello, before testing implemented your code I testing with POSTMAN my Zabbix API was result success with ouput json

Then i tried your code same as like simple.php file to access my Zabbix APPI ,here my code :

`require_once("ZabbixApi.php");

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

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

$zabUrl ='https://my.zabbixurl.com/api_jsonrpc.php'; $zabUser = 'myuser'; $zabPassword = 'mypassword';

$zbx = new ZabbixApi(); try {

$zbx->login($zabUrl, $zabUser, $zabPassword);
//this is similar to: $result = $zbx->call('apiinfo.version');
$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; }`

Result :

Zabbix API Example Connect to API, check certificate/hostname and get number of hosts ===================================================== ==== Zabbix API Exception === Errorcode: 404 ErrorMessage: Request failed with HTTP-Code:404, sslVerifyResult:0.

Whats wrong with my code ?

But I expriment with code using curl :

`$url = "https://my.zabbixurl.com/api_jsonrpc.php";

$headers = array( "Content-Type: application/json-rpc", );

$curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$data = <<<DATA { "jsonrpc": "2.0", "method": "user.login", "params": { "user": "myuser", "password": "mypassword" }, "id": 1 }

DATA;

curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

$resp = curl_exec($curl); curl_close($curl);

echo $resp;`

Thats code successfull output json same as like i tried with POSTMAN

What is different between your class code because I want use your class ? Please give me some suggestion to handle the issues ?

Yey..solved. I wrong write url endpoint. Remove "api_jsonrpc.php" from url so the actual is : https://my.zabbixurl.com

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants