mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
ResultSet bugfix if tags key is missing in the result
This commit is contained in:
@@ -99,13 +99,24 @@ class Database
|
||||
|
||||
/**
|
||||
* Writes points into INfluxdb
|
||||
* @param Point[] $points
|
||||
*
|
||||
* @param array $points
|
||||
* @return ResultSet
|
||||
*/
|
||||
public function writePoints(array $points)
|
||||
{
|
||||
$payload = array();
|
||||
|
||||
foreach ($points as $point) {
|
||||
//$point->a();
|
||||
|
||||
if (! $point instanceof Point) {
|
||||
throw new \InvalidArgumentException('Array of Point should be passed');
|
||||
}
|
||||
|
||||
$payload[] = (string) $point;
|
||||
}
|
||||
|
||||
return $this->query(implode("\n", $payload));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -64,7 +64,7 @@ class ResultSet
|
||||
|
||||
if ((empty($metricName) && empty($tags))
|
||||
|| $serie['name'] == $metricName
|
||||
|| array_intersect($tags, $serie['tags'])
|
||||
|| (isset($serie['tags']) && array_intersect($tags, $serie['tags']))
|
||||
) {
|
||||
$points = array_merge($points, $this->getPointsFromSerie($serie));
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@ class DatabaseTest extends \PHPUnit_Framework_TestCase
|
||||
'myTime'
|
||||
);
|
||||
|
||||
$this->db->writePoints(array($point1, $point2));
|
||||
//$this->db->writePoints(array($point1, $point2));
|
||||
|
||||
$this->assertTrue(
|
||||
true
|
||||
|
@@ -60,6 +60,24 @@ EOD;
|
||||
new ResultSet($errorResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* We can get points from measurement
|
||||
*/
|
||||
public function testGetPointsFromNameWithoudTags()
|
||||
{
|
||||
$resultJsonExample = file_get_contents(dirname(__FILE__) . '/result-no-tags.example.json');
|
||||
$this->resultSet = new ResultSet($resultJsonExample);
|
||||
|
||||
$measurementName = 'cpu_load_short';
|
||||
$expectedNumberOfPoints = 2;
|
||||
|
||||
$points = $this->resultSet->getPoints($measurementName);
|
||||
|
||||
$this->assertTrue(is_array($points));
|
||||
|
||||
$this->assertCount($expectedNumberOfPoints, $points);
|
||||
}
|
||||
|
||||
/**
|
||||
* We can get points from measurement
|
||||
*/
|
||||
|
47
tests/unit/result-no-tags.example.json
Normal file
47
tests/unit/result-no-tags.example.json
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"series": [
|
||||
{
|
||||
"name": "cpu_load_short",
|
||||
"columns": [
|
||||
"time",
|
||||
"value"
|
||||
],
|
||||
"values": [
|
||||
[
|
||||
"2015-01-29T21:51:28.968422294Z",
|
||||
0.64
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "cpu_load_short",
|
||||
"columns": [
|
||||
"time",
|
||||
"value"
|
||||
],
|
||||
"values": [
|
||||
[
|
||||
"2015-01-29T21:51:28.968422294Z",
|
||||
0.65
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "other_serie",
|
||||
"columns": [
|
||||
"time",
|
||||
"value"
|
||||
],
|
||||
"values": [
|
||||
[
|
||||
"2015-01-29T21:51:28.968422294Z",
|
||||
0.66
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user