Skip to content

Commit

Permalink
Add support for Zabbix 4 (#10)
Browse files Browse the repository at this point in the history
Added support for Zabbix 4
  • Loading branch information
Zulgabis authored and disc committed Oct 30, 2018
1 parent e8391e3 commit 14c16c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/Zabbix/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,12 @@ protected function getData()
*/
protected function buildRequestBody()
{
return json_encode([
$data = json_encode([
'request' => 'sender data',
'data' => $this->getData(),
]);

return "ZBXD\1" . pack('P', strlen($data)) . $data;
}

/**
Expand Down
22 changes: 13 additions & 9 deletions tests/SenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,22 @@ public function setUp()
public function testAddData()
{
/** @var Mock|Sender $sender */

$sender = \Mockery::mock(Sender::class . '[sendData]', ['localhost']);
$sender->shouldAllowMockingProtectedMethods();
$sender->shouldReceive('sendData')->once()->with(json_encode([
$data = json_encode([
'request' => 'sender data',
'data' => [],
]));
]);
$sender->shouldReceive('sendData')->once()->with("ZBXD\1" . pack('P', strlen($data)) . $data);

$sender->send();

$sender->addData('Host', 'test.key', 'some value');
$sender->addData('Host', 'another.key', 123);
$expectedTime = time();
$sender->addData('Host', 'one.more.key', 0.001, $expectedTime);

$sender->shouldReceive('sendData')->once()->with(json_encode([
$data = json_encode([
'request' => 'sender data',
'data' => [
[
Expand All @@ -76,7 +77,8 @@ public function testAddData()
'clock' => $expectedTime,
],
],
]));
]);
$sender->shouldReceive('sendData')->once()->with("ZBXD\1" . pack('P', strlen($data)) . $data);
$sender->send();
}

Expand All @@ -94,7 +96,7 @@ public function testClearData()
$sender->shouldAllowMockingProtectedMethods();

$sender->addData('Host', 'test.key', 'some value');
$sender->shouldReceive('sendData')->once()->with(json_encode([
$data = json_encode([
'request' => 'sender data',
'data' => [
[
Expand All @@ -103,12 +105,14 @@ public function testClearData()
'value' => 'some value',
]
],
]));
]);
$sender->shouldReceive('sendData')->once()->with("ZBXD\1" . pack('P', strlen($data)) . $data);
$sender->send();
$sender->shouldReceive('sendData')->once()->with(json_encode([
$data = json_encode([
'request' => 'sender data',
'data' => [],
]));
]);
$sender->shouldReceive('sendData')->once()->with("ZBXD\1" . pack('P', strlen($data)) . $data);
$sender->send();
}

Expand Down

0 comments on commit 14c16c4

Please sign in to comment.