mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-27 08:02:51 +02:00
Fixes invalid saved timestamp for UDP/IP
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace InfluxDB\Adapter;
|
||||
|
||||
use DateTime;
|
||||
use InfluxDB\Options;
|
||||
|
||||
final class UdpAdapter extends AdapterAbstract
|
||||
@@ -28,10 +29,11 @@ final class UdpAdapter extends AdapterAbstract
|
||||
$tags = array_replace_recursive($tags, $message["tags"]);
|
||||
}
|
||||
|
||||
$unixepoch = (int)microtime(true);
|
||||
$now = new DateTime();
|
||||
$unixepoch = (int)($now->format("U") * 1e9);
|
||||
if (array_key_exists("time", $message)) {
|
||||
$dt = new \DateTime($message["time"]);
|
||||
$unixepoch = $dt->format("U");
|
||||
$dt = new DateTime($message["time"]);
|
||||
$unixepoch = (int)($dt->format("U") * 1e9);
|
||||
}
|
||||
|
||||
$lines = [];
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace InfluxDB;
|
||||
|
||||
use DateTime;
|
||||
use InfluxDB\Adapter\GuzzleAdapter as InfluxHttpAdapter;
|
||||
use InfluxDB\Options;
|
||||
use InfluxDB\Adapter\UdpAdapter;
|
||||
@@ -250,6 +251,68 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(712423, $body["results"][0]["series"][0]["values"][0][2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group udp
|
||||
* @group date
|
||||
*/
|
||||
public function testWriteDirectMessageWillPreserveActualTime()
|
||||
{
|
||||
$object = $this->createClientWithUdpAdapter();
|
||||
|
||||
$object->mark([
|
||||
"points" => [
|
||||
[
|
||||
"measurement" => "vm-serie",
|
||||
"fields" => [
|
||||
"cpu" => 18.12,
|
||||
"free" => 712423,
|
||||
],
|
||||
],
|
||||
]
|
||||
]);
|
||||
|
||||
sleep(2);
|
||||
|
||||
$this->options->setDatabase("udp.test");
|
||||
$body = $this->object->query("select * from \"vm-serie\"");
|
||||
|
||||
$this->assertCount(1, $body["results"][0]["series"][0]["values"]);
|
||||
$this->assertEquals("time", $body["results"][0]["series"][0]["columns"][0]);
|
||||
$saved = new DateTime($body["results"][0]["series"][0]["values"][0][0]);
|
||||
$this->assertEquals(date("Y-m-d"), $saved->format("Y-m-d"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group udp
|
||||
* @group date
|
||||
*/
|
||||
public function testWriteDirectMessageWillPreserveDatetime()
|
||||
{
|
||||
$object = $this->createClientWithUdpAdapter();
|
||||
|
||||
$object->mark([
|
||||
"time" => "2009-11-10T23:00:00Z",
|
||||
"points" => [
|
||||
[
|
||||
"measurement" => "vm-serie",
|
||||
"fields" => [
|
||||
"cpu" => 18.12,
|
||||
"free" => 712423,
|
||||
],
|
||||
],
|
||||
]
|
||||
]);
|
||||
|
||||
sleep(2);
|
||||
|
||||
$this->options->setDatabase("udp.test");
|
||||
$body = $this->object->query("select * from \"vm-serie\"");
|
||||
|
||||
$this->assertCount(1, $body["results"][0]["series"][0]["values"]);
|
||||
$this->assertEquals("time", $body["results"][0]["series"][0]["columns"][0]);
|
||||
$this->assertEquals("2009-11-10T23:00:00Z", $body["results"][0]["series"][0]["values"][0][0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group udp
|
||||
* @group tags
|
||||
|
||||
Reference in New Issue
Block a user