mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-27 16:08:55 +02:00
Moved database into options
This commit is contained in:
@@ -6,8 +6,10 @@
|
||||
Send metrics to InfluxDB.
|
||||
|
||||
```php
|
||||
$options = new \InfluxDB\Options();
|
||||
|
||||
$client = new \InfluxDB\Client();
|
||||
$client->setAdapter(new \InfluxDB\Adapter\UdpAdapter());
|
||||
$client->setAdapter(new \InfluxDB\Adapter\UdpAdapter($options));
|
||||
|
||||
$client->mark("search", [
|
||||
"query" => "php"
|
||||
@@ -58,10 +60,10 @@ $options->setHost("analytics.mine.domain.tld");
|
||||
$options->setPort(8086);
|
||||
$options->setUsername("root");
|
||||
$options->setPassword("root");
|
||||
$options->setDatabase("mine");
|
||||
|
||||
$guzzleHttp = new GuzzleHttpClient();
|
||||
$adapter = new InfluxHttpAdapter($guzzleHttp, $options);
|
||||
$adapter->setDatabase("mine");
|
||||
|
||||
$influx = new Client();
|
||||
$influx->setAdapter($adapter);
|
||||
|
||||
@@ -31,5 +31,10 @@
|
||||
"psr-0": {
|
||||
"InfluxDB": ["./src/", "./tests"]
|
||||
}
|
||||
},
|
||||
"suggests": {
|
||||
"fabpot/pimple": "Allows to prepare the client dependencies in order to require an initialized instance",
|
||||
"zendframework/zend-servicemanager": "Use a service locator in order to prepare a valid instance",
|
||||
"symfony/dependency-injection": "Prepare a valid instance via the symfony DiC"
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+1
-1
@@ -4,7 +4,7 @@
|
||||
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "6ba22c8acf314366cc2d58a2cfaccbd3",
|
||||
"hash": "1b622dda38682502a547657384b6fe7f",
|
||||
"packages": [
|
||||
{
|
||||
"name": "guzzlehttp/guzzle",
|
||||
|
||||
@@ -11,7 +11,7 @@ class GuzzleAdapterSpec extends ObjectBehavior
|
||||
{
|
||||
function let(Client $client, Options $options)
|
||||
{
|
||||
$options->getTcpEndpointFor(Argument::Any())->willReturn("localhost");
|
||||
$options->getTcpEndpoint()->willReturn("localhost");
|
||||
$this->beConstructedWith($client, $options);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@ class OptionsSpec extends ObjectBehavior
|
||||
|
||||
function it_should_create_a_valid_tcp_endpoint()
|
||||
{
|
||||
$this->getTcpEndpointFor("mine")
|
||||
$this->setDatabase("mine");
|
||||
$this->getTcpEndpoint()
|
||||
->shouldReturn("http://localhost:8086/db/mine/series?u=root&p=root");
|
||||
}
|
||||
|
||||
@@ -24,14 +25,16 @@ class OptionsSpec extends ObjectBehavior
|
||||
$this->setPort(19385);
|
||||
$this->setUsername("walter");
|
||||
$this->setPassword("walter");
|
||||
$this->getTcpEndpointFor("me")
|
||||
$this->setDatabase("me");
|
||||
$this->getTcpEndpoint()
|
||||
->shouldReturn("http://influx.1.prod.tld:19385/db/me/series?u=walter&p=walter");
|
||||
}
|
||||
|
||||
function it_should_allows_https_for_tcp_endpoint()
|
||||
{
|
||||
$this->setProtocol("https");
|
||||
$this->getTcpEndpointFor("me")
|
||||
$this->setDatabase("me");
|
||||
$this->getTcpEndpoint()
|
||||
->shouldReturn("https://localhost:8086/db/me/series?u=root&p=root");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,23 +17,12 @@ class GuzzleAdapter implements AdapterInterface
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public function getDatabase()
|
||||
{
|
||||
return $this->database;
|
||||
}
|
||||
|
||||
public function setDatabase($database)
|
||||
{
|
||||
$this->database = $database;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function send($message)
|
||||
{
|
||||
$httpMessage = [
|
||||
"body" => json_encode($message)
|
||||
];
|
||||
$endpoint = $this->options->getTcpEndpointFor($this->getDatabase());
|
||||
$endpoint = $this->options->getTcpEndpoint();
|
||||
|
||||
$this->httpClient->post($endpoint, $httpMessage);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ class Options
|
||||
private $password;
|
||||
private $protocol;
|
||||
|
||||
private $database;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->host = "localhost";
|
||||
@@ -74,14 +76,25 @@ class Options
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTcpEndpointFor($database)
|
||||
public function getDatabase()
|
||||
{
|
||||
return $this->database;
|
||||
}
|
||||
|
||||
public function setDatabase($database)
|
||||
{
|
||||
$this->database = $database;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTcpEndpoint()
|
||||
{
|
||||
return sprintf(
|
||||
"%s://%s:%d/db/%s/series?u=%s&p=%s",
|
||||
$this->getProtocol(),
|
||||
$this->getHost(),
|
||||
$this->getPort(),
|
||||
$database,
|
||||
$this->getDatabase(),
|
||||
$this->getUsername(),
|
||||
$this->getPassword()
|
||||
);
|
||||
|
||||
@@ -45,10 +45,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
$options->setPort($tcpOptions["port"]);
|
||||
$options->setUsername($tcpOptions["username"]);
|
||||
$options->setPassword($tcpOptions["password"]);
|
||||
$options->setDatabase($tcpOptions["database"]);
|
||||
|
||||
$guzzleHttp = new GuzzleHttpClient();
|
||||
$adapter = new InfluxHttpAdapter($guzzleHttp, $options);
|
||||
$adapter->setDatabase($tcpOptions["database"]);
|
||||
|
||||
$influx = new Client();
|
||||
$influx->setAdapter($adapter);
|
||||
|
||||
Reference in New Issue
Block a user