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 @@ +<?php +// {{{ICINGA_LICENSE_HEADER}}} +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Icinga\Module\Monitoring\Forms\Command\Object; + +use Icinga\Web\Notification; +use Icinga\Module\Monitoring\Command\Object\ProcessCheckResultCommand; + +/** + * Form for submitting a passive host or service check result + */ +class ProcessCheckResultCommandForm extends ObjectsCommandForm +{ + /** + * (non-PHPDoc) + * @see \Icinga\Web\Form::getSubmitLabel() For the method documentation. + */ + public function getSubmitLabel() + { + return mtp( + 'monitoring', 'Submit Passive Check Result', 'Submit Passive Check Results', count($this->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 @@ </a> </div> + <div> + <a href="<?= $processCheckResultAllLink; ?>"> + <?= $this->icon('reply'); ?> + <?= $this->translate('Submit passive check results'); ?> + </a> + </div> + <?php if (! empty($unhandledObjects)): ?> <h3> <?= sprintf( diff --git a/modules/monitoring/application/views/scripts/services/show.phtml b/modules/monitoring/application/views/scripts/services/show.phtml index af05979fb..18071c152 100644 --- a/modules/monitoring/application/views/scripts/services/show.phtml +++ b/modules/monitoring/application/views/scripts/services/show.phtml @@ -59,6 +59,13 @@ </a> </div> + <div> + <a href="<?= $processCheckResultAllLink; ?>"> + <?= $this->icon('reply'); ?> + <?= $this->translate('Submit passive check results'); ?> + </a> + </div> + <?php if (! empty($unhandledObjects)): ?> <h3> <?= sprintf( diff --git a/modules/monitoring/application/views/scripts/show/components/command.phtml b/modules/monitoring/application/views/scripts/show/components/command.phtml index 715240679..a13ed1bee 100644 --- a/modules/monitoring/application/views/scripts/show/components/command.phtml +++ b/modules/monitoring/application/views/scripts/show/components/command.phtml @@ -5,7 +5,21 @@ $command = array_shift($parts); ?><tr class="newsection"> <th><?= $this->translate('Command') ?></th> - <td><?= $this->escape($command) ?> + <td> + <?= $this->escape($command) ?> + <?php if ($object->passive_checks_enabled): ?> + <?php if ($object->getType() === $object::TYPE_HOST): ?> + <a href="<?= $this->href( + 'monitoring/host/process-check-result', + array('host' => $object->getName()) + ); ?>"><?= $this->icon('reply'); ?> <?= $this->translate('Process check result'); ?></a> + <?php else: ?> + <a href="<?= $this->href( + 'monitoring/service/process-check-result', + array('host' => $object->getHost()->getName(), 'service' => $object->getName()) + ); ?>"><?= $this->icon('reply'); ?> <?= $this->translate('Process check result'); ?></a> + <?php endif ?> + <?php endif ?> </tr> <?php