Decide which templates to use based on the real check command

refs #5
This commit is contained in:
Alexander A. Klimov 2017-10-06 17:03:45 +02:00
parent a911599924
commit aba61645f8
3 changed files with 33 additions and 14 deletions

View file

@ -62,6 +62,15 @@ abstract class Graphs extends AbstractWidget
*/
protected $checkCommand;
/**
* The "real" check command (if any) of the monitored object we display graphs for
*
* E.g. the command executed remotely via check_by_ssh
*
* @var string|null
*/
protected $obscuredCheckCommand;
/**
* Additional CSS classes for the <div/>s around the images
*
@ -83,7 +92,8 @@ abstract class Graphs extends AbstractWidget
/** @var Host $object */
return new HostGraphs(
$object->getName(),
$object->host_check_command
$object->host_check_command,
$object->_host_check_command
);
case 'service':
@ -91,7 +101,8 @@ abstract class Graphs extends AbstractWidget
return new ServiceGraphs(
$object->getHost()->getName(),
$object->getName(),
$object->service_check_command
$object->service_check_command,
$object->_service_check_command
);
}
}
@ -99,11 +110,14 @@ abstract class Graphs extends AbstractWidget
/**
* Constructor
*
* @param string $checkCommand The check command of the monitored object we display graphs for
* @param string $checkCommand The check command of the monitored object we display graphs for
* @param string|null $obscuredCheckCommand The "real" check command (if any) of the monitored object
* we display graphs for
*/
public function __construct($checkCommand)
public function __construct($checkCommand, $obscuredCheckCommand)
{
$this->checkCommand = $checkCommand;
$this->obscuredCheckCommand = $obscuredCheckCommand;
}
/**
@ -135,6 +149,7 @@ abstract class Graphs extends AbstractWidget
$filter = $this->getMonitoredObjectFilter();
$imageBaseUrl = $this->getImageBaseUrl();
$templates = static::getAllTemplates()->getTemplates();
$checkCommand = $this->obscuredCheckCommand === null ? $this->checkCommand : $this->obscuredCheckCommand;
$classes = $this->classes;
$classes[] = 'images';
@ -142,7 +157,7 @@ abstract class Graphs extends AbstractWidget
foreach ($templates as $templateName => $template) {
if ($this->designedForMyMonitoredObjectType($template)
&& $template->getCheckCommand() === $this->checkCommand) {
&& $template->getCheckCommand() === $checkCommand) {
$charts = $template->getCharts(static::getMetricsDataSource(), $filter);
if (! empty($charts)) {
$result[] = $div;

View file

@ -18,12 +18,14 @@ class Host extends Graphs
/**
* Constructor
*
* @param string $host The host to render the graphs of
* @param string $checkCommand The check command of the monitored object we display graphs for
* @param string $host The host to render the graphs of
* @param string $checkCommand The check command of the monitored object we display graphs for
* @param string|null $obscuredCheckCommand The "real" check command (if any) of the monitored object
* we display graphs for
*/
public function __construct($host, $checkCommand)
public function __construct($host, $checkCommand, $obscuredCheckCommand)
{
parent::__construct($checkCommand);
parent::__construct($checkCommand, $obscuredCheckCommand);
$this->host = $host;
}

View file

@ -25,13 +25,15 @@ 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 $checkCommand The check command of the monitored object we display graphs for
* @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
* @param string|null $obscuredCheckCommand The "real" check command (if any) of the monitored object
* we display graphs for
*/
public function __construct($host, $service, $checkCommand)
public function __construct($host, $service, $checkCommand, $obscuredCheckCommand)
{
parent::__construct($checkCommand);
parent::__construct($checkCommand, $obscuredCheckCommand);
$this->host = $host;
$this->service = $service;