Add ProcessCheckResultCommandForm

refs #6854
This commit is contained in:
Johannes Meyer 2014-12-11 15:52:23 +01:00
parent 8779e80291
commit ddc121d1cc
8 changed files with 196 additions and 1 deletions

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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;
}
}

View File

@ -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(

View File

@ -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(

View File

@ -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