parent
d6bbed3a54
commit
2091f63c3b
|
@ -136,11 +136,14 @@ class CommandPipe
|
|||
* @param $state
|
||||
* @param $output
|
||||
*/
|
||||
public function submitCheckResult($objects, $state, $output)
|
||||
public function submitCheckResult($objects, $state, $output, $perfdata = "")
|
||||
{
|
||||
if ($perfdata) {
|
||||
$output = $output."|".$perfdata;
|
||||
}
|
||||
foreach ($objects as $object) {
|
||||
if (isset($object->service_description)) {
|
||||
$this->send("PROCESS_SVC_CHECK_RESULT;$object->host_name;$object->service_description;$state;$output");
|
||||
$this->send("PROCESS_SERVICE_CHECK_RESULT;$object->host_name;$object->service_description;$state;$output");
|
||||
} else {
|
||||
$this->send("PROCESS_HOST_CHECK_RESULT;$object->host_name;$state;$output");
|
||||
}
|
||||
|
@ -349,7 +352,7 @@ class CommandPipe
|
|||
*/
|
||||
public function disableActiveChecks($objects)
|
||||
{
|
||||
$this->modifyMonitoringProperties(
|
||||
$this->setMonitoringProperties(
|
||||
$objects,
|
||||
new PropertyModifier(
|
||||
array(
|
||||
|
@ -379,7 +382,7 @@ class CommandPipe
|
|||
*/
|
||||
public function disablePassiveChecks($objects)
|
||||
{
|
||||
$this->modifyMonitoringProperties(
|
||||
$this->setMonitoringProperties(
|
||||
$objects,
|
||||
new PropertyModifier(
|
||||
array(
|
||||
|
@ -536,6 +539,32 @@ class CommandPipe
|
|||
);
|
||||
}
|
||||
|
||||
public function startObsessing($objects)
|
||||
{
|
||||
foreach ($objects as $object) {
|
||||
$type = $this->getObjectType($object);
|
||||
$msg = "START_OBSESSING_OVER_". (($type == self::TYPE_SERVICE) ? 'SVC' : 'HOST');
|
||||
$msg .= ';'.$object->host_name;
|
||||
if ($type == self::TYPE_SERVICE) {
|
||||
$msg .= ';'.$object->service_description;
|
||||
}
|
||||
$this->send($msg);
|
||||
}
|
||||
}
|
||||
|
||||
public function stopObsessing($objects)
|
||||
{
|
||||
foreach ($objects as $object) {
|
||||
$type = $this->getObjectType($object);
|
||||
$msg = "STOP_OBSESSING_OVER_". (($type == self::TYPE_SERVICE) ? 'SVC' : 'HOST');
|
||||
$msg .= ';'.$object->host_name;
|
||||
if ($type == self::TYPE_SERVICE) {
|
||||
$msg .= ';'.$object->service_description;
|
||||
}
|
||||
$this->send($msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the transport handler that handles actual sending of commands
|
||||
*
|
||||
|
|
|
@ -74,6 +74,7 @@ class PropertyModifier
|
|||
*/
|
||||
const FRESHNESS = "%s_FRESHNESS_CHECKS";
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -88,6 +89,7 @@ class PropertyModifier
|
|||
self::PASSIVE => self::STATE_KEEP,
|
||||
self::NOTIFICATIONS => self::STATE_KEEP,
|
||||
self::FRESHNESS => self::STATE_KEEP,
|
||||
self::OBSESSING => self::STATE_KEEP,
|
||||
self::EVENTHANDLER => self::STATE_KEEP
|
||||
);
|
||||
|
||||
|
|
|
@ -29,8 +29,10 @@
|
|||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
use Icinga\Application\Benchmark;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Backend;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Authentication\Manager;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Web\ModuleActionController;
|
||||
|
@ -113,6 +115,11 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->objects = $this->selectCommandTargets();
|
||||
if (empty($this->objects) && ! $this->isGlobalCommand()) {
|
||||
throw new \Exception("No objects found for your command");
|
||||
}
|
||||
|
||||
if ($this->_request->isPost()) {
|
||||
|
||||
$instance = $this->_request->getPost("instance");
|
||||
|
@ -142,6 +149,11 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
}
|
||||
}
|
||||
|
||||
private function isGlobalCommand()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all existing targets for host- and service combination
|
||||
* @param string $hostname
|
||||
|
@ -149,21 +161,38 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
* @return array
|
||||
* @throws Icinga\Exception\MissingParameterException
|
||||
*/
|
||||
private function selectCommandTargets($hostname, $servicename = null)
|
||||
private function selectCommandTargets()
|
||||
{
|
||||
$target = "hostlist";
|
||||
$filter = array();
|
||||
if (!$hostname && !$servicename) {
|
||||
throw new MissingParameterException("Missing host and service definition");
|
||||
$query = null;
|
||||
$fields = array(
|
||||
'host_name',
|
||||
'host_state'
|
||||
);
|
||||
try {
|
||||
$hostname = $this->getParam('host', null);
|
||||
$servicename = $this->getParam('service', null);
|
||||
$filter = array();
|
||||
if (!$hostname && !$servicename) {
|
||||
throw new MissingParameterException("No target given for this command");
|
||||
}
|
||||
if ($hostname) {
|
||||
$filter["host_name"] = $hostname;
|
||||
}
|
||||
if ($servicename) {
|
||||
$filter["service_description"] = $servicename;
|
||||
$fields[] = "service_description";
|
||||
$fields[] = "service_state";
|
||||
}
|
||||
;
|
||||
$query = Backend::getInstance()->select()->from("status", $fields);
|
||||
return $query->applyFilters($filter)->fetchAll();
|
||||
} catch (\Exception $e) {
|
||||
Logger::error(
|
||||
"CommandController: SQL Query '%s' failed (message %s) ",
|
||||
$query ? (string) $query->getQuery()->dump() : '--', $e->getMessage()
|
||||
);
|
||||
return array();
|
||||
}
|
||||
if ($hostname) {
|
||||
$filter["host_name"] = $hostname;
|
||||
}
|
||||
if ($servicename) {
|
||||
$filter["service_description"] = $servicename;
|
||||
$target = "servicelist";
|
||||
}
|
||||
return Backend::getInstance()->select()->from($target)->applyFilters($filter)->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -193,6 +222,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function disableactivechecksAction()
|
||||
{
|
||||
|
||||
$form = new ConfirmationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setSubmitLabel(t('Disable active checks'));
|
||||
|
@ -200,7 +230,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
$this->setForm($form);
|
||||
|
||||
if ($form->isPostAndValid() === true) {
|
||||
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
|
||||
$this->target->disableActiveChecks($this->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -217,7 +247,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
$this->setForm($form);
|
||||
|
||||
if ($form->isPostAndValid() === true) {
|
||||
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
|
||||
$this->target->enableActiveChecks($this->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,7 +263,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
$this->setForm($form);
|
||||
|
||||
if ($form->isPostAndValid() === true) {
|
||||
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
|
||||
$this->target->scheduleCheck($this->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -252,7 +282,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
$this->setForm($form);
|
||||
|
||||
if ($form->isPostAndValid() === true) {
|
||||
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
|
||||
$this->target->submitCheckResult($this->objects, $form->getState(), $form->getOutput(), $form->getPerformancedata());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,7 +299,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
$this->setForm($form);
|
||||
|
||||
if ($form->isPostAndValid() === true) {
|
||||
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
|
||||
$this->target->stopObsessing($this->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -286,7 +316,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
$this->setForm($form);
|
||||
|
||||
if ($form->isPostAndValid() === true) {
|
||||
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
|
||||
$this->target->startObsessing($this->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,12 +68,14 @@ class ConfirmationForm extends Form
|
|||
|
||||
/**
|
||||
* Array of messages
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $notes = array();
|
||||
|
||||
/**
|
||||
* Setter for cancel label
|
||||
*
|
||||
* @param string $cancelLabel
|
||||
*/
|
||||
public function setCancelLabel($cancelLabel)
|
||||
|
@ -83,6 +85,7 @@ class ConfirmationForm extends Form
|
|||
|
||||
/**
|
||||
* Getter for cancel label
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCancelLabel()
|
||||
|
@ -92,6 +95,7 @@ class ConfirmationForm extends Form
|
|||
|
||||
/**
|
||||
* Setter for submit label
|
||||
*
|
||||
* @param string $submitLabel
|
||||
*/
|
||||
public function setSubmitLabel($submitLabel)
|
||||
|
@ -101,6 +105,7 @@ class ConfirmationForm extends Form
|
|||
|
||||
/**
|
||||
* Getter for submit label
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSubmitLabel()
|
||||
|
@ -110,6 +115,7 @@ class ConfirmationForm extends Form
|
|||
|
||||
/**
|
||||
* Add message to stack
|
||||
*
|
||||
* @param string $message
|
||||
*/
|
||||
public function addNote($message)
|
||||
|
@ -119,6 +125,7 @@ class ConfirmationForm extends Form
|
|||
|
||||
/**
|
||||
* Purge messages from stack
|
||||
*
|
||||
*/
|
||||
public function clearNotes()
|
||||
{
|
||||
|
@ -127,6 +134,7 @@ class ConfirmationForm extends Form
|
|||
|
||||
/**
|
||||
* Getter for notes
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNotes()
|
||||
|
@ -148,6 +156,7 @@ class ConfirmationForm extends Form
|
|||
|
||||
/**
|
||||
* Add elements to this form (used by extending classes)
|
||||
*
|
||||
* @see Form::create
|
||||
*/
|
||||
protected function create()
|
||||
|
@ -191,15 +200,16 @@ class ConfirmationForm extends Form
|
|||
|
||||
/**
|
||||
* Get the author name
|
||||
* TODO(mh): This should work on the request, at present it's fix
|
||||
|
||||
*/
|
||||
protected function getAuthorName()
|
||||
{
|
||||
return 'Iwan IV. Wassiljewitsch, der Schreckliche';
|
||||
return $this->getRequest()->getUser()->getUsername();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creator for author field
|
||||
*
|
||||
* @return Zend_Form_Element_Hidden
|
||||
*/
|
||||
protected function createAuthorField()
|
||||
|
|
|
@ -168,4 +168,20 @@ class SubmitPassiveCheckResultForm extends ConfirmationForm
|
|||
|
||||
parent::create();
|
||||
}
|
||||
|
||||
public function getState()
|
||||
{
|
||||
return intval($this->getValue('pluginstate'));
|
||||
}
|
||||
|
||||
public function getOutput()
|
||||
{
|
||||
return $this->getValue('checkoutput');
|
||||
}
|
||||
|
||||
public function getPerformancedata()
|
||||
{
|
||||
return $this->getValue('performancedata');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ class Zend_View_Helper_MonitoringFlags extends Zend_View_Helper_Abstract
|
|||
private static $keys = array(
|
||||
'passive_checks_enabled' => 'Passive checks',
|
||||
'active_checks_enabled' => 'Active checks',
|
||||
'obsess_over_host' => 'Obsessing',
|
||||
'obsessing' => 'Obsessing',
|
||||
'notifications_enabled' => 'Notifications',
|
||||
'event_handler_enabled' => 'Event handler',
|
||||
'flap_detection_enabled' => 'Flap detection',
|
||||
|
|
|
@ -149,7 +149,7 @@ class AbstractBackend implements DatasourceInterface
|
|||
'host_scheduled_downtime_depth',
|
||||
'host_failure_prediction_enabled',
|
||||
'host_process_performance_data',
|
||||
'host_obsess_over_host',
|
||||
'host_obsessing',
|
||||
'host_modified_host_attributes',
|
||||
'host_event_handler',
|
||||
'host_check_command',
|
||||
|
@ -230,7 +230,7 @@ class AbstractBackend implements DatasourceInterface
|
|||
'service_scheduled_downtime_depth',
|
||||
'service_failure_prediction_enabled',
|
||||
'service_process_performance_data',
|
||||
'service_obsess_over_service',
|
||||
'service_obsessing',
|
||||
'service_modified_service_attributes',
|
||||
'service_event_handler',
|
||||
'service_check_command',
|
||||
|
|
|
@ -60,7 +60,7 @@ class StatusQuery extends AbstractQuery
|
|||
'host_scheduled_downtime_depth' => 'hs.scheduled_downtime_depth',
|
||||
'host_failure_prediction_enabled' => 'hs.failure_prediction_enabled',
|
||||
'host_process_performance_data' => 'hs.process_performance_data',
|
||||
'host_obsess_over_host' => 'hs.obsess_over_host',
|
||||
'host_obsessing' => 'hs.obsess_over_host',
|
||||
'host_modified_host_attributes' => 'hs.modified_host_attributes',
|
||||
'host_event_handler' => 'hs.event_handler',
|
||||
'host_check_command' => 'hs.check_command',
|
||||
|
@ -160,7 +160,7 @@ class StatusQuery extends AbstractQuery
|
|||
'service_scheduled_downtime_depth' => 'ss.scheduled_downtime_depth',
|
||||
'service_failure_prediction_enabled' => 'ss.failure_prediction_enabled',
|
||||
'service_process_performance_data' => 'ss.process_performance_data',
|
||||
'service_obsess_over_service' => 'ss.obsess_over_service',
|
||||
'service_obsessing' => 'ss.obsess_over_service',
|
||||
'service_modified_service_attributes' => 'ss.modified_service_attributes',
|
||||
'service_event_handler' => 'ss.event_handler',
|
||||
'service_check_command' => 'ss.check_command',
|
||||
|
|
|
@ -729,8 +729,8 @@ class Meta
|
|||
} else {
|
||||
unset($commands[self::CMD_START_ACCEPTING_PASSIVE_CHECKS]);
|
||||
}
|
||||
$obsess = 'obsess_over_'.$type;
|
||||
if ($object->$obsess === '1') {
|
||||
|
||||
if ($object->obsessing === '1') {
|
||||
unset($commands[self::CMD_START_OBSESSING]);
|
||||
} else {
|
||||
unset($commands[self::CMD_STOP_OBSESSING]);
|
||||
|
|
|
@ -54,7 +54,7 @@ class HostStruct extends \stdClass
|
|||
public $host_scheduled_downtime_depth = '1';
|
||||
public $host_failure_prediction_enabled = '1';
|
||||
public $host_process_performance_data = '1';
|
||||
public $host_obsess_over_host = '1';
|
||||
public $host_obsessing = '1';
|
||||
public $host_modified_host_attributes = '14';
|
||||
public $host_event_handler = '';
|
||||
public $host_normal_check_interval = '5';
|
||||
|
|
|
@ -13,7 +13,7 @@ class MonitoringFlagsTest extends \PHPUnit_Framework_TestCase
|
|||
$testArray = array(
|
||||
'host_passive_checks_enabled' => '0',
|
||||
'host_active_checks_enabled' => '0',
|
||||
'host_obsess_over_host' => '1',
|
||||
'host_obsessing' => '1',
|
||||
'host_notifications_enabled' => '0',
|
||||
'host_event_handler_enabled' => '1',
|
||||
'host_flap_detection_enabled' => '1',
|
||||
|
@ -41,7 +41,7 @@ class MonitoringFlagsTest extends \PHPUnit_Framework_TestCase
|
|||
$testArray = array(
|
||||
'service_passive_checks_enabled' => '0',
|
||||
'service_active_checks_enabled' => '1',
|
||||
'service_obsess_over_host' => '0',
|
||||
'service_obsessing' => '0',
|
||||
'service_notifications_enabled' => '1',
|
||||
'service_event_handler_enabled' => '1',
|
||||
'service_flap_detection_enabled' => '0',
|
||||
|
@ -68,7 +68,7 @@ class MonitoringFlagsTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$testArray = array(
|
||||
'service_active_checks_enabled' => '1',
|
||||
'service_obsess_over_host' => '1',
|
||||
'service_obsessing' => '1',
|
||||
'DING DING' => '$$$',
|
||||
'DONG DONG' => '###'
|
||||
);
|
||||
|
|
|
@ -50,7 +50,7 @@ class HostStruct4Properties extends \stdClass
|
|||
public $host_scheduled_downtime_depth = '1';
|
||||
public $host_failure_prediction_enabled = '1';
|
||||
public $host_process_performance_data = '1';
|
||||
public $host_obsess_over_host = '1';
|
||||
public $host_obsessing = '1';
|
||||
public $host_modified_host_attributes = '14';
|
||||
public $host_event_handler = '';
|
||||
public $host_normal_check_interval = '5';
|
||||
|
|
|
@ -51,7 +51,7 @@ class HostStruct extends \stdClass
|
|||
public $host_scheduled_downtime_depth = '1';
|
||||
public $host_failure_prediction_enabled = '1';
|
||||
public $host_process_performance_data = '1';
|
||||
public $host_obsess_over_host = '1';
|
||||
public $host_obsessing = '1';
|
||||
public $host_modified_host_attributes = '14';
|
||||
public $host_event_handler = '';
|
||||
public $host_normal_check_interval = '5';
|
||||
|
@ -158,7 +158,7 @@ class MetaTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$object = new HostStruct();
|
||||
|
||||
$object->host_obsess_over_host = '0';
|
||||
$object->host_obsessing = '0';
|
||||
$object->host_flap_detection_enabled = '0';
|
||||
$object->host_active_checks_enabled = '0';
|
||||
|
||||
|
|
Loading…
Reference in New Issue