mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Dropped time precision feature
This commit is contained in:
@@ -11,5 +11,5 @@ interface AdapterInterface
|
||||
* @param mixed $message
|
||||
* @param string|boolean $timePrecision
|
||||
*/
|
||||
public function send($message, $timePrecision = false);
|
||||
public function send($message);
|
||||
}
|
||||
|
||||
@@ -78,47 +78,6 @@ class GuzzleAdapter implements AdapterInterface, QueryableInterface
|
||||
return $this->get($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getDatabases()
|
||||
{
|
||||
$options = [
|
||||
"auth" => [$this->options->getUsername(), $this->options->getPassword()],
|
||||
"query" => [
|
||||
"q" => "show databases",
|
||||
],
|
||||
];
|
||||
|
||||
return $this->get($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function createDatabase($name)
|
||||
{
|
||||
$httpMessage = [
|
||||
"auth" => [$this->options->getUsername(), $this->options->getPassword()],
|
||||
"query" => ["q" => "CREATE DATABASE \"{$name}\""],
|
||||
];
|
||||
|
||||
return $this->get($httpMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function deleteDatabase($name)
|
||||
{
|
||||
$httpMessage = [
|
||||
"auth" => [$this->options->getUsername(), $this->options->getPassword()],
|
||||
"query" => ["q" => "drop database \"{$name}\""],
|
||||
];
|
||||
|
||||
return $this->get($httpMessage);
|
||||
}
|
||||
|
||||
private function get(array $httpMessage)
|
||||
{
|
||||
$endpoint = $this->options->getHttpQueryEndpoint();
|
||||
|
||||
@@ -1,34 +1,7 @@
|
||||
<?php
|
||||
namespace InfluxDB\Adapter;
|
||||
|
||||
/**
|
||||
* The Adapter implement this interface if it supports database query
|
||||
*/
|
||||
interface QueryableInterface
|
||||
{
|
||||
/**
|
||||
* Make query into database
|
||||
* @param string $query
|
||||
* @param string|bool $timePrecision
|
||||
*/
|
||||
public function query($query, $timePrecision = false);
|
||||
|
||||
/**
|
||||
* Return database
|
||||
*/
|
||||
public function getDatabases();
|
||||
|
||||
/**
|
||||
* Create database
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
public function createDatabase($name);
|
||||
|
||||
/**
|
||||
* Delete database by database
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
public function deleteDatabase($name);
|
||||
public function query($query);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class UdpAdapter implements AdapterInterface
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function send($message, $timePrecision = false)
|
||||
public function send($message)
|
||||
{
|
||||
$message = json_encode($message);
|
||||
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
|
||||
|
||||
+7
-11
@@ -23,31 +23,27 @@ class Client
|
||||
return $this->adapter;
|
||||
}
|
||||
|
||||
public function mark($name, array $values = [], $timePrecision = false)
|
||||
public function mark($name, array $values = [])
|
||||
{
|
||||
$data = $name;
|
||||
if (!is_array($name)) {
|
||||
$data =[];
|
||||
|
||||
$timePrecision = $this->clearTimePrecision($timePrecision);
|
||||
|
||||
$data["database"] = $this->getAdapter()->getOptions()->getDatabase();
|
||||
$data['points'][0]['name'] = $name;
|
||||
$data['points'][0]['fields'] = $values;
|
||||
}
|
||||
|
||||
return $this->getAdapter()->send($data, $timePrecision);
|
||||
return $this->getAdapter()->send($data);
|
||||
}
|
||||
|
||||
public function query($query, $timePrecision = false)
|
||||
public function query($query)
|
||||
{
|
||||
if (!($this->getAdapter() instanceOf QueryableInterface)) {
|
||||
throw new \BadMethodCallException("You can query the database only if the adapter supports it!");
|
||||
}
|
||||
|
||||
$timePrecision = $this->clearTimePrecision($timePrecision);
|
||||
|
||||
$return = $this->getAdapter()->query($query, $timePrecision);
|
||||
$return = $this->getAdapter()->query($query);
|
||||
|
||||
return $return;
|
||||
}
|
||||
@@ -57,7 +53,7 @@ class Client
|
||||
if (!($this->getAdapter() instanceOf QueryableInterface)) {
|
||||
throw new \BadMethodCallException("You can query the database only if the adapter supports it!");
|
||||
}
|
||||
return $this->getAdapter()->getDatabases();
|
||||
return $this->getAdapter()->query("show databases");
|
||||
}
|
||||
|
||||
public function createDatabase($name)
|
||||
@@ -65,7 +61,7 @@ class Client
|
||||
if (!($this->getAdapter() instanceOf QueryableInterface)) {
|
||||
throw new \BadMethodCallException("You can query the database only if the adapter supports it!");
|
||||
}
|
||||
return $this->getAdapter()->createDatabase($name);
|
||||
return $this->getAdapter()->query("create database \"{$name}\"");
|
||||
}
|
||||
|
||||
public function deleteDatabase($name)
|
||||
@@ -73,7 +69,7 @@ class Client
|
||||
if (!($this->getAdapter() instanceOf QueryableInterface)) {
|
||||
throw new \BadMethodCallException("You can query the database only if the adapter supports it!");
|
||||
}
|
||||
return $this->getAdapter()->deleteDatabase($name);
|
||||
return $this->getAdapter()->query("drop database \"{$name}\"");
|
||||
}
|
||||
|
||||
private function clearTimePrecision($timePrecision)
|
||||
|
||||
@@ -97,41 +97,6 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals("element", $body["results"][0]["series"][0]["values"][0][1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group tcp
|
||||
*/
|
||||
public function testGuzzleHttpQueryApiWithTimePrecision()
|
||||
{
|
||||
$this->markTestSkipped("Skip time precision");
|
||||
$this->object->mark("tcp.test", ["mark" => "element"]);
|
||||
|
||||
sleep(1);
|
||||
|
||||
$body = $this->object->query("select mark from \"tcp.test\"", "s");
|
||||
|
||||
$this->assertCount(1, $body["results"][0]["series"][0]["values"]);
|
||||
$this->assertEquals("mark", $body["results"][0]["series"][0]["columns"][1]);
|
||||
$this->assertEquals("element", $body["results"][0]["series"][0]["values"][0][1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group tcp
|
||||
*/
|
||||
public function testGuzzleHttpWriteApiWithTimePrecision()
|
||||
{
|
||||
$this->markTestSkipped("Skip time precision");
|
||||
$this->object->mark("tcp.test", ["time" => 1410591552, "mark" => "element"], "s");
|
||||
|
||||
sleep(1);
|
||||
|
||||
$body = $this->object->query("select mark from \"tcp.test\"", "ms");
|
||||
|
||||
$this->assertCount(1, $body[0]["points"]);
|
||||
$this->assertEquals("tcp.test", $body[0]["name"]);
|
||||
|
||||
$this->assertEquals("1410591552000", $body[0]["points"][0][0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group udp
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user