项目作者: zarplata

项目描述 :
Zabbix sender protocol implementation
高级语言: PHP
项目地址: git://github.com/zarplata/zabbix-sender-php.git
创建时间: 2018-05-31T10:54:57Z
项目社区:https://github.com/zarplata/zabbix-sender-php

开源协议:MIT License

下载


Zabbix sender

Zabbix sender it’s a PHP implementation of Zabbix sender protocol.
With this library you can send any metric to Zabbix server.
Additional information about Zabbix sender protocol and request/response
you can be found in official documentation:

Installation

  1. composer require zarplata/zabbix-sender

Usage

  1. <?php
  2. use \Zarplata\Zabbix\ZabbixSender;
  3. use \Zarplata\Zabbix\Request\Packet as ZabbixPacket;
  4. use \Zarplata\Zabbix\Request\Metric as ZabbixMetric;
  5. // At first you must initialize ZabbixSender object
  6. // with address of Zabbix Server. If your Zabbix Server
  7. // don't listen default port (10051) you can define it in constructor
  8. // $sender = new ZabbixSender(
  9. // $serverAddress='ZABBIX_SERVER_HOSTNAME',
  10. // $serverPort=12345
  11. // );
  12. $sender = new ZabbixSender('ZABBIX_SERVER_HOSTNAME');
  13. // After you define the $sender you must create ZabbixPacket
  14. // it's just accumulator of your metrics which you will add.
  15. $packet = new ZabbixPacket();
  16. // Define your metrinc
  17. $packet->addMetric(new ZabbixMetric('my.super.text.item.key', 'OK'));
  18. $packet->addMetric(new ZabbixMetric('my.super.int.item.key', 1));
  19. // And finally send to Zabbix Server
  20. $sender->send($packet);

Advanced usage options

Sometimes it may be necessary to provide hostname and/or timestamp
of metric. By default construction:

  1. <?php
  2. new ZabbixMetric('my.super.text.item.key', 'OK');

take your current hostname and set object creation time as a metric timestamp.
If you want define another hostname or/and timestamp you must
write the following code:

  1. <?php
  2. (new ZabbixMetric('my.super.text.item.key', 'OK'))
  3. ->withHostname('my_non_local_hostname')
  4. ->withTimestamp(662637600); //Timestamp in past

License

MIT.