PHP code example of zarplata / zabbix-sender

1. Go to this page and download the library: Download zarplata/zabbix-sender 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/ */

    

zarplata / zabbix-sender example snippets




use \Zarplata\Zabbix\ZabbixSender;
use \Zarplata\Zabbix\Request\Packet as ZabbixPacket;
use \Zarplata\Zabbix\Request\Metric as ZabbixMetric;

// At first you must initialize ZabbixSender object
// with address of Zabbix Server. If your Zabbix Server
// don't listen default port (10051) you can define it in constructor
// $sender = new ZabbixSender(
//     $serverAddress='ZABBIX_SERVER_HOSTNAME',
//     $serverPort=12345
// );
$sender = new ZabbixSender('ZABBIX_SERVER_HOSTNAME');

// After you define the $sender you must create ZabbixPacket
// it's just accumulator of your metrics which you will add.
$packet = new ZabbixPacket();

// Define your metrinc
$packet->addMetric(new ZabbixMetric('my.super.text.item.key', 'OK'));
$packet->addMetric(new ZabbixMetric('my.super.int.item.key', 1));

// And finally send to Zabbix Server
$sender->send($packet);



new ZabbixMetric('my.super.text.item.key', 'OK');



(new ZabbixMetric('my.super.text.item.key', 'OK'))
    ->withHostname('my_non_local_hostname')
    ->withTimestamp(662637600); //Timestamp in past