mirror of
https://github.com/stylersnico/librenms.git
synced 2026-08-01 16:26:55 +02:00
Changing Client Exception, testing Point
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Leaseweb\InfluxDB\Client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Exception
|
||||||
|
*
|
||||||
|
* @package Leaseweb\InfluxDB\Client
|
||||||
|
*/
|
||||||
|
class Exception extends \Leaseweb\InfluxDB\Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -104,7 +104,7 @@ class Database
|
|||||||
public function writePoints(array $points)
|
public function writePoints(array $points)
|
||||||
{
|
{
|
||||||
foreach ($points as $point) {
|
foreach ($points as $point) {
|
||||||
$point->a();
|
//$point->a();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Leaseweb\InfluxDB;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class InfluxDBClientError
|
|
||||||
* @package Leaseweb\InfluxDB
|
|
||||||
*/
|
|
||||||
class InfluxDBClientError extends \RuntimeException
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -41,15 +41,24 @@ class Point
|
|||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
return "";
|
return sprintf(
|
||||||
/*return sprintf(
|
|
||||||
'%s,%s %s %s',
|
'%s,%s %s %s',
|
||||||
$this->measurement,
|
$this->measurement,
|
||||||
implode()
|
$this->arrayToString($this->tags),
|
||||||
);*/
|
$this->arrayToString($this->fields),
|
||||||
|
$this->timestamp
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function a(){
|
private function arrayToString(array $arr)
|
||||||
|
{
|
||||||
|
$strParts = array();
|
||||||
|
|
||||||
|
foreach ($arr as $key=> $value) {
|
||||||
|
$strParts[]="{$key}={$value}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(",", $strParts);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
namespace Leaseweb\InfluxDB;
|
namespace Leaseweb\InfluxDB;
|
||||||
|
|
||||||
|
use Leaseweb\InfluxDB\Client\Exception as ClientException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ResultSet
|
* Class ResultSet
|
||||||
*
|
*
|
||||||
@@ -26,7 +28,7 @@ class ResultSet
|
|||||||
* @param $raw
|
* @param $raw
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
* @throws InfluxDBClientError
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function __construct($raw)
|
public function __construct($raw)
|
||||||
{
|
{
|
||||||
@@ -40,11 +42,11 @@ class ResultSet
|
|||||||
|
|
||||||
// There was an error in the query thrown by influxdb
|
// There was an error in the query thrown by influxdb
|
||||||
if (isset($this->parsedResults['error'])) {
|
if (isset($this->parsedResults['error'])) {
|
||||||
throw new InfluxDBClientError($this->parsedResults['error']);
|
throw new ClientException($this->parsedResults['error']);
|
||||||
|
|
||||||
// Check if there are errors in the first serie
|
// Check if there are errors in the first serie
|
||||||
} elseif (isset($this->parsedResults['results'][0]['error'])) {
|
} elseif (isset($this->parsedResults['results'][0]['error'])) {
|
||||||
throw new InfluxDBClientError($this->parsedResults['results'][0]['error']);
|
throw new ClientException($this->parsedResults['results'][0]['error']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +79,7 @@ class ResultSet
|
|||||||
* results is an array of objects, one for each query,
|
* results is an array of objects, one for each query,
|
||||||
* each containing the keys for a series
|
* each containing the keys for a series
|
||||||
*
|
*
|
||||||
* @throws InfluxDBClientError
|
* @throws Exception
|
||||||
*
|
*
|
||||||
* @return array $series
|
* @return array $series
|
||||||
*/
|
*/
|
||||||
@@ -86,7 +88,7 @@ class ResultSet
|
|||||||
$pickSeries = function ($object) {
|
$pickSeries = function ($object) {
|
||||||
|
|
||||||
if (isset($object['error'])) {
|
if (isset($object['error'])) {
|
||||||
throw new InfluxDBClientError($object['error']);
|
throw new ClientException($object['error']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $object['series'];
|
return $object['series'];
|
||||||
|
|||||||
@@ -13,10 +13,9 @@ use Leaseweb\InfluxDB\Point;
|
|||||||
|
|
||||||
class PointTest extends \PHPUnit_Framework_TestCase
|
class PointTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
public function testPointStringRepresentation()
|
public function testPointStringRepresentation()
|
||||||
{
|
{
|
||||||
$expected = 'cpu_load_short,host=server01,region=us-west value=0.64 mytime';
|
$expected = 'cpu_load_short,host=server01,region=us-west value=0.64 myTime';
|
||||||
|
|
||||||
$point = new Point(
|
$point = new Point(
|
||||||
'cpu_load_short',
|
'cpu_load_short',
|
||||||
@@ -25,8 +24,6 @@ class PointTest extends \PHPUnit_Framework_TestCase
|
|||||||
'myTime'
|
'myTime'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
$this->assertEquals($expected, (string) $point);
|
$this->assertEquals($expected, (string) $point);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ class ResultSetTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Throws Exception if something went wrong with influxDB
|
* Throws Exception if something went wrong with influxDB
|
||||||
* @expectedException \Leaseweb\InfluxDB\InfluxDBClientError
|
* @expectedException \Leaseweb\InfluxDB\Exception
|
||||||
*/
|
*/
|
||||||
public function testThrowsInfluxDBException()
|
public function testThrowsInfluxDBException()
|
||||||
{
|
{
|
||||||
@@ -42,7 +42,7 @@ EOD;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Throws Exception if something went wrong with influxDB after processing the query
|
* Throws Exception if something went wrong with influxDB after processing the query
|
||||||
* @expectedException \Leaseweb\InfluxDB\InfluxDBClientError
|
* @expectedException \Leaseweb\InfluxDB\Exception
|
||||||
*/
|
*/
|
||||||
public function testThrowsInfluxDBExceptionIfAnyErrorInSeries()
|
public function testThrowsInfluxDBExceptionIfAnyErrorInSeries()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user