mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
ResultSet - implementing getPoints
This commit is contained in:
@@ -5,7 +5,11 @@
|
|||||||
|
|
||||||
namespace Leaseweb\InfluxDB;
|
namespace Leaseweb\InfluxDB;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ResultSet
|
||||||
|
*
|
||||||
|
* @package Leaseweb\InfluxDB
|
||||||
|
*/
|
||||||
class ResultSet
|
class ResultSet
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -13,13 +17,32 @@ class ResultSet
|
|||||||
*/
|
*/
|
||||||
protected $raw = '';
|
protected $raw = '';
|
||||||
|
|
||||||
/**
|
protected $parsedResults = array();
|
||||||
* @param $raw
|
|
||||||
*
|
|
||||||
* @param bool $throwExceptions
|
|
||||||
*/
|
|
||||||
public function __construct($raw, $throwExceptions = true)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $raw
|
||||||
|
*
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function __construct($raw)
|
||||||
|
{
|
||||||
|
$this->raw = $raw;
|
||||||
|
|
||||||
|
$this->parsedResults = json_decode($raw, true);
|
||||||
|
|
||||||
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||||
|
throw new \InvalidArgumentException("Invalid JSON");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $metricName
|
||||||
|
* @param array $tags
|
||||||
|
*
|
||||||
|
* @return array $points
|
||||||
|
*/
|
||||||
|
public function getPoints($metricName = '', $tags = array())
|
||||||
|
{
|
||||||
|
return array();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,27 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Leaseweb\InfluxDB\Test;
|
namespace Leaseweb\InfluxDB\Test;
|
||||||
|
|
||||||
|
use Leaseweb\InfluxDB\ResultSet;
|
||||||
|
|
||||||
class ResultSetTest extends \PHPUnit_Framework_TestCase
|
class ResultSetTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testResultSetFromRaw()
|
/** @var ResultSet $resultSet*/
|
||||||
|
protected $resultSet;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
{
|
{
|
||||||
|
$resultJsonExample = file_get_contents(dirname(__FILE__) . '/result.example.json');
|
||||||
|
$this->resultSet = new ResultSet($resultJsonExample);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPointsFromMeasurementName()
|
||||||
|
{
|
||||||
|
$measurementName = 'cpu_load_short';
|
||||||
|
|
||||||
|
$points = $this->resultSet->getPoints($measurementName);
|
||||||
|
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
false
|
is_array($points)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
59
tests/unit/result.example.json
Normal file
59
tests/unit/result.example.json
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
{
|
||||||
|
"results": [
|
||||||
|
{
|
||||||
|
"series": [
|
||||||
|
{
|
||||||
|
"measurement": "cpu_load_short",
|
||||||
|
"tags": {
|
||||||
|
"host": "server01",
|
||||||
|
"region": "us-west"
|
||||||
|
},
|
||||||
|
"columns": [
|
||||||
|
"time",
|
||||||
|
"value"
|
||||||
|
],
|
||||||
|
"values": [
|
||||||
|
[
|
||||||
|
"2015-01-29T21:51:28.968422294Z",
|
||||||
|
0.64
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"measurement": "cpu_load_short",
|
||||||
|
"tags": {
|
||||||
|
"host": "server02",
|
||||||
|
"region": "us-west"
|
||||||
|
},
|
||||||
|
"columns": [
|
||||||
|
"time",
|
||||||
|
"value"
|
||||||
|
],
|
||||||
|
"values": [
|
||||||
|
[
|
||||||
|
"2015-01-29T21:51:28.968422294Z",
|
||||||
|
0.65
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"measurement": "other_serie",
|
||||||
|
"tags": {
|
||||||
|
"host": "server01",
|
||||||
|
"region": "us-west"
|
||||||
|
},
|
||||||
|
"columns": [
|
||||||
|
"time",
|
||||||
|
"value"
|
||||||
|
],
|
||||||
|
"values": [
|
||||||
|
[
|
||||||
|
"2015-01-29T21:51:28.968422294Z",
|
||||||
|
0.66
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user