Call commandhandler from commandcontroller actions
The CommandController now implements the calls to the specific command methods and sends commands to the icinga process refs #4441
This commit is contained in:
parent
2091f63c3b
commit
b44de95caa
|
@ -46,25 +46,46 @@ class CommandPipe
|
|||
private $transport = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* Constant identifying a monitoring object as host
|
||||
*/
|
||||
const TYPE_HOST = "HOST";
|
||||
|
||||
/**
|
||||
*
|
||||
* Constant identifying a monitoring object as service
|
||||
*/
|
||||
const TYPE_SERVICE = "SVC";
|
||||
|
||||
/**
|
||||
*
|
||||
* Constant identifying a monitoring object as hostgroup
|
||||
*/
|
||||
const TYPE_HOSTGROUP = "HOSTGROUP";
|
||||
|
||||
/**
|
||||
*
|
||||
* Constant identifying a monitoring object as servicegroups
|
||||
*/
|
||||
const TYPE_SERVICEGROUP = "SERVICEGROUP";
|
||||
|
||||
/**
|
||||
* Notification option (use logical OR for combination)
|
||||
*
|
||||
* Broadcast (send notification to all normal and all escalated contacts for the service)
|
||||
*/
|
||||
const NOTIFY_BROADCAST = 1;
|
||||
|
||||
/**
|
||||
* Notification option (use logical OR for combination)
|
||||
*
|
||||
* notification is sent out regardless of current time, whether or not notifications are enabled, etc.
|
||||
*/
|
||||
const NOTIFY_FORCED = 2;
|
||||
|
||||
/**
|
||||
* Notification option (use logical OR for combination)
|
||||
*
|
||||
* Increment current notification # for the service(this is not done by default for custom notifications)
|
||||
*/
|
||||
const NOTIFY_INCREMENT = 4;
|
||||
|
||||
/**
|
||||
* @param \Zend_Config $config
|
||||
*/
|
||||
|
@ -565,6 +586,91 @@ class CommandPipe
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a custom host or service notification
|
||||
*
|
||||
* @param $objects monitoring objects to send this notification to
|
||||
* @param Comment $comment comment to use in the notification
|
||||
* @param int [$...] Optional list of Notification flags which will be used as the option parameter
|
||||
*/
|
||||
public function sendCustomNotification($objects, Comment $comment, $optionsVarList = 0/*, ...*/)
|
||||
{
|
||||
$args = func_get_args();
|
||||
// logical OR for all notification options
|
||||
for ($i = 3; $i < count($args); $i++) {
|
||||
$optionsVarList |= $args[$i];
|
||||
}
|
||||
|
||||
foreach ($objects as $object) {
|
||||
$type = $this->getObjectType($object);
|
||||
$msg = 'SEND_CUSTOM_'.(($type == self::TYPE_SERVICE) ? 'SVC' : 'HOST' ).'_NOTIFICATION';
|
||||
$msg .= ';'.$object->host_name;
|
||||
if ($type == self::TYPE_SERVICE) {
|
||||
$msg .= ';'.$object->service_description;
|
||||
}
|
||||
$msg .= ';'.$optionsVarList;
|
||||
$msg .= ';'.$comment->author;
|
||||
$msg .= ';'.$comment->comment;
|
||||
$this->send($msg);
|
||||
}
|
||||
}
|
||||
|
||||
public function disableNotificationsForServices($objects)
|
||||
{
|
||||
foreach ($objects as $host) {
|
||||
$msg = 'DISABLE_HOST_SVC_NOTIFICATIONS;'.$host->host_name;
|
||||
$this->send($msg);
|
||||
}
|
||||
}
|
||||
|
||||
public function enableNotificationsForServices($objects)
|
||||
{
|
||||
foreach ($objects as $host) {
|
||||
$msg = 'ENABLE_HOST_SVC_NOTIFICATIONS;'.$host->host_name;
|
||||
$this->send($msg);
|
||||
}
|
||||
}
|
||||
|
||||
public function disableActiveChecksWithChildren($objects)
|
||||
{
|
||||
foreach ($objects as $host) {
|
||||
$msg = 'DISABLE_HOST_SVC_CHECKS;'.$host->host_name;
|
||||
$this->send($msg);
|
||||
}
|
||||
}
|
||||
|
||||
public function enableActiveChecksWithChildren($objects)
|
||||
{
|
||||
foreach ($objects as $host) {
|
||||
$msg = 'ENABLE_HOST_SVC_CHECKS;'.$host->host_name;
|
||||
$this->send($msg);
|
||||
}
|
||||
}
|
||||
|
||||
public function resetAttributes($objects)
|
||||
{
|
||||
foreach ($objects as $object) {
|
||||
$type = $this->getObjectType($object);
|
||||
if ($type === self::TYPE_SERVICE) {
|
||||
$this->send('CHANGE_SVC_MODATTR;'.$object->host_name.';'.$object->service_description.';0');
|
||||
} else {
|
||||
$this->send('CHANGE_HOST_MODATTR;'.$object->host_name.';0');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function delayNotification($objects, $time)
|
||||
{
|
||||
foreach ($objects as $object) {
|
||||
$type = $this->getObjectType($object);
|
||||
if ($type === self::TYPE_SERVICE) {
|
||||
$this->send('DELAY_SVC_NOTIFICATION;'.$object->host_name.';'.$object->service_description.';'.$time);
|
||||
} else {
|
||||
$this->send('DELAY_HOST_NOTIFICATION;'.$object->host_name.';'.$time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the transport handler that handles actual sending of commands
|
||||
*
|
||||
|
|
|
@ -34,6 +34,9 @@ namespace Icinga\Protocol\Commandpipe;
|
|||
*/
|
||||
class Downtime
|
||||
{
|
||||
const TYPE_WITH_CHILDREN = 'AND_PROPAGATE_';
|
||||
const TYPE_WITH_CHILDREN_TRIGERRED = 'AND_PROPAGATE_TRIGGERED_';
|
||||
const TYPE_HOST_SVC = 'HOST_SVC';
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
|
@ -59,21 +62,29 @@ class Downtime
|
|||
*/
|
||||
public $comment;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $trigger_id = 0;
|
||||
|
||||
private $subtype = '';
|
||||
|
||||
/**
|
||||
* @param $start
|
||||
* @param $end
|
||||
* @param Comment $comment
|
||||
* @param int $duration
|
||||
*/
|
||||
public function __construct($start, $end, Comment $comment, $duration = 0)
|
||||
public function __construct($start, $end, Comment $comment, $duration = 0, $trigger_id = 0)
|
||||
{
|
||||
$this->startTime = $start;
|
||||
$this->endTime = $end;
|
||||
$this->comment = $comment;
|
||||
if ($duration != 0) {
|
||||
if ($duration == 0) {
|
||||
$this->fixed = true;
|
||||
}
|
||||
$this->duration = intval($duration);
|
||||
$this->trigger_id = intval($trigger_id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,10 +93,26 @@ class Downtime
|
|||
*/
|
||||
public function getFormatString($type)
|
||||
{
|
||||
return 'SCHEDULE_' . $type . '_DOWNTIME;%s'
|
||||
. ($type == CommandPipe::TYPE_SERVICE ? ';%s;' : ';')
|
||||
. $this->startTime . ';' . $this->endTime
|
||||
. ';' . ($this->fixed ? '1' : '0') . ';' . $this->duration . ';0;'
|
||||
. $this->comment->author . ';' . $this->comment->comment;
|
||||
if ($this->subtype == self::TYPE_HOST_SVC) {
|
||||
$type = "";
|
||||
}
|
||||
return 'SCHEDULE_'
|
||||
. $this->subtype
|
||||
. $type
|
||||
. '_DOWNTIME;'
|
||||
. '%s;'
|
||||
. ($type == CommandPipe::TYPE_SERVICE ? '%s;' : '')
|
||||
. $this->startTime . ';'
|
||||
. $this->endTime . ';'
|
||||
. ($this->fixed ? '1' : '0') . ';'
|
||||
. $this->trigger_id . ';'
|
||||
. $this->duration . ';'
|
||||
. $this->comment->author . ';'
|
||||
. $this->comment->comment;
|
||||
}
|
||||
|
||||
public function setType($type)
|
||||
{
|
||||
$this->subtype = $type;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,7 +89,6 @@ 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
|
||||
);
|
||||
|
||||
|
|
|
@ -115,10 +115,7 @@ 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()) {
|
||||
|
||||
|
@ -144,6 +141,9 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
}
|
||||
|
||||
if ($this->getRequest()->getActionName() !== 'list') {
|
||||
|
||||
|
||||
|
||||
// Reduce template writing mess
|
||||
$this->_helper->viewRenderer->setRender(self::DEFAULT_VIEW_SCRIPT);
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
* @return array
|
||||
* @throws Icinga\Exception\MissingParameterException
|
||||
*/
|
||||
private function selectCommandTargets()
|
||||
private function selectCommandTargets($hostOnly = false)
|
||||
{
|
||||
$query = null;
|
||||
$fields = array(
|
||||
|
@ -178,7 +178,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
if ($hostname) {
|
||||
$filter["host_name"] = $hostname;
|
||||
}
|
||||
if ($servicename) {
|
||||
if ($servicename && !$hostOnly) {
|
||||
$filter["service_description"] = $servicename;
|
||||
$fields[] = "service_description";
|
||||
$fields[] = "service_state";
|
||||
|
@ -212,6 +212,30 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
$this->view->commands = $commands;
|
||||
}
|
||||
|
||||
private function supportedParameter(array $supported)
|
||||
{
|
||||
$given = array_intersect_key(array_flip($supported), $this->getRequest()->getParams());
|
||||
if (empty($given)) {
|
||||
throw new \Exception('Missing parameter, supported: '.implode(', ', $supported));
|
||||
}
|
||||
if (isset($given["host"])) {
|
||||
$this->objects = $this->selectCommandTargets(!in_array("service", $supported));
|
||||
if (empty($this->objects)) {
|
||||
throw new \Exception("No objects found for your command");
|
||||
}
|
||||
|
||||
} else if (in_array("downtimeid", $supported)) {
|
||||
$this->objects = array();
|
||||
$downtimes = $this->getParam("downtimeid");
|
||||
if (!is_array($downtimes)) {
|
||||
$downtimes = array($downtimes);
|
||||
}
|
||||
foreach ($downtimes as $downtimeId) {
|
||||
$this->objects[] = (object) array("downtime_id" => $downtimeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Commands for hosts / services
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -222,7 +246,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function disableactivechecksAction()
|
||||
{
|
||||
|
||||
$this->supportedParameter(array('host', 'service'));
|
||||
$form = new ConfirmationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setSubmitLabel(t('Disable active checks'));
|
||||
|
@ -240,6 +264,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function enableactivechecksAction()
|
||||
{
|
||||
$this->supportedParameter(array('host', 'service'));
|
||||
$form = new ConfirmationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setSubmitLabel(t('Enable active checks'));
|
||||
|
@ -257,6 +282,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function reschedulenextcheckAction()
|
||||
{
|
||||
$this->supportedParameter(array('host', 'service'));
|
||||
$form = new RescheduleNextCheckForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
|
||||
|
@ -273,6 +299,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function submitpassivecheckresultAction()
|
||||
{
|
||||
$this->supportedParameter(array('host', 'service'));
|
||||
$type = SubmitPassiveCheckResultForm::TYPE_SERVICE;
|
||||
|
||||
$form = new SubmitPassiveCheckResultForm();
|
||||
|
@ -292,6 +319,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function stopobsessingAction()
|
||||
{
|
||||
$this->supportedParameter(array('host', 'service'));
|
||||
$form = new ConfirmationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setSubmitLabel(t('Stop obsessing'));
|
||||
|
@ -309,6 +337,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function startobsessingAction()
|
||||
{
|
||||
$this->supportedParameter(array('host', 'service'));
|
||||
$form = new ConfirmationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setSubmitLabel(t('Start obsessing'));
|
||||
|
@ -326,6 +355,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function stopacceptingpassivechecksAction()
|
||||
{
|
||||
$this->supportedParameter(array('host', 'service'));
|
||||
$form = new ConfirmationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setSubmitLabel(t('Stop accepting passive checks'));
|
||||
|
@ -333,7 +363,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->disablePassiveChecks($this->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -343,6 +373,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function startacceptingpassivechecksAction()
|
||||
{
|
||||
$this->supportedParameter(array('host', 'service'));
|
||||
$form = new ConfirmationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setSubmitLabel(t('Start accepting passive checks'));
|
||||
|
@ -350,7 +381,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -360,6 +391,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function disablenotificationsAction()
|
||||
{
|
||||
$this->supportedParameter(array('host', 'service'));
|
||||
$form = new ConfirmationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setSubmitLabel(t('Disable notifications'));
|
||||
|
@ -367,7 +399,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->disableNotifications($this->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -384,7 +416,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->enableNotifications($this->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -394,12 +426,18 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function sendcustomnotificationAction()
|
||||
{
|
||||
$this->supportedParameter(array('host', 'service'));
|
||||
$form = new CustomNotificationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$this->setForm($form);
|
||||
|
||||
if ($form->isPostAndValid() === true) {
|
||||
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
|
||||
$author = $this->getRequest()->getUser()->getUsername();
|
||||
$this->target->sendCustomNotification(
|
||||
$this->objects,
|
||||
new Comment($author, $form->getComment()),
|
||||
$form->getOptions()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -409,13 +447,14 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function scheduledowntimeAction()
|
||||
{
|
||||
$this->supportedParameter(array('host', 'service'));
|
||||
$form = new ScheduleDowntimeForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setWithChildren(false);
|
||||
$this->setForm($form);
|
||||
|
||||
if ($form->isPostAndValid() === true) {
|
||||
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
|
||||
$this->target->scheduleDowntime($this->objects, $form->getDowntime());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -425,13 +464,14 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function scheduledowntimeswithchildrenAction()
|
||||
{
|
||||
$this->supportedParameter(array('host'));
|
||||
$form = new ScheduleDowntimeForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setWithChildren(true);
|
||||
$this->setForm($form);
|
||||
|
||||
if ($form->isPostAndValid() === true) {
|
||||
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
|
||||
$this->target->scheduleDowntime($this->objects, $form->getDowntime());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -441,6 +481,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function removedowntimeswithchildrenAction()
|
||||
{
|
||||
$this->supportedParameter(array('host'));
|
||||
$form = new ConfirmationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setSubmitLabel(t('Remove downtime(s)'));
|
||||
|
@ -448,7 +489,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->removeDowntime($this->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -458,6 +499,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function disablenotificationswithchildrenAction()
|
||||
{
|
||||
$this->supportedParameter(array('host'));
|
||||
$form = new ConfirmationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setSubmitLabel(t('Disable notifications'));
|
||||
|
@ -465,7 +507,8 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
$this->setForm($form);
|
||||
|
||||
if ($form->isPostAndValid() === true) {
|
||||
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
|
||||
$this->target->disableNotifications($this->objects);
|
||||
$this->target->disableNotificationsForServices($this->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -475,6 +518,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function enablenotificationswithchildrenAction()
|
||||
{
|
||||
$this->supportedParameter(array('host'));
|
||||
$form = new ConfirmationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setSubmitLabel(t('Enable notifications'));
|
||||
|
@ -482,7 +526,8 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
$this->setForm($form);
|
||||
|
||||
if ($form->isPostAndValid() === true) {
|
||||
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
|
||||
$this->target->enableNotifications($this->objects);
|
||||
$this->target->enableNotificationsForServices($this->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -492,6 +537,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function reschedulenextcheckwithchildrenAction()
|
||||
{
|
||||
$this->supportedParameter(array('host'));
|
||||
$form = new RescheduleNextCheckForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
|
||||
|
@ -500,7 +546,13 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
$this->setForm($form);
|
||||
|
||||
if ($form->isPostAndValid() === true) {
|
||||
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
|
||||
if ($form->isForced()) {
|
||||
$this->target->scheduleForcedCheck($this->objects, time());
|
||||
$this->target->scheduleForcedCheck($this->objects, time(), true);
|
||||
} else {
|
||||
$this->target->scheduleCheck($this->objects, time());
|
||||
$this->target->scheduleCheck($this->objects, time(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -510,6 +562,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function disableactivecheckswithchildrenAction()
|
||||
{
|
||||
$this->supportedParameter(array('host'));
|
||||
$form = new ConfirmationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setSubmitLabel(t('Disable active checks'));
|
||||
|
@ -517,7 +570,8 @@ 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);
|
||||
$this->target->disableActiveChecksWithChildren($this->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -527,6 +581,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function enableactivecheckswithchildrenAction()
|
||||
{
|
||||
$this->supportedParameter(array('host'));
|
||||
$form = new ConfirmationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setSubmitLabel(t('Enable active checks'));
|
||||
|
@ -534,7 +589,8 @@ 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);
|
||||
$this->target->enableActiveChecksWithChildren($this->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -544,6 +600,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function disableeventhandlerAction()
|
||||
{
|
||||
$this->supportedParameter(array('host', 'service'));
|
||||
$form = new ConfirmationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setSubmitLabel(t('Disable event handler'));
|
||||
|
@ -551,7 +608,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->disableEventHandler($this->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -561,6 +618,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function enableeventhandlerAction()
|
||||
{
|
||||
$this->supportedParameter(array('host', 'service'));
|
||||
$form = new ConfirmationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setSubmitLabel(t('Enable event handler'));
|
||||
|
@ -568,7 +626,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->enableEventHandler($this->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -578,6 +636,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function disableflapdetectionAction()
|
||||
{
|
||||
$this->supportedParameter(array('host', 'service'));
|
||||
$form = new ConfirmationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setSubmitLabel(t('Disable flapping detection'));
|
||||
|
@ -585,7 +644,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->disableFlappingDetection($this->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -595,6 +654,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function enableflapdetectionAction()
|
||||
{
|
||||
$this->supportedParameter(array('host', 'service'));
|
||||
$form = new ConfirmationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setSubmitLabel(t('Enable flapping detection'));
|
||||
|
@ -602,7 +662,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->enableFlappingDetection($this->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -612,13 +672,14 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function addcommentAction()
|
||||
{
|
||||
$this->supportedParameter(array('host', 'service'));
|
||||
$form = new CommentForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
|
||||
$this->setForm($form);
|
||||
|
||||
if ($form->isPostAndValid() === true) {
|
||||
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
|
||||
$this->target->addComment($this->objects, $form->getComment());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -628,6 +689,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function resetattributesAction()
|
||||
{
|
||||
$this->supportedParameter(array('host', 'service'));
|
||||
$form = new ConfirmationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setSubmitLabel(t('Reset attributes'));
|
||||
|
@ -635,7 +697,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->resetAttributes($this->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -645,13 +707,14 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function acknowledgeproblemAction()
|
||||
{
|
||||
$this->supportedParameter(array('host', 'service'));
|
||||
$form = new AcknowledgeForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
|
||||
$this->setForm($form);
|
||||
|
||||
if ($form->isPostAndValid() === true) {
|
||||
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
|
||||
$this->target->acknowledge($this->objects, $form->getAcknowledgement());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -661,6 +724,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function removeacknowledgementAction()
|
||||
{
|
||||
$this->supportedParameter(array('host', 'service'));
|
||||
$form = new ConfirmationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setSubmitLabel(t('Remove problem acknowledgement'));
|
||||
|
@ -668,7 +732,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->removeAcknowledge($this->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -678,13 +742,14 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function delaynotificationAction()
|
||||
{
|
||||
$this->supportedParameter(array('host', 'service'));
|
||||
$form = new DelayNotificationForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
|
||||
$this->setForm($form);
|
||||
|
||||
if ($form->isPostAndValid() === true) {
|
||||
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
|
||||
$this->target->delayNotification($this->objects, $form->getDelayTime());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -694,6 +759,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
*/
|
||||
public function removedowntimeAction()
|
||||
{
|
||||
$this->supportedParameter(array('downtimeid'));
|
||||
$form = new ConfirmationWithIdentifierForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
|
||||
|
@ -705,7 +771,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->removeDowntime($this->objects);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,8 @@ use Icinga\Web\Form\Element\DateTime;
|
|||
use \DateTime as PhpDateTime;
|
||||
use \DateInterval;
|
||||
use Icinga\Web\Form\Element\Note;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Acknowledgement;
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
/**
|
||||
* Form for acknowledge commands
|
||||
*/
|
||||
|
@ -142,4 +143,24 @@ class AcknowledgeForm extends ConfirmationForm
|
|||
$expireTime->addValidator($this->createDateTimeValidator(), true);
|
||||
}
|
||||
}
|
||||
|
||||
public function getAcknowledgement()
|
||||
{
|
||||
$expireTime = -1;
|
||||
if ($this->getValue('expire')) {
|
||||
$time = new PhpDateTime($this->getValue('expiretime'));
|
||||
$expireTime = $time->getTimestamp();
|
||||
}
|
||||
return new Acknowledgement(
|
||||
new Comment(
|
||||
$this->getAuthorName(),
|
||||
$this->getValue('comment'),
|
||||
$this->getValue('persistent')
|
||||
),
|
||||
$this->getValue('notify'),
|
||||
$expireTime,
|
||||
$this->getValue('sticky')
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
namespace Monitoring\Form\Command;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
/**
|
||||
* Form for adding comment commands
|
||||
*/
|
||||
|
@ -64,4 +65,9 @@ class CommentForm extends ConfirmationForm
|
|||
|
||||
parent::create();
|
||||
}
|
||||
|
||||
public function getComment()
|
||||
{
|
||||
return new Comment($this->getAuthorName(), $this->getValue('comment'), $this->getValue('persistent'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,4 +73,21 @@ class CustomNotificationForm extends ConfirmationForm
|
|||
|
||||
parent::create();
|
||||
}
|
||||
|
||||
public function getComment()
|
||||
{
|
||||
return $this->getValue('comment');
|
||||
}
|
||||
|
||||
public function getOptions()
|
||||
{
|
||||
$value = 0;
|
||||
if ($this->getValue('force')) {
|
||||
$value |= 2;
|
||||
}
|
||||
if ($this->getValue('broadcast')) {
|
||||
$value |= 1;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,4 +70,9 @@ class DelayNotificationForm extends ConfirmationForm
|
|||
|
||||
parent::create();
|
||||
}
|
||||
|
||||
public function getDelayTime()
|
||||
{
|
||||
return $this->getValue('minutes')*60;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,4 +79,9 @@ class RescheduleNextCheckForm extends WithChildrenCommandForm
|
|||
|
||||
parent::create();
|
||||
}
|
||||
|
||||
public function isForced()
|
||||
{
|
||||
return $this->getValue('forcecheck') == true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
namespace Monitoring\Form\Command;
|
||||
|
||||
use Icinga\Web\Form\Element\DateTime;
|
||||
use Icinga\Protocol\Commandpipe\Downtime;
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
use \DateTime as PhpDateTime;
|
||||
use \DateInterval;
|
||||
use \Zend_Form_Element_Text;
|
||||
|
@ -58,6 +60,7 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
|
||||
/**
|
||||
* Build an array of timestamps
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
private function generateDefaultTimestamps()
|
||||
|
@ -76,6 +79,7 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
|
||||
/**
|
||||
* Generate translated multi options based on type constants
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getDowntimeTypeOptions()
|
||||
|
@ -88,6 +92,7 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
|
||||
/**
|
||||
* Interface method to build the form
|
||||
*
|
||||
* @see ConfirmationForm::create
|
||||
*/
|
||||
protected function create()
|
||||
|
@ -104,6 +109,10 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* @TODO: Display downtime list (Bug #4496)
|
||||
*
|
||||
*/
|
||||
$this->addElement(
|
||||
'text',
|
||||
'triggered',
|
||||
|
@ -242,6 +251,7 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
|
||||
/**
|
||||
* Change validators at runtime
|
||||
*
|
||||
* @see Form::preValidation
|
||||
* @param array $data
|
||||
*/
|
||||
|
@ -265,4 +275,45 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
$minutes->addValidator($greaterThanValidator, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the downtime submitted in this form
|
||||
*
|
||||
* @return Downtime
|
||||
*/
|
||||
public function getDowntime()
|
||||
{
|
||||
|
||||
$comment = new Comment(
|
||||
$this->getRequest()->getUser()->getUsername(),
|
||||
$this->getValue('comment')
|
||||
);
|
||||
$duration = 0;
|
||||
if ($this->getValue('type') === self::TYPE_FLEXIBLE) {
|
||||
$duration = ($this->getValue('hours')*3600) + ($this->getValue('minutes')*60);
|
||||
}
|
||||
$starttime = new PhpDateTime($this->getValue('starttime'));
|
||||
$endtime = new PhpDateTime($this->getValue('endtime'));
|
||||
|
||||
$downtime = new Downtime(
|
||||
$starttime->getTimestamp(),
|
||||
$endtime->getTimestamp(),
|
||||
$comment,
|
||||
$duration,
|
||||
$this->getValue('triggered')
|
||||
);
|
||||
if (! $this->getWithChildren()) {
|
||||
switch ($this->getValue('childobjects')) {
|
||||
case 1:
|
||||
$downtime->setType(Downtime::TYPE_WITH_CHILDREN_TRIGERRED);
|
||||
break;
|
||||
case 2:
|
||||
$downtime->setType(Downtime::TYPE_WITH_CHILDREN);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$downtime->setType(Downtime::TYPE_HOST_SVC);
|
||||
}
|
||||
return $downtime;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ use Icinga\Protocol\Commandpipe\Acknowledgement as Acknowledgement;
|
|||
use Icinga\Protocol\Commandpipe\Downtime as Downtime;
|
||||
use Icinga\Protocol\Commandpipe\Commandpipe as Commandpipe;
|
||||
use \Icinga\Protocol\Commandpipe\PropertyModifier as MONFLAG;
|
||||
use Icinga\Protocol\Ldap\Exception;
|
||||
|
||||
if(!defined("EXTCMD_TEST_BIN"))
|
||||
define("EXTCMD_TEST_BIN", "./bin/extcmd_test");
|
||||
|
@ -413,6 +414,58 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
$this->cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether custom servicenotifications are correctly send to the commandpipe without options
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testSendCustomServiceNotification()
|
||||
{
|
||||
$pipe = $this->getLocalTestPipe();
|
||||
try {
|
||||
$comment = new Comment("author", "commenttext");
|
||||
$pipe->sendCustomNotification(array(
|
||||
(object) array(
|
||||
"host_name" => "host1",
|
||||
"service_description" => "service1"
|
||||
)
|
||||
), $comment);
|
||||
$this->assertCommandSucceeded(
|
||||
"SEND_CUSTOM_SVC_NOTIFICATION;host1;service1;0;author;commenttext"
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
}
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether custom hostnotifications are correctly send to the commandpipe with a varlist of options
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testSendCustomHostNotificationWithOptions()
|
||||
{
|
||||
$pipe = $this->getLocalTestPipe();
|
||||
try {
|
||||
$comment = new Comment('author', 'commenttext');
|
||||
$pipe->sendCustomNotification(array(
|
||||
(object) array(
|
||||
'host_name' => 'host'
|
||||
)
|
||||
), $comment, Commandpipe::NOTIFY_FORCED, Commandpipe::NOTIFY_BROADCAST, Commandpipe::NOTIFY_INCREMENT);
|
||||
|
||||
$this->assertCommandSucceeded(
|
||||
'SEND_CUSTOM_HOST_NOTIFICATION;host;7;author;commenttext'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
}
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test sending of commands via SSH (currently disabled)
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue