Fix incorrect checkresult type selection

When submitting a passive checkresult for hosts only their correct
result types are added to the selection.

refs #4600
This commit is contained in:
Johannes Meyer 2013-09-02 09:41:19 +02:00 committed by Jannis Moßhammer
parent b63e19063e
commit 24ecbb56d7
4 changed files with 138 additions and 42 deletions

View File

@ -27,12 +27,10 @@
*/ */
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
use \Icinga\Application\Benchmark;
use \Icinga\Application\Icinga; use \Icinga\Application\Icinga;
use \Monitoring\Backend; use \Monitoring\Backend;
use \Icinga\Application\Config; use \Icinga\Application\Config;
use \Icinga\Application\Logger; use \Icinga\Application\Logger;
use \Icinga\Authentication\Manager;
use \Icinga\Web\Form; use \Icinga\Web\Form;
use \Icinga\Web\Controller\ModuleActionController; use \Icinga\Web\Controller\ModuleActionController;
use \Icinga\Protocol\Commandpipe\CommandPipe; use \Icinga\Protocol\Commandpipe\CommandPipe;
@ -59,18 +57,21 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Command target * Command target
*
* @var CommandPipe * @var CommandPipe
*/ */
private $target; private $target;
/** /**
* Current form working on * Current form working on
*
* @var Form * @var Form
*/ */
private $form; private $form;
/** /**
* Setter for form * Setter for form
*
* @param Form $form * @param Form $form
*/ */
public function setForm($form) public function setForm($form)
@ -80,6 +81,7 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Test if we have a valid form object * Test if we have a valid form object
*
* @return bool * @return bool
*/ */
public function issetForm() public function issetForm()
@ -143,9 +145,7 @@ class Monitoring_CommandController extends ModuleActionController
* *
* @param $hostOnly Ignore the service parameters * @param $hostOnly Ignore the service parameters
* (for example when using commands that only make sense for hosts) * (for example when using commands that only make sense for hosts)
*
* @return array Array of monitoring objects * @return array Array of monitoring objects
*
* @throws Icinga\Exception\MissingParameterException * @throws Icinga\Exception\MissingParameterException
*/ */
private function selectCommandTargets($hostOnly = false) private function selectCommandTargets($hostOnly = false)
@ -170,7 +170,6 @@ class Monitoring_CommandController extends ModuleActionController
$fields[] = "service_description"; $fields[] = "service_description";
$fields[] = "service_state"; $fields[] = "service_state";
} }
;
$query = Backend::getInstance($this->_getParam('backend'))->select()->from("status", $fields); $query = Backend::getInstance($this->_getParam('backend'))->select()->from("status", $fields);
return $query->applyFilters($filter)->fetchAll(); return $query->applyFilters($filter)->fetchAll();
} catch (\Exception $e) { } catch (\Exception $e) {
@ -187,7 +186,6 @@ class Monitoring_CommandController extends ModuleActionController
* *
* This method uses reflection on the sourcecode to determine all *Action classes and return * This method uses reflection on the sourcecode to determine all *Action classes and return
* a list of them (ignoring the listAction) * a list of them (ignoring the listAction)
*
*/ */
public function listAction() public function listAction()
{ {
@ -206,9 +204,8 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Tell the controller that at least one of the parameters in $supported is required to be availabe * Tell the controller that at least one of the parameters in $supported is required to be availabe
* *
* @param array $supported An array of properties to check for existence in the POST or GET parameter list * @param array $supported An array of properties to check for existence in the POST or GET parameter list
* * @throws Exception When non of the supported parameters is given
* @throws Exception When non of the supported parameters is given
*/ */
private function setSupportedParameters(array $supported) private function setSupportedParameters(array $supported)
{ {
@ -221,8 +218,7 @@ class Monitoring_CommandController extends ModuleActionController
if (empty($this->view->objects)) { if (empty($this->view->objects)) {
throw new \Exception("No objects found for your command"); throw new \Exception("No objects found for your command");
} }
} elseif (in_array("downtimeid", $supported)) {
} else if (in_array("downtimeid", $supported)) {
$this->view->objects = array(); $this->view->objects = array();
$downtimes = $this->getParam("downtimeid"); $downtimes = $this->getParam("downtimeid");
if (!is_array($downtimes)) { if (!is_array($downtimes)) {
@ -240,7 +236,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command disableactivechecks * Handle command disableactivechecks
*
*/ */
public function disableactivechecksAction() public function disableactivechecksAction()
{ {
@ -258,7 +253,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command enableactivechecks * Handle command enableactivechecks
*
*/ */
public function enableactivechecksAction() public function enableactivechecksAction()
{ {
@ -276,7 +270,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command reschedulenextcheck * Handle command reschedulenextcheck
*
*/ */
public function reschedulenextcheckAction() public function reschedulenextcheckAction()
{ {
@ -293,12 +286,14 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command submitpassivecheckresult * Handle command submitpassivecheckresult
*
*/ */
public function submitpassivecheckresultAction() public function submitpassivecheckresultAction()
{ {
$this->setSupportedParameters(array('host', 'service')); $this->setSupportedParameters(array('host', 'service'));
$type = SubmitPassiveCheckResultForm::TYPE_SERVICE; $type = SubmitPassiveCheckResultForm::TYPE_SERVICE;
if ($this->getParam('service', null) === null) {
$type = SubmitPassiveCheckResultForm::TYPE_HOST;
}
$form = new SubmitPassiveCheckResultForm(); $form = new SubmitPassiveCheckResultForm();
$form->setRequest($this->getRequest()); $form->setRequest($this->getRequest());
@ -313,7 +308,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command stopobsessing * Handle command stopobsessing
*
*/ */
public function stopobsessingAction() public function stopobsessingAction()
{ {
@ -331,7 +325,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command startobsessing * Handle command startobsessing
*
*/ */
public function startobsessingAction() public function startobsessingAction()
{ {
@ -349,7 +342,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command stopacceptingpassivechecks * Handle command stopacceptingpassivechecks
*
*/ */
public function stopacceptingpassivechecksAction() public function stopacceptingpassivechecksAction()
{ {
@ -367,7 +359,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command startacceptingpassivechecks * Handle command startacceptingpassivechecks
*
*/ */
public function startacceptingpassivechecksAction() public function startacceptingpassivechecksAction()
{ {
@ -385,7 +376,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command disablenotifications * Handle command disablenotifications
*
*/ */
public function disablenotificationsAction() public function disablenotificationsAction()
{ {
@ -403,7 +393,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command enablenotifications * Handle command enablenotifications
*
*/ */
public function enablenotificationsAction() public function enablenotificationsAction()
{ {
@ -420,7 +409,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command sendcustomnotification * Handle command sendcustomnotification
*
*/ */
public function sendcustomnotificationAction() public function sendcustomnotificationAction()
{ {
@ -436,7 +424,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command scheduledowntime * Handle command scheduledowntime
*
*/ */
public function scheduledowntimeAction() public function scheduledowntimeAction()
{ {
@ -453,8 +440,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command scheduledowntimeswithchildren * Handle command scheduledowntimeswithchildren
*
* @throws Icinga\Exception\ProgrammingError
*/ */
public function scheduledowntimeswithchildrenAction() public function scheduledowntimeswithchildrenAction()
{ {
@ -471,7 +456,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command removedowntimeswithchildren * Handle command removedowntimeswithchildren
*
*/ */
public function removedowntimeswithchildrenAction() public function removedowntimeswithchildrenAction()
{ {
@ -489,7 +473,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command disablenotificationswithchildren * Handle command disablenotificationswithchildren
*
*/ */
public function disablenotificationswithchildrenAction() public function disablenotificationswithchildrenAction()
{ {
@ -508,7 +491,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command enablenotificationswithchildren * Handle command enablenotificationswithchildren
*
*/ */
public function enablenotificationswithchildrenAction() public function enablenotificationswithchildrenAction()
{ {
@ -527,7 +509,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command reschedulenextcheckwithchildren * Handle command reschedulenextcheckwithchildren
*
*/ */
public function reschedulenextcheckwithchildrenAction() public function reschedulenextcheckwithchildrenAction()
{ {
@ -552,7 +533,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command disableactivecheckswithchildren * Handle command disableactivecheckswithchildren
*
*/ */
public function disableactivecheckswithchildrenAction() public function disableactivecheckswithchildrenAction()
{ {
@ -571,7 +551,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command enableactivecheckswithchildren * Handle command enableactivecheckswithchildren
*
*/ */
public function enableactivecheckswithchildrenAction() public function enableactivecheckswithchildrenAction()
{ {
@ -590,7 +569,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command disableeventhandler * Handle command disableeventhandler
*
*/ */
public function disableeventhandlerAction() public function disableeventhandlerAction()
{ {
@ -608,7 +586,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command enableeventhandler * Handle command enableeventhandler
*
*/ */
public function enableeventhandlerAction() public function enableeventhandlerAction()
{ {
@ -626,7 +603,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command disableflapdetection * Handle command disableflapdetection
*
*/ */
public function disableflapdetectionAction() public function disableflapdetectionAction()
{ {
@ -644,7 +620,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command enableflapdetection * Handle command enableflapdetection
*
*/ */
public function enableflapdetectionAction() public function enableflapdetectionAction()
{ {
@ -662,7 +637,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command addcomment * Handle command addcomment
*
*/ */
public function addcommentAction() public function addcommentAction()
{ {
@ -679,7 +653,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command resetattributes * Handle command resetattributes
*
*/ */
public function resetattributesAction() public function resetattributesAction()
{ {
@ -697,7 +670,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command acknowledgeproblem * Handle command acknowledgeproblem
*
*/ */
public function acknowledgeproblemAction() public function acknowledgeproblemAction()
{ {
@ -714,7 +686,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command removeacknowledgement * Handle command removeacknowledgement
*
*/ */
public function removeacknowledgementAction() public function removeacknowledgementAction()
{ {
@ -732,7 +703,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command delaynotification * Handle command delaynotification
*
*/ */
public function delaynotificationAction() public function delaynotificationAction()
{ {
@ -749,7 +719,6 @@ class Monitoring_CommandController extends ModuleActionController
/** /**
* Handle command removedowntime * Handle command removedowntime
*
*/ */
public function removedowntimeAction() public function removedowntimeAction()
{ {

View File

@ -124,6 +124,8 @@ class SubmitPassiveCheckResultForm extends CommandForm
*/ */
protected function create() protected function create()
{ {
$this->setName('form_submit_passive_checkresult');
$this->addNote( $this->addNote(
t( t(
'This command is used to submit a passive check result for particular hosts/services. It is ' 'This command is used to submit a passive check result for particular hosts/services. It is '

View File

@ -127,7 +127,7 @@ class Backend
if ($name === null) { if ($name === null) {
$name = self::getDefaultName(); $name = self::getDefaultName();
} else { } else {
if (! self::exists($name)) { if (!self::exists($name)) {
throw new Exception( throw new Exception(
sprintf( sprintf(
'There is no such backend: "%s"', 'There is no such backend: "%s"',

View File

@ -0,0 +1,125 @@
/**
* SubmitPassiveCheckResult is always type service
*
* As a user I want to be able to choose between host
* check results when no services are passed in.
*
* This test performs the following steps
*
* - Login using the provided credentials
* - Open the form to submit passive check results
* - Check whether it is possible to choose between result types for hosts,
* if no services are given
* - Check whether it is possible to choose between result types for services
**/
/**
* The icinga util object
*
* @type object
*/
var icinga = require('./icingawebtest');
/**
* The casperjs object
*
* @type Casper
*/
var casper = icinga.getTestEnv();
/**
* Login to the instance
*/
icinga.performLogin();
/**
* Open the command dialog with only a host pattern and ensure that the form exists
*/
casper.thenOpen('/monitoring/command/submitpassivecheckresult?host=*', function() {
this.test.assertExists(
'#form_submit_passive_checkresult',
'Test whether the form to submit passive checkresults is available'
);
this.test.assertExists(
'#form_submit_passive_checkresult select#pluginstate',
'Ensure that the result type input exists'
);
});
/**
* Check whether the input contains the checkresult types for hosts
*/
casper.then(function() {
var options = this.evaluate(function() {
var elements = document.querySelector(
'#form_submit_passive_checkresult select#pluginstate'
).options;
var options = [];
for (var i = 0; i < elements.length; i++)
options.push(elements[i].text);
return options;
});
if (options.indexOf('UP') == -1)
{
this.test.fail('UP not available as checkresult type for hosts');
}
else if (options.indexOf('DOWN') == -1)
{
this.test.fail('DOWN not available as checkresult type for hosts');
}
else if (options.indexOf('UNREACHABLE') == -1)
{
this.test.fail('UNREACHABLE not available as checkresult type for hosts');
}
else
{
this.test.pass('Found all checkresult types for hosts');
}
});
/**
* Open the command dialog with a host and a service pattern as well and
* check whether the input contains the checkresult types for services
*/
casper.thenOpen('/monitoring/command/submitpassivecheckresult?host=*&service=*', function() {
var options = this.evaluate(function() {
var elements = document.querySelector(
'#form_submit_passive_checkresult select#pluginstate'
).options;
var options = [];
for (var i = 0; i < elements.length; i++)
options.push(elements[i].text);
return options;
});
if (options.indexOf('OK') == -1)
{
this.test.fail('OK not available as checkresult type for services');
}
else if (options.indexOf('WARNING') == -1)
{
this.test.fail('WARNING not available as checkresult type for services');
}
else if (options.indexOf('CRITICAL') == -1)
{
this.test.fail('CRITICAL not available as checkresult type for services');
}
else if (options.indexOf('UNKNOWN') == -1)
{
this.test.fail('UNKNOWN not available as checkresult type for services');
}
else
{
this.test.pass('Found all checkresult types for services');
}
});
/**
* Run the tests
*/
casper.run(function() {
this.test.done();
});