From ddc121d1ccab73e991273a77936c2af690ec3716 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 11 Dec 2014 15:52:23 +0100 Subject: [PATCH] Add ProcessCheckResultCommandForm refs #6854 --- .../controllers/HostController.php | 10 ++ .../controllers/HostsController.php | 11 ++ .../controllers/ServiceController.php | 10 ++ .../controllers/ServicesController.php | 13 ++ .../Object/ProcessCheckResultCommandForm.php | 123 ++++++++++++++++++ .../views/scripts/hosts/show.phtml | 7 + .../views/scripts/services/show.phtml | 7 + .../scripts/show/components/command.phtml | 16 ++- 8 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 modules/monitoring/application/forms/Command/Object/ProcessCheckResultCommandForm.php diff --git a/modules/monitoring/application/controllers/HostController.php b/modules/monitoring/application/controllers/HostController.php index 0a4a727ed..184e05a4c 100644 --- a/modules/monitoring/application/controllers/HostController.php +++ b/modules/monitoring/application/controllers/HostController.php @@ -2,6 +2,7 @@ // {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}} +use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\AddCommentCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostCheckCommandForm; @@ -76,4 +77,13 @@ class Monitoring_HostController extends MonitoredObjectController $this->view->title = $this->translate('Schedule Host Downtime'); $this->handleCommandForm(new ScheduleHostDowntimeCommandForm()); } + + /** + * Submit a passive host check result + */ + public function processCheckResultAction() + { + $this->view->title = $this->translate('Submit Passive Host Check Result'); + $this->handleCommandForm(new ProcessCheckResultCommandForm()); + } } diff --git a/modules/monitoring/application/controllers/HostsController.php b/modules/monitoring/application/controllers/HostsController.php index fe34c1d6f..4aa090572 100644 --- a/modules/monitoring/application/controllers/HostsController.php +++ b/modules/monitoring/application/controllers/HostsController.php @@ -4,6 +4,7 @@ use Icinga\Data\Filter\Filter; use Icinga\Module\Monitoring\Controller; +use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\CheckNowCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ObjectsCommandForm; @@ -103,6 +104,7 @@ class Monitoring_HostsController extends Controller $this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/hosts'); $this->view->rescheduleAllLink = Url::fromRequest()->setPath('monitoring/hosts/reschedule-check'); $this->view->downtimeAllLink = Url::fromRequest()->setPath('monitoring/hosts/schedule-downtime'); + $this->view->processCheckResultAllLink = Url::fromRequest()->setPath('monitoring/hosts/process-check-result'); $this->view->hostStates = $hostStates; $this->view->objects = $this->hostList; $this->view->unhandledObjects = $unhandledObjects; @@ -161,4 +163,13 @@ class Monitoring_HostsController extends Controller $this->view->title = $this->translate('Schedule Host Downtimes'); $this->handleCommandForm(new ScheduleHostDowntimeCommandForm()); } + + /** + * Submit passive host check results + */ + public function processCheckResultAction() + { + $this->view->title = $this->translate('Submit Passive Host Check Results'); + $this->handleCommandForm(new ProcessCheckResultCommandForm()); + } } diff --git a/modules/monitoring/application/controllers/ServiceController.php b/modules/monitoring/application/controllers/ServiceController.php index c6d0e4e2f..70aa9e519 100644 --- a/modules/monitoring/application/controllers/ServiceController.php +++ b/modules/monitoring/application/controllers/ServiceController.php @@ -2,6 +2,7 @@ // {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}} +use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\AddCommentCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceCheckCommandForm; @@ -76,4 +77,13 @@ class Monitoring_ServiceController extends MonitoredObjectController $this->view->title = $this->translate('Schedule Service Downtime'); $this->handleCommandForm(new ScheduleServiceDowntimeCommandForm()); } + + /** + * Submit a passive service check result + */ + public function processCheckResultAction() + { + $this->view->title = $this->translate('Submit Passive Service Check Result'); + $this->handleCommandForm(new ProcessCheckResultCommandForm()); + } } diff --git a/modules/monitoring/application/controllers/ServicesController.php b/modules/monitoring/application/controllers/ServicesController.php index 56813180d..bbe2024d7 100644 --- a/modules/monitoring/application/controllers/ServicesController.php +++ b/modules/monitoring/application/controllers/ServicesController.php @@ -4,6 +4,7 @@ use Icinga\Data\Filter\Filter; use Icinga\Module\Monitoring\Controller; +use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\CheckNowCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ObjectsCommandForm; @@ -117,6 +118,9 @@ class Monitoring_ServicesController extends Controller $this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/services'); $this->view->rescheduleAllLink = Url::fromRequest()->setPath('monitoring/services/reschedule-check'); $this->view->downtimeAllLink = Url::fromRequest()->setPath('monitoring/services/schedule-downtime'); + $this->view->processCheckResultAllLink = Url::fromRequest()->setPath( + 'monitoring/services/process-check-result' + ); $this->view->hostStates = $hostStates; $this->view->serviceStates = $serviceStates; $this->view->objects = $this->serviceList; @@ -181,4 +185,13 @@ class Monitoring_ServicesController extends Controller $this->view->title = $this->translate('Schedule Service Downtimes'); $this->handleCommandForm(new ScheduleServiceDowntimeCommandForm()); } + + /** + * Submit passive service check results + */ + public function processCheckResultAction() + { + $this->view->title = $this->translate('Submit Passive Service Check Results'); + $this->handleCommandForm(new ProcessCheckResultCommandForm()); + } } diff --git a/modules/monitoring/application/forms/Command/Object/ProcessCheckResultCommandForm.php b/modules/monitoring/application/forms/Command/Object/ProcessCheckResultCommandForm.php new file mode 100644 index 000000000..48ee00ab3 --- /dev/null +++ b/modules/monitoring/application/forms/Command/Object/ProcessCheckResultCommandForm.php @@ -0,0 +1,123 @@ +objects) + ); + } + + /** + * (non-PHPDoc) + * @see \Icinga\Module\Monitoring\Forms\Command\CommandForm::getHelp() For the method documentation. + */ + public function getHelp() + { + return mt( + 'monitoring', + 'This command is used to submit passive host or service check results.' + ); + } + + /** + * (non-PHPDoc) + * @see \Icinga\Web\Form::createElements() For the method documentation. + */ + public function createElements(array $formData) + { + foreach ($this->getObjects() as $object) { + /** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */ + // Nasty, but as getObjects() returns everything but an object with a real + // iterator interface this is the only way to fetch just the first element + break; + } + + $this->addElement( + 'select', + 'status', + array( + 'required' => true, + 'label' => mt('monitoring', 'Status'), + 'description' => mt('monitoring', 'The state this check result should report'), + 'multiOptions' => $object->getType() === $object::TYPE_HOST ? array( + ProcessCheckResultCommand::HOST_UP => mt('monitoring', 'UP', 'icinga.state'), + ProcessCheckResultCommand::HOST_DOWN => mt('monitoring', 'DOWN', 'icinga.state'), + ProcessCheckResultCommand::HOST_UNREACHABLE => mt('monitoring', 'UNREACHABLE', 'icinga.state') + ) : array( + ProcessCheckResultCommand::SERVICE_OK => mt('monitoring', 'OK', 'icinga.state'), + ProcessCheckResultCommand::SERVICE_WARNING => mt('monitoring', 'WARNING', 'icinga.state'), + ProcessCheckResultCommand::SERVICE_CRITICAL => mt('monitoring', 'CRITICAL', 'icinga.state'), + ProcessCheckResultCommand::SERVICE_UNKNOWN => mt('monitoring', 'UNKNOWN', 'icinga.state') + ) + ) + ); + $this->addElement( + 'text', + 'output', + array( + 'required' => true, + 'label' => mt('monitoring', 'Output'), + 'description' => mt('monitoring', 'The plugin output of this check result') + ) + ); + $this->addElement( + 'text', + 'perfdata', + array( + 'allowEmpty' => true, + 'label' => mt('monitoring', 'Performance Data'), + 'description' => mt( + 'monitoring', + 'The performance data of this check result. Leave empty' + . ' if this check result has no performance data' + ) + ) + ); + } + + /** + * (non-PHPDoc) + * @see \Icinga\Web\Form::onSuccess() For the method documentation. + */ + public function onSuccess() + { + foreach ($this->objects as $object) { + /** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */ + $command = new ProcessCheckResultCommand(); + $command->setObject($object); + $command->setStatus($this->getValue('status')); + $command->setOutput($this->getValue('output')); + + if ($perfdata = $this->getValue('perfdata')) { + $command->setPerformanceData($perfdata); + } + + $this->getTransport($this->request)->send($command); + } + + Notification::success(mtp( + 'monitoring', + 'Processing check result..', + 'Processing check results..', + count($this->objects) + )); + + return true; + } +} diff --git a/modules/monitoring/application/views/scripts/hosts/show.phtml b/modules/monitoring/application/views/scripts/hosts/show.phtml index 6adc300d8..6ab717635 100644 --- a/modules/monitoring/application/views/scripts/hosts/show.phtml +++ b/modules/monitoring/application/views/scripts/hosts/show.phtml @@ -47,6 +47,13 @@ +
+ + icon('reply'); ?> + translate('Submit passive check results'); ?> + +
+

+
+ + icon('reply'); ?> + translate('Submit passive check results'); ?> + +
+

translate('Command') ?> - escape($command) ?> + + escape($command) ?> + passive_checks_enabled): ?> + getType() === $object::TYPE_HOST): ?> + icon('reply'); ?> translate('Process check result'); ?> + + icon('reply'); ?> translate('Process check result'); ?> + +