mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-27 16:08:55 +02:00
Silently handle socket errors in the UdpAdapter (closes #27), add testcase
This commit is contained in:
@@ -15,9 +15,18 @@ final class UdpAdapter extends AdapterAbstract
|
||||
|
||||
public function write($message)
|
||||
{
|
||||
// Create a handler in order to handle the 'Host is down' message
|
||||
set_error_handler(function() {
|
||||
// Suppress the error, this is the UDP adapter and if we can't send
|
||||
// it then we shouldn't inturrupt their application.
|
||||
});
|
||||
|
||||
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
|
||||
socket_sendto($socket, $message, strlen($message), 0, $this->getOptions()->getHost(), $this->getOptions()->getPort());
|
||||
socket_close($socket);
|
||||
|
||||
// Remove our error handler.
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
private function serialize(array $message)
|
||||
|
||||
@@ -359,6 +359,30 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(712423, $body["results"][0]["series"][0]["values"][0][2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that we handle socket problems correctly in the UDP
|
||||
* adapter, and that they don't inturrupt the user's application.
|
||||
*
|
||||
* @group udp
|
||||
*/
|
||||
public function testReplicateIssue27()
|
||||
{
|
||||
$options = new \InfluxDB\Options();
|
||||
|
||||
// Configure options
|
||||
$options->setHost('172.16.1.182');
|
||||
$options->setPort(4444);
|
||||
$options->setDatabase('...');
|
||||
$options->setUsername('root');
|
||||
$options->setPassword('root');
|
||||
|
||||
$httpAdapter = new \InfluxDB\Adapter\UdpAdapter($options);
|
||||
|
||||
$client = new \InfluxDB\Client();
|
||||
$client->setAdapter($httpAdapter);
|
||||
$client->mark("udp.test", ["mark" => "element"]);
|
||||
}
|
||||
|
||||
public function testListActiveDatabses()
|
||||
{
|
||||
$databases = $this->object->getDatabases();
|
||||
|
||||
Reference in New Issue
Block a user