Private GIT

Skip to content
Snippets Groups Projects
Commit bb31802d authored by Maximilien Bersoult's avatar Maximilien Bersoult
Browse files

* List only the services with metrics on graph view

parent 4824ee0c
No related branches found
No related tags found
No related merge requests found
......@@ -139,6 +139,28 @@ class GraphController extends Controller
$router->response()->json($data);
}
/**
* Get list of service with metrics
*
* @route /service/withmetrics
* @method get
*/
public function getServiceWithMetricsAction()
{
$router = Di::getDefault()->get('router');
$requestParams = $this->getParams('get');
$list = GraphView::getServiceWithMetrics($requestParams['q']);
foreach ($list as $infos) {
$finalList[] = array(
'id' => $infos['service_id'],
'text' => $infos['name'] . ' ' . $infos['description']
);
}
$router->response()->json($finalList);
}
/**
* Save a graph view
*
......
......@@ -233,4 +233,36 @@ class GraphView
}
return array_unique($metrics);
}
/**
* Get the list of services with metrics
*
* @param string $filter The filter search
* @return array
*/
public static function getServiceWithMetrics($filter = null)
{
$dbconn = Di::getDefault()->get('db_centreon');
$query = "SELECT DISTINCT h.host_id, h.name, s.service_id, s.description
FROM rt_hosts h, rt_services s, rt_index_data i, rt_metrics m
WHERE h.host_id = s.host_id
AND (h.name LIKE :name OR s.description LIKE :name)
AND h.host_id = i.host_id
AND s.service_id = i.service_id
AND i.id = m.index_id";
if (is_null($filter) || $filter == '') {
$filterStr = "%";
} else {
$filterStr = "%" . $filter . "%";
}
$stmt = $dbconn->prepare($query);
$stmt->bindParam(':name', $filterStr, \PDO::PARAM_STR);
$stmt->execute();
$list = array();
while ($row = $stmt->fetch()) {
$list[] = $row;
}
return $list;
}
}
......@@ -281,7 +281,7 @@ $(function() {
ajax: {
data: function(term, page) { return { q: term }; },
dataType: "json",
url: "{url_for url="/centreon-configuration/service/formlist"}" ,
url: "{url_for url="/centreon-performance/service/withmetrics"}" ,
results: function(data) { return { results: data, more: false }; }
}
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment