mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Added from dsn method
This commit is contained in:
@@ -7,6 +7,8 @@ namespace Leaseweb\InfluxDB;
|
|||||||
|
|
||||||
|
|
||||||
use GuzzleHttp\Client as httpClient;
|
use GuzzleHttp\Client as httpClient;
|
||||||
|
use Leaseweb\InfluxDB\Client\Exception as ClientException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Client
|
* Class Client
|
||||||
*
|
*
|
||||||
@@ -84,7 +86,6 @@ class Client
|
|||||||
* @param int $timeout
|
* @param int $timeout
|
||||||
*
|
*
|
||||||
* @todo add UDP support
|
* @todo add UDP support
|
||||||
* @todo add SSL support
|
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$host,
|
$host,
|
||||||
@@ -94,8 +95,6 @@ class Client
|
|||||||
$ssl = false,
|
$ssl = false,
|
||||||
$verifySSL = true,
|
$verifySSL = true,
|
||||||
$timeout = 0
|
$timeout = 0
|
||||||
// $useUdp = false,
|
|
||||||
// $udpPort = 4444
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -206,31 +205,71 @@ class Client
|
|||||||
* List all the users
|
* List all the users
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* @todo implement once issue #3048 is fixed
|
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
// public function listUsers()
|
public function listUsers()
|
||||||
// {
|
{
|
||||||
// $result = $this->query(null, 'SHOW USERS')->getPoints();
|
$result = $this->query(null, 'SHOW USERS')->getPoints();
|
||||||
//
|
|
||||||
// return $this->pointsToArray($result);
|
return $this->pointsToArray($result);
|
||||||
// }
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the client from a dsn
|
* Build the client from a dsn
|
||||||
*
|
*
|
||||||
* Example: tcp+influxdb://username:pass@localhost:8086/databasename', timeout=5
|
* Example: https+influxdb://username:pass@localhost:8086/databasename', timeout=5
|
||||||
*
|
*
|
||||||
* @param string $dsn
|
* @param string $dsn
|
||||||
*
|
*
|
||||||
* @todo implement this functionality
|
* @param int $timeout
|
||||||
|
* @param bool $verifySSL
|
||||||
|
*
|
||||||
|
* @return Client|Database
|
||||||
|
*
|
||||||
|
* @throws ClientException
|
||||||
*/
|
*/
|
||||||
// public static function fromDSN($dsn)
|
public static function fromDSN($dsn, $timeout = 0, $verifySSL = false)
|
||||||
// {
|
{
|
||||||
// $args = array();
|
$connParams = parse_url($dsn);
|
||||||
// }
|
$schemeInfo = explode('+', $connParams['scheme']);
|
||||||
|
$dbName = null;
|
||||||
|
|
||||||
|
if (count($schemeInfo) == 1) {
|
||||||
|
$modifier = null;
|
||||||
|
$scheme = $schemeInfo[0];
|
||||||
|
} else {
|
||||||
|
$modifier = $schemeInfo[0];
|
||||||
|
$scheme = $schemeInfo[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($scheme != 'influxdb') {
|
||||||
|
throw new ClientException(sprintf('%s is not a valid scheme', $scheme));
|
||||||
|
}
|
||||||
|
|
||||||
|
$ssl = ($modifier && $modifier == 'https' ? true : false);
|
||||||
|
|
||||||
|
if ($connParams['path']) {
|
||||||
|
$dbName = substr($connParams['path'], 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$client = new self(
|
||||||
|
$connParams['host'],
|
||||||
|
$connParams['port'],
|
||||||
|
$connParams['user'],
|
||||||
|
$connParams['pass'],
|
||||||
|
$ssl,
|
||||||
|
$verifySSL,
|
||||||
|
$timeout
|
||||||
|
);
|
||||||
|
|
||||||
|
$return = $client;
|
||||||
|
if ($dbName) {
|
||||||
|
$return = $client->db($dbName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -164,6 +164,14 @@ class Database
|
|||||||
return new QueryBuilder($this);
|
return new QueryBuilder($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Client
|
||||||
|
*/
|
||||||
|
public function getClient()
|
||||||
|
{
|
||||||
|
return $this->client;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $method
|
* @param $method
|
||||||
* @param RetentionPolicy $retentionPolicy
|
* @param RetentionPolicy $retentionPolicy
|
||||||
|
|||||||
@@ -62,9 +62,10 @@ class ResultSet
|
|||||||
|
|
||||||
foreach ($this->getSeries() as $serie) {
|
foreach ($this->getSeries() as $serie) {
|
||||||
|
|
||||||
if ((empty($metricName) && empty($tags))
|
if ((empty($metricName) && empty($tags)
|
||||||
|| $serie['name'] == $metricName
|
|| $serie['name'] == $metricName
|
||||||
|| (isset($serie['tags']) && array_intersect($tags, $serie['tags']))
|
|| (isset($serie['tags']) && array_intersect($tags, $serie['tags'])))
|
||||||
|
&& isset($serie['values'])
|
||||||
) {
|
) {
|
||||||
$points = array_merge($points, $this->getPointsFromSerie($serie));
|
$points = array_merge($points, $this->getPointsFromSerie($serie));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user