mirror of
https://github.com/Icinga/icingaweb2-module-graphite.git
synced 2026-05-28 04:34:57 -04:00
Query only the templates designed for the monitored object's check command
refs #55
This commit is contained in:
parent
ecf68be45a
commit
e723b04a04
8 changed files with 83 additions and 18 deletions
|
|
@ -29,7 +29,7 @@ class ListController extends MonitoringAwareController
|
|||
);
|
||||
|
||||
$this->view->hosts = $hosts = $this->applyMonitoringRestriction(
|
||||
$this->backend->select()->from('hoststatus', ['host_name', 'host_display_name'])
|
||||
$this->backend->select()->from('hoststatus', ['host_name', 'host_display_name', 'host_check_command'])
|
||||
);
|
||||
|
||||
$this->filterQuery($hosts);
|
||||
|
|
@ -54,7 +54,8 @@ class ListController extends MonitoringAwareController
|
|||
'host_name',
|
||||
'host_display_name',
|
||||
'service_description',
|
||||
'service_display_name'
|
||||
'service_display_name',
|
||||
'service_check_command'
|
||||
])
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,9 @@ if ($filterEditor->getFilter()->isEmpty()) {
|
|||
)
|
||||
. '</h2>';
|
||||
}
|
||||
echo (new Host($host->host_name))->setCompact()->handleRequest();
|
||||
echo (new Host($host->host_name, $host->host_check_command))
|
||||
->setCompact()
|
||||
->handleRequest();
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,9 @@ if ($filterEditor->getFilter()->isEmpty()) {
|
|||
)
|
||||
. '</h2>';
|
||||
}
|
||||
echo (new Service($service->host_name, $service->service_description))->setCompact()->handleRequest();
|
||||
echo (new Service($service->host_name, $service->service_description, $service->service_check_command))
|
||||
->setCompact()
|
||||
->handleRequest();
|
||||
}
|
||||
|
||||
if (! $compact && $services->hasMore()) {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,13 @@ class Template
|
|||
*/
|
||||
protected $urlParams = [];
|
||||
|
||||
/**
|
||||
* The check command this template is designed for
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $checkCommand;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
|
@ -173,4 +180,28 @@ class Template
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the check command this template is designed for
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCheckCommand()
|
||||
{
|
||||
return $this->checkCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the check command this template is designed for
|
||||
*
|
||||
* @param string $checkCommand
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCheckCommand($checkCommand)
|
||||
{
|
||||
$this->checkCommand = $checkCommand;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -264,7 +264,8 @@ class Templates
|
|||
|
||||
$templates[$templateName] = (new Template())
|
||||
->setCurves($curves)
|
||||
->setUrlParams($urlParams);
|
||||
->setUrlParams($urlParams)
|
||||
->setCheckCommand($checkCommand);
|
||||
}
|
||||
|
||||
foreach ($templates as $templateName => $template) {
|
||||
|
|
|
|||
|
|
@ -55,6 +55,13 @@ abstract class Graphs extends AbstractWidget
|
|||
*/
|
||||
protected $compact = false;
|
||||
|
||||
/**
|
||||
* The check command of the monitored object we display graphs for
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $checkCommand;
|
||||
|
||||
/**
|
||||
* Factory, based on the given object
|
||||
*
|
||||
|
|
@ -67,14 +74,31 @@ abstract class Graphs extends AbstractWidget
|
|||
switch ($object->getType()) {
|
||||
case 'host':
|
||||
/** @var Host $object */
|
||||
return (new HostGraphs($object->getName()));
|
||||
return new HostGraphs(
|
||||
$object->getName(),
|
||||
$object->host_check_command
|
||||
);
|
||||
|
||||
case 'service':
|
||||
/** @var Service $object */
|
||||
return (new ServiceGraphs($object->getHost()->getName(), $object->getName()));
|
||||
return new ServiceGraphs(
|
||||
$object->getHost()->getName(),
|
||||
$object->getName(),
|
||||
$object->service_check_command
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $checkCommand The check command of the monitored object we display graphs for
|
||||
*/
|
||||
public function __construct($checkCommand)
|
||||
{
|
||||
$this->checkCommand = $checkCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the given request using this widget
|
||||
*
|
||||
|
|
@ -104,13 +128,11 @@ abstract class Graphs extends AbstractWidget
|
|||
$filter = $this->getMonitoredObjectFilter();
|
||||
$imageBaseUrl = $this->getImageBaseUrl();
|
||||
$templates = static::getAllTemplates()->getTemplates();
|
||||
$templateNames = array_keys($templates);
|
||||
|
||||
shuffle($templateNames);
|
||||
|
||||
foreach ($templateNames as $templateName) {
|
||||
if ($this->designedForMyMonitoredObjectType($templates[$templateName])) {
|
||||
$charts = $templates[$templateName]->getCharts(static::getMetricsDataSource(), $filter);
|
||||
foreach ($templates as $templateName => $template) {
|
||||
if ($this->designedForMyMonitoredObjectType($template)
|
||||
&& $template->getCheckCommand() === $this->checkCommand) {
|
||||
$charts = $template->getCharts(static::getMetricsDataSource(), $filter);
|
||||
if (! empty($charts)) {
|
||||
$result[] = '<div class="images">';
|
||||
|
||||
|
|
|
|||
|
|
@ -18,10 +18,13 @@ class Host extends Graphs
|
|||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $host The host to render the graphs of
|
||||
* @param string $host The host to render the graphs of
|
||||
* @param string $checkCommand The check command of the monitored object we display graphs for
|
||||
*/
|
||||
public function __construct($host)
|
||||
public function __construct($host, $checkCommand)
|
||||
{
|
||||
parent::__construct($checkCommand);
|
||||
|
||||
$this->host = $host;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,11 +25,14 @@ class Service extends Graphs
|
|||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $host The host to render the graphs of
|
||||
* @param string $service The service to render the graphs of
|
||||
* @param string $host The host to render the graphs of
|
||||
* @param string $service The service to render the graphs of
|
||||
* @param string $checkCommand The check command of the monitored object we display graphs for
|
||||
*/
|
||||
public function __construct($host, $service)
|
||||
public function __construct($host, $service, $checkCommand)
|
||||
{
|
||||
parent::__construct($checkCommand);
|
||||
|
||||
$this->host = $host;
|
||||
$this->service = $service;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue