Commit bc37482f authored by Ad Schellevis's avatar Ad Schellevis

(systemhealth) fix for rrd files without topic in them, like ntpd

parent 852b7e71
...@@ -457,7 +457,7 @@ class SystemhealthController extends ApiControllerBase ...@@ -457,7 +457,7 @@ class SystemhealthController extends ApiControllerBase
/** /**
* retrieve descriptive details of rrd * retrieve descriptive details of rrd
* @param string $rrd rrd filename * @param string $rrd rrd category - item
* @return array result status and data * @return array result status and data
*/ */
private function getRRDdetails($rrd) private function getRRDdetails($rrd)
...@@ -466,15 +466,22 @@ class SystemhealthController extends ApiControllerBase ...@@ -466,15 +466,22 @@ class SystemhealthController extends ApiControllerBase
$result = array(); $result = array();
$backend = new Backend(); $backend = new Backend();
$response = $backend->configdpRun("systemhealth list"); $response = $backend->configdpRun("systemhealth list");
$output= json_decode($response, true); $healthList = json_decode($response, true);
if (is_array($output) && array_key_exists($rrd, $output)) { // search by topic and name, return array with filename
$result["result"] = "ok"; if (is_array($healthList)) {
$result["data"] = $output[$rrd]; foreach ($healthList as $filename => $healthItem) {
} else { if ($healthItem['itemName'] .'-' . $healthItem['topic'] == $rrd) {
// always return a valid (empty) data set $result["result"] = "ok";
$result["result"] = "not found"; $healthItem['filename'] = $filename;
$result["data"] = ["title"=>"","y-axis_label"=>"","field_units"=>[]]; $result["data"] = $healthItem;
return $result;
}
}
} }
// always return a valid (empty) data set
$result["result"] = "not found";
$result["data"] = ["title"=>"","y-axis_label"=>"","field_units"=>[], "itemName" => "", "filename" => ""];
return $result; return $result;
} }
...@@ -485,7 +492,7 @@ class SystemhealthController extends ApiControllerBase ...@@ -485,7 +492,7 @@ class SystemhealthController extends ApiControllerBase
*/ */
public function getRRDlistAction() public function getRRDlistAction()
{ {
# Suurce of data: filelisting of /var/db/rrd/*.rrd # Source of data: filelisting of /var/db/rrd/*.rrd
$result = array(); $result = array();
$backend = new Backend(); $backend = new Backend();
$response = $backend->configdpRun("systemhealth list"); $response = $backend->configdpRun("systemhealth list");
...@@ -536,9 +543,13 @@ class SystemhealthController extends ApiControllerBase ...@@ -536,9 +543,13 @@ class SystemhealthController extends ApiControllerBase
$rrd_details=$this->getRRDdetails($rrd)["data"]; $rrd_details=$this->getRRDdetails($rrd)["data"];
$backend = new Backend(); if ($rrd_details['filename'] != "") {
$response = $backend->configdpRun("systemhealth fetch ", array($rrd)); $backend = new Backend();
$xml = simplexml_load_string($response); $response = $backend->configdpRun("systemhealth fetch ", array($rrd_details['filename']));
$xml = simplexml_load_string($response);
} else {
$xml = false;
}
if ($xml !== false) { if ($xml !== false) {
// we only use the average databases in any RRD, remove the rest to avoid strange behaviour. // we only use the average databases in any RRD, remove the rest to avoid strange behaviour.
......
...@@ -188,11 +188,7 @@ ...@@ -188,11 +188,7 @@
} }
subitem=data["data"][category][0]; // first sub item subitem=data["data"][category][0]; // first sub item
if (category=="system") { rrd_name = subitem + '-' + category;
rrd_name = category + '-' + subitem;
} else {
rrd_name = subitem + '-' + category;
}
// create dropdown menu // create dropdown menu
tabs+='<a data-toggle="dropdown" href="#" class="dropdown-toggle pull-right visible-lg-inline-block visible-md-inline-block visible-xs-inline-block visible-sm-inline-block" role="button" style="border-left: 1px dashed lightgray;">'; tabs+='<a data-toggle="dropdown" href="#" class="dropdown-toggle pull-right visible-lg-inline-block visible-md-inline-block visible-xs-inline-block visible-sm-inline-block" role="button" style="border-left: 1px dashed lightgray;">';
...@@ -205,11 +201,7 @@ ...@@ -205,11 +201,7 @@
// add subtabs // add subtabs
for (var count=0; count<data["data"][category].length;++count ) { for (var count=0; count<data["data"][category].length;++count ) {
subitem=data["data"][category][count]; subitem=data["data"][category][count];
if (category=="system") { rrd_name = subitem + '-' + category;
rrd_name = category + '-' + subitem;
} else {
rrd_name = subitem + '-' + category;
}
if (subitem==active_subitem) { if (subitem==active_subitem) {
tabs += '<li class="active"><a data-toggle="tab" onclick="getdata(\''+rrd_name+'\',0,0,120,0);" id="'+rrd_name+'"><i class="fa fa-check-square"></i> ' + subitem[0].toUpperCase() + subitem.slice(1) + '</a></li>'; tabs += '<li class="active"><a data-toggle="tab" onclick="getdata(\''+rrd_name+'\',0,0,120,0);" id="'+rrd_name+'"><i class="fa fa-check-square"></i> ' + subitem[0].toUpperCase() + subitem.slice(1) + '</a></li>';
......
...@@ -46,6 +46,10 @@ for filename in glob.glob('%s/*.rrd' % rrd_reports_dir): ...@@ -46,6 +46,10 @@ for filename in glob.glob('%s/*.rrd' % rrd_reports_dir):
if rrdFilename.split('-')[0] == 'system' and rrdFilename.find('-') > -1: if rrdFilename.split('-')[0] == 'system' and rrdFilename.find('-') > -1:
topic = rrdFilename.split('-')[0] topic = rrdFilename.split('-')[0]
itemName = '-'.join(rrdFilename.split('-')[1:]) itemName = '-'.join(rrdFilename.split('-')[1:])
elif rrdFilename.find('-') == -1:
# set topic for items without one
topic = 'services'
itemName = rrdFilename.split('.')[0]
else: else:
topic = rrdFilename.split('-')[-1] topic = rrdFilename.split('-')[-1]
itemName = '-'.join(rrdFilename.split('-')[:-1]) itemName = '-'.join(rrdFilename.split('-')[:-1])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment