PHP code example of kamermans / zabbix-client

1. Go to this page and download the library: Download kamermans/zabbix-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kamermans / zabbix-client example snippets


$client = new ZabbixClient(
    "http://myzabbixserver/zabbix/api_jsonrpc.php",
    "myusername",
    "mypassword"
);

$response = $client->request('apiinfo.version');
echo "Server is running Zabbix $response\n";

$hosts = $client->request('host.get', [
    'output' => [
        'host_id',
        'host',
    ],
]);

foreach ($hosts as $host) {
    echo "{$host['hostid']}: {$host['host']}\n";
}

$response = $client->request('apiinfo.version');
$response->dd(); // '2.2.8'

$time = $client->ping();
echo "Pinged Zabbix Server in {$time}ms\n";



amermans\ZabbixClient\ZabbixClient;

$client = new ZabbixClient(
    "http://myzabbixserver/zabbix/api_jsonrpc.php",
    "myusername",
    "mypassword"
);

$host = 'Zabbix server';
$key = 'system';

echo "Showing $key items for $host\n\n";

$response = $client->request('item.get', [
    'host' => $host,
    'search' => [
        'key_' => $key,
    ],
    'sortfield' => 'name',
]);

foreach ($response as $item) {
    echo "{$item['name']}: {$item['lastvalue']}\n";
}