Skip to content

Commit

Permalink
add disable and enable methods to toggle sender functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Platonov Andrey committed Jun 5, 2018
1 parent 75a107d commit a3de414
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/ZabbixSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class ZabbixSender
*/
private $packet;

/**
* @var bool Disable send operation
*/
private $disable = false;

/**
* Create singletone object
*
Expand Down Expand Up @@ -94,9 +99,33 @@ public function configure(array $options = array())
$this->serverPort = intval($options['server_port']);
}

if (isset($options['disable'])) {
$this->disable = boolval($options['disable']);
}

return $this;
}

/**
* Disable sender functionality. It may be necessary if you want
* switch off send metrics but you don't want remove the code
* from your project.
*
* @return void
*/
public function disable() {
$this->disable = true;
}

/**
* Enable sender functionality. This is reverse operation of `disable()`
*
* @return void
*/
public function enable() {
$this->disable = false;
}

/**
* Send packet of metrics to Zabbix server through network socket
*
Expand All @@ -110,6 +139,10 @@ public function configure(array $options = array())
*/
public function send(ZabbixPacket $packet)
{
if ($this->disable) {
return;
}

$payload = $this->makePayload($packet);
$payloadLength = strlen($payload);

Expand Down

0 comments on commit a3de414

Please sign in to comment.