diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index 39bc0bd..eeff4f1 100644 --- a/application/controllers/ListController.php +++ b/application/controllers/ListController.php @@ -6,6 +6,7 @@ use Icinga\Module\Graphite\Forms\TimeRangePicker\TimeRangePickerTrait as TimeRan use Icinga\Module\Graphite\Forms\TimeRangePicker\TimeRangePickerTrait as TimeRangePickerFormTrait; use Icinga\Module\Graphite\Web\Controller\MonitoringAwareController; use Icinga\Module\Graphite\Web\Controller\TimeRangePickerTrait; +use Icinga\Module\Graphite\Web\Widget\Graphs; use Icinga\Module\Monitoring\DataView\DataView; use Icinga\Web\Url; use Icinga\Web\Widget\Tabextension\DashboardAction; @@ -34,7 +35,7 @@ class ListController extends MonitoringAwareController 'host_name', 'host_display_name', 'host_check_command', - '_host_check_command' + '_host_check_command' => '_host_' . Graphs::getObscuredCheckCommandCustomVar() ]) ); @@ -68,7 +69,7 @@ class ListController extends MonitoringAwareController 'service_description', 'service_display_name', 'service_check_command', - '_service_check_command' + '_service_check_command' => '_service_' . Graphs::getObscuredCheckCommandCustomVar() ]) ); diff --git a/application/forms/Config/AdvancedForm.php b/application/forms/Config/AdvancedForm.php index 5ff3b75..896d037 100644 --- a/application/forms/Config/AdvancedForm.php +++ b/application/forms/Config/AdvancedForm.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Graphite\Forms\Config; use Icinga\Forms\ConfigForm; use Icinga\Module\Graphite\Web\Form\Validator\MacroTemplateValidator; +use Zend_Validate_Regex; class AdvancedForm extends ConfigForm { @@ -39,6 +40,18 @@ class AdvancedForm extends ConfigForm ), 'validators' => [new MacroTemplateValidator()] ] + ], + [ + 'text', + 'icinga_customvar_obscured_check_command', + [ + 'label' => $this->translate('Obscured check command custom variable'), + 'description' => $this->translate( + 'The Icinga custom variable with the "actual" check command obscured' + . ' by e.g. check_by_ssh (defaults to check_command)' + ), + 'validators' => [new Zend_Validate_Regex('/\A\w*\z/')] + ] ] ]); } diff --git a/library/Graphite/Web/Widget/Graphs.php b/library/Graphite/Web/Widget/Graphs.php index aa7184e..b36679b 100644 --- a/library/Graphite/Web/Widget/Graphs.php +++ b/library/Graphite/Web/Widget/Graphs.php @@ -2,6 +2,7 @@ namespace Icinga\Module\Graphite\Web\Widget; +use Icinga\Application\Config; use Icinga\Application\Icinga; use Icinga\Module\Graphite\Forms\TimeRangePicker\TimeRangePickerTrait; use Icinga\Module\Graphite\Graphing\GraphingTrait; @@ -20,6 +21,13 @@ abstract class Graphs extends AbstractWidget { use GraphingTrait; + /** + * The Icinga custom variable with the "real" check command (if any) of monitored objects we display graphs for + * + * @var string + */ + protected static $obscuredCheckCommandCustomVar; + /** * Graph image width * @@ -114,7 +122,7 @@ abstract class Graphs extends AbstractWidget return new HostGraphs( $object->getName(), $object->host_check_command, - $object->_host_check_command + $object->{'_host_' . Graphs::getObscuredCheckCommandCustomVar()} ); case 'service': @@ -123,11 +131,26 @@ abstract class Graphs extends AbstractWidget $object->getHost()->getName(), $object->getName(), $object->service_check_command, - $object->_service_check_command + $object->{'_service_' . Graphs::getObscuredCheckCommandCustomVar()} ); } } + /** + * Get the Icinga custom variable with the "real" check command (if any) of monitored objects we display graphs for + * + * @return string + */ + public static function getObscuredCheckCommandCustomVar() + { + if (static::$obscuredCheckCommandCustomVar === null) { + static::$obscuredCheckCommandCustomVar = Config::module('graphite') + ->get('icinga', 'customvar_obscured_check_command', 'check_command'); + } + + return static::$obscuredCheckCommandCustomVar; + } + /** * Constructor *