diff --git a/modules/monitoring/application/forms/Command/AcknowledgeForm.php b/modules/monitoring/application/forms/Command/AcknowledgeForm.php deleted file mode 100644 index 4ac4901b0..000000000 --- a/modules/monitoring/application/forms/Command/AcknowledgeForm.php +++ /dev/null @@ -1,154 +0,0 @@ -addNote( - t( - 'This command is used to acknowledge host or service problems. When a problem is ' - . 'acknowledged, future notifications about problems are temporarily disabled until the ' - . 'host/service changes from its current state.' - ) - ); - - $this->addElement($this->createAuthorField()); - - $this->addElement( - 'textarea', - 'comment', - array( - 'label' => t('Comment'), - 'rows' => 4, - 'cols' => 72, - 'required' => true, - 'helptext' => t( - ' If you work with other administrators you may find it useful to share information ' - . 'about a host or service that is having problems if more than one of you may be working on ' - . 'it. Make sure you enter a brief description of what you are doing.' - ) - ) - ); - - $this->addElement( - 'checkbox', - 'persistent', - array( - 'label' => t('Persistent Comment'), - 'value' => false, - 'helptext' => t( - 'If you would like the comment to remain even when the acknowledgement is removed, ' - . 'check this option.' - ) - ) - ); - - $this->addElement( - 'checkbox', - 'expire', - array( - 'label' => t('Use Expire Time'), - 'helptext' => t('If the acknowledgement should expire, check this option.') - ) - ); - $this->enableAutoSubmit(array('expire')); - - if ($this->getRequest()->getPost('expire', '0') === '1') { - $now = DateTimeFactory::create(); - $this->addElement( - new DateTimePicker( - array( - 'name' => 'expiretime', - 'label' => t('Expire Time'), - 'value' => $now->getTimestamp() + 3600, - 'patterns' => $this->getValidDateTimeFormats(), - 'helptext' => t( - 'Enter the expire date/time for this acknowledgement here. Icinga will ' - . ' delete the acknowledgement after this date expired.' - ), - 'jspicker' => true - ) - ) - ); - } - - $this->addElement( - 'checkbox', - 'sticky', - array( - 'label' => t('Sticky Acknowledgement'), - 'value' => true, - 'helptext' => t( - 'If you want the acknowledgement to disable notifications until the host/service ' - . 'recovers, check this option.' - ) - ) - ); - - $this->addElement( - 'checkbox', - 'notify', - array( - 'label' => t('Send Notification'), - 'value' => true, - 'helptext' => t( - 'If you do not want an acknowledgement notification to be sent out to the appropriate ' - . 'contacts, uncheck this option.' - ) - ) - ); - - $this->setSubmitLabel(t('Acknowledge Problem')); - - parent::create(); - } - - /** - * Add validator for dependent fields - * - * @param array $data - * - * @see \Icinga\Web\Form::preValidation() - */ - protected function preValidation(array $data) - { - if (isset($data['expire']) && intval($data['expire']) === 1) { - $expireTime = $this->getElement('expiretime'); - $expireTime->setRequired(true); - } - } - - /** - * Create the acknowledgement command object - * - * @return AcknowledgeCommand - */ - public function createCommand() - { - return new AcknowledgeCommand( - new Comment( - $this->getAuthorName(), - $this->getValue('comment'), - $this->getValue('persistent') - ), - $this->getValue('expire') ? $this->getValue('expire') : -1, - $this->getValue('notify'), - $this->getValue('sticky') - ); - } -} diff --git a/modules/monitoring/application/forms/Command/CommentForm.php b/modules/monitoring/application/forms/Command/CommentForm.php deleted file mode 100644 index 497c276f1..000000000 --- a/modules/monitoring/application/forms/Command/CommentForm.php +++ /dev/null @@ -1,75 +0,0 @@ -setName('form_CommentForm'); - - $this->addNote(t('This command is used to add a comment to hosts or services.')); - - $this->addElement($this->createAuthorField()); - - $this->addElement( - 'textarea', - 'comment', - array( - 'label' => t('Comment'), - 'rows' => 4, - 'cols' => 72, - 'required' => true, - 'helptext' => t( - 'If you work with other administrators, you may find it useful to share information ' - . 'about a host or service that is having problems if more than one of you may be working on ' - . 'it. Make sure you enter a brief description of what you are doing.' - ) - ) - ); - - $this->addElement( - 'checkbox', - 'persistent', - array( - 'label' => t('Persistent'), - 'value' => true, - 'helptext' => t( - 'If you uncheck this option, the comment will automatically be deleted the next time ' - . 'Icinga is restarted.' - ) - ) - ); - - $this->setSubmitLabel(t('Post Comment')); - - parent::create(); - } - - /** - * Create the command object to add comments - * - * @return AddCommentCommand - */ - public function createCommand() - { - return new AddCommentCommand( - new Comment( - $this->getAuthorName(), - $this->getValue('comment'), - $this->getValue('persistent') - ) - ); - } -} diff --git a/modules/monitoring/application/forms/Command/Common/ScheduleDowntimeCommandForm.php b/modules/monitoring/application/forms/Command/Common/ScheduleDowntimeCommandForm.php deleted file mode 100644 index d48b814e7..000000000 --- a/modules/monitoring/application/forms/Command/Common/ScheduleDowntimeCommandForm.php +++ /dev/null @@ -1,153 +0,0 @@ -add(new DateInterval('PT1H')); - $this->addElements(array( - array( - 'textarea', - 'comment', - array( - 'required' => true, - 'label' => mt('monitoring', 'Comment'), - 'description' => mt( - 'monitoring', - 'If you work with other administrators, you may find it useful to share information about the' - . ' the host or service that is having problems. Make sure you enter a brief description of' - . ' what you are doing.' - ) - ) - ), - new DateTimePicker( - 'start', - array( - 'required' => true, - 'label' => t('Start Time'), - 'description' => mt('monitoring', 'Set the start date and time for the downtime.'), - 'value' => $start - ) - ), - new DateTimePicker( - 'end', - array( - 'required' => true, - 'label' => t('End Time'), - 'description' => mt('monitoring', 'Set the end date and time for the downtime.'), - 'value' => $end - ) - ), - array( - 'select', - 'type', - array( - 'required' => true, - 'autosubmit' => true, - 'label' => mt('monitoring', 'Type'), - 'description' => mt( - 'monitoring', - 'If you select the fixed option, the downtime will be in effect between the start and end' - . ' times you specify whereas a flexible downtime starts when the host or service enters a' - . ' problem state sometime between the start and end times you specified and lasts as long' - . ' as the duration time you enter. The duration fields do not apply for fixed downtimes.' - ), - 'multiOptions' => array( - self::FIXED => mt('monitoring', 'Fixed'), - self::FLEXIBLE => mt('monitoring', 'Flexible') - ), - 'validators' => array( - array( - 'InArray', - true, - array(array(self::FIXED, self::FLEXIBLE)) - ) - ) - ) - ) - )); - $this->addDisplayGroup( - array('start', 'end'), - 'start-end', - array( - 'decorators' => array( - 'FormElements', - array('HtmlTag', array('tag' => 'div', 'class' => 'control-group')) - ) - ) - ); - if (isset($formData['type']) && $formData['type'] === self::FLEXIBLE) { - $this->addElements(array( - new Number( - 'hours', - array( - 'required' => true, - 'label' => mt('monitoring', 'Hours'), - 'value' => 2, - 'min' => -1 - ) - ), - new Number( - 'minutes', - array( - 'required' => true, - 'label' => mt('monitoring', 'Minutes'), - 'value' => 0, - 'min' => -1 - ) - ) - )); - $this->addDisplayGroup( - array('hours', 'minutes'), - 'duration', - array( - 'legend' => mt('monitoring', 'Flexible Duration'), - 'description' => mt( - 'monitoring', - 'Enter here the duration of the downtime. The downtime will be automatically deleted after this' - . ' time expired.' - ), - 'decorators' => array( - 'FormElements', - array('HtmlTag', array('tag' => 'div', 'class' => 'control-group')), - array( - 'Description', - array('tag' => 'span', 'class' => 'description', 'placement' => 'prepend') - ), - 'Fieldset' - ) - ) - ); - } - return $this; - } -} diff --git a/modules/monitoring/application/forms/Command/CustomNotificationForm.php b/modules/monitoring/application/forms/Command/CustomNotificationForm.php deleted file mode 100644 index 9eb75a67b..000000000 --- a/modules/monitoring/application/forms/Command/CustomNotificationForm.php +++ /dev/null @@ -1,93 +0,0 @@ -addNote( - t( - 'This command is used to send a custom notification about hosts or services. Useful in ' - . 'emergencies when you need to notify admins of an issue regarding a monitored system or ' - . 'service.' - ) - ); - - $this->addElement($this->createAuthorField()); - - $this->addElement( - 'textarea', - 'comment', - array( - 'label' => t('Comment'), - 'rows' => 4, - 'cols' => 72, - 'required' => true, - 'helptext' => t( - 'If you work with other administrators, you may find it useful to share information ' - . 'about a host or service that is having problems if more than one of you may be working on ' - . 'it. Make sure you enter a brief description of what you are doing.' - ) - ) - ); - - $this->addElement( - 'checkbox', - 'forced', - array( - 'label' => t('Forced'), - 'helptext' => t( - 'Custom notifications normally follow the regular notification logic in Icinga. Selecting this ' - . 'option will force the notification to be sent out, regardless of time restrictions, ' - . 'whether or not notifications are enabled, etc.' - ) - ) - ); - - $this->addElement( - 'checkbox', - 'broadcast', - array( - 'label' => t('Broadcast'), - 'helptext' => t( - 'Selecting this option causes the notification to be sent out to all normal (non-escalated) ' - . ' and escalated contacts. These options allow you to override the normal notification logic ' - . 'if you need to get an important message out.' - ) - ) - ); - - $this->setSubmitLabel(t('Send Custom Notification')); - - parent::create(); - } - - /** - * Create the command object to send custom notifications - * - * @return CustomNotificationCommand - */ - public function createCommand() - { - return new CustomNotificationCommand( - new Comment( - $this->getAuthorName(), - $this->getValue('comment') - ), - $this->getValue('forced'), - $this->getValue('broadcast') - ); - } -} diff --git a/modules/monitoring/application/forms/Command/DelayNotificationForm.php b/modules/monitoring/application/forms/Command/DelayNotificationForm.php deleted file mode 100644 index efb6eae0f..000000000 --- a/modules/monitoring/application/forms/Command/DelayNotificationForm.php +++ /dev/null @@ -1,65 +0,0 @@ -addNote(t('This command is used to delay the next problem notification that is sent out.')); - - $this->addElement( - 'text', - 'minutes', - array( - 'label' => t('Notification Delay (Minutes From Now)'), - 'style' => 'width: 80px;', - 'value' => 0, - 'required' => true, - 'validators' => array( - array( - 'between', - true, - array( - 'min' => 1, - 'max' => self::MAX_DELAY - ) - ) - ), - 'helptext' => t( - 'The notification delay will be disregarded if the host/service changes state before the next ' - . 'notification is scheduled to be sent out.' - ) - ) - ); - - $this->setSubmitLabel(t('Delay Notification')); - - parent::create(); - } - - /** - * Create the command object to delay notifications - * - * @return DelayNotificationCommand - */ - public function createCommand() - { - return new DelayNotificationCommand($this->getValue('minutes') * 60); - } -} diff --git a/modules/monitoring/application/forms/Command/DisableNotificationWithExpireForm.php b/modules/monitoring/application/forms/Command/DisableNotificationWithExpireForm.php deleted file mode 100644 index d6657dd37..000000000 --- a/modules/monitoring/application/forms/Command/DisableNotificationWithExpireForm.php +++ /dev/null @@ -1,56 +0,0 @@ -addNote('Disable notifications for a specific time on a program-wide basis'); - - $now = DateTimeFactory::create(); - $this->addElement( - new DateTimePicker( - array( - 'name' => 'expiretime', - 'label' => t('Expire Time'), - 'value' => $now->getTimestamp() + 3600, - 'patterns' => $this->getValidDateTimeFormats(), - 'helptext' => t( - 'Enter the expire date/time for this acknowledgement here. Icinga will ' - . ' delete the acknowledgement after this date expired.' - ) - ) - ) - ); - - $this->setSubmitLabel('Disable notifications'); - - parent::create(); - } - - - /** - * Create command object for CommandPipe protocol - * - * @return AcknowledgeCommand - */ - public function createCommand() - { - $command = new DisableNotificationWithExpireCommand(); - $command->setExpirationTimestamp($this->getValue('expiretime')); - return $command; - } -} diff --git a/modules/monitoring/application/forms/Command/MultiCommandFlagForm.php b/modules/monitoring/application/forms/Command/MultiCommandFlagForm.php deleted file mode 100644 index e413848c8..000000000 --- a/modules/monitoring/application/forms/Command/MultiCommandFlagForm.php +++ /dev/null @@ -1,147 +0,0 @@ -flags = $flags; - parent::__construct(); - $this->setEnctype(Zend_Form::ENCTYPE_MULTIPART); - } - - /** - * Initialise the form values with the array of items to configure. - * - * @param mixed $items The items that will be edited with this form. - */ - public function initFromItems($items) - { - $this->values = $this->valuesFromObjects($items); - $this->buildForm(); - $this->populate($this->values); - } - - /** - * Return only the values that have been updated. - */ - public function getChangedValues() - { - $values = $this->getValues(); - $changed = array(); - foreach ($values as $key => $value) { - $oldKey = $key . self::OLD_VALUE_MARKER; - if (array_key_exists($oldKey, $values)) { - if ($values[$oldKey] !== $value) { - $changed[$key] = $value; - } - } - } - return $changed; - } - - private function valuesFromObjects($items) - { - $values = array(); - foreach ($items as $item) { - foreach ($this->flags as $key => $unused) { - if (isset($item->{$key})) { - $value = $item->{$key}; - // convert strings - if ($value === '1' || $value === '0') { - $value = intval($value); - } - // init key with first value - if (!array_key_exists($key, $values)) { - $values[$key] = $value; - continue; - } - // already a mixed state ? - if ($values[$key] === 'unchanged') { - continue; - } - // values differ? - if ($values[$key] ^ $value) { - $values[$key] = 'unchanged'; - } - } - } - } - $old = array(); - foreach ($values as $key => $value) { - $old[$key . self::OLD_VALUE_MARKER] = $value; - } - return array_merge($values, $old); - } - - public function buildCheckboxes() - { - $checkboxes = array(); - foreach ($this->flags as $flag => $description) { - $checkboxes[] = new TriStateCheckbox( - $flag, - array( - 'label' => $description, - 'required' => true - ) - ); - } - return $checkboxes; - } - - /** - * Create the multi flag form - * - * @see Form::create() - */ - public function create() - { - $this->setName('form_flag_configuration'); - foreach ($this->buildCheckboxes() as $checkbox) { - $this->addElement($checkbox); - $old = new Zend_Form_Element_Hidden($checkbox->getName() . self::OLD_VALUE_MARKER); - $this->addElement($old); - } - $this->setSubmitLabel('Save Configuration'); - } -} diff --git a/modules/monitoring/application/forms/Command/RescheduleNextCheckForm.php b/modules/monitoring/application/forms/Command/RescheduleNextCheckForm.php deleted file mode 100644 index cb7ab90f1..000000000 --- a/modules/monitoring/application/forms/Command/RescheduleNextCheckForm.php +++ /dev/null @@ -1,82 +0,0 @@ -addNote( - t( - 'This command is used to schedule the next check of hosts/services. Icinga will re-queue the ' - . 'check at the time you specify.' - ) - ); - - $this->addElement( - new DateTimePicker( - array( - 'name' => 'checktime', - 'label' => t('Check Time'), - 'patterns' => $this->getValidDateTimeFormats(), - 'value' => DateTimeFactory::create()->getTimestamp(), - 'required' => !$this->getRequest()->getPost('forcecheck'), - 'helptext' => t('Set the date/time when this check should be executed.') - ) - ) - ); - - $this->addElement( - new Zend_Form_Element_Checkbox( - array( - 'name' => 'forcecheck', - 'label' => t('Force Check'), - 'value' => true, - 'helptext' => t( - 'If you select this option, Icinga will force a check regardless of both what time the ' - . 'scheduled check occurs and whether or not checks are enabled.' - ) - ) - ) - ); - - // TODO: As of the time of writing it's possible to set hosts AND services as affected by this command but - // with children only makes sense on hosts - if ($this->getWithChildren() === true) { - $this->addNote(t('TODO: Help message when with children is enabled')); - } else { - $this->addNote(t('TODO: Help message when with children is disabled')); - } - - $this->setSubmitLabel(t('Reschedule Check')); - - parent::create(); - } - - /** - * Create the command object to schedule checks - * - * @return ScheduleCheckCommand - */ - public function createCommand() - { - $command = new ScheduleCheckCommand( - $this->getValue('checktime'), - $this->getValue('forcecheck') - ); - return $command->excludeHost($this->getWithChildren()); - } -} diff --git a/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php b/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php deleted file mode 100644 index 73ce2666c..000000000 --- a/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php +++ /dev/null @@ -1,336 +0,0 @@ -setName('ScheduleDowntimeForm'); - } - - /** - * Generate translated multi options based on type constants - * - * @return array - */ - private function getDowntimeTypeOptions() - { - return array( - self::TYPE_FIXED => t('Fixed'), - self::TYPE_FLEXIBLE => t('Flexible') - ); - } - - /** - * Fetch all available downtimes from the database - * - * @return array - */ - private function getCurrentDowntimes() - { - if (isset($this->downtimes)) { - return $this->downtimes; - } - - $cfg = $this->getConfiguration(); - $preferences = $this->getUserPreferences(); - $object = MonitoredObject::fromParams(Url::fromRequest()->getParams()); - $object->fetchDowntimes(); - $downtimes = $object->downtimes; -/* - - $downtimes = Backend::createBackend($this->getRequest()->getParam('backend'))->select() - ->from( - 'downtime', - array( - 'host', - 'service', - 'downtime_start', - 'downtime_scheduled_start_time', - 'downtime_internal_downtime_id' - ) - )->fetchAll(); -*/ - $options = array( - '0' => 'No Triggered Downtime' - ); - $dateFormat = $this->getView()->dateFormat(); - foreach ($downtimes as $downtime) { - $label = sprintf( - 'ID %s: %s%s Starting @ %s', - $downtime->id, - $object->host_name, - $object instanceof Service ? ' (' . $object->service_description . ')' : '', - $dateFormat->formatDateTime($downtime->scheduled_start) - ); - $options[$downtime->id] = $label; - } - return $options; - } - - /** - * Set the downtimes displayed by this form (used for testing) - * - * @param array $downtimes list of strings - */ - public function setCurrentDowntimes($downtimes) - { - $this->downtimes = $downtimes; - } - - /** - * Create the form's elements - */ - protected function create() - { - $this->addNote( - t( - 'This command is used to schedule downtime for hosts/services. During the specified downtime, ' - . 'Icinga will not send notifications out about the affected objects. When the scheduled ' - . 'downtime expires, Icinga will send out notifications as it normally would. Scheduled ' - . 'downtimes are preserved across program shutdowns and restarts.' - ) - ); - - $this->addElement($this->createAuthorField()); - - $this->addElement( - 'textarea', - 'comment', - array( - 'label' => t('Comment'), - 'rows' => 4, - 'cols' => 72, - 'required' => true, - 'helptext' => t( - 'If you work with other administrators, you may find it useful to share information ' - . 'about a host or service that is having problems if more than one of you may be working on ' - . 'it. Make sure you enter a brief description of what you are doing.' - ) - ) - ); - - $this->addElement( - 'select', - 'triggered', - array( - 'label' => t('Triggered by'), - 'required' => true, - 'multiOptions' => $this->getCurrentDowntimes() - ) - ); - - $now = DateTimeFactory::create(); - - $this->addElement( - new DateTimePicker( - array( - 'name' => 'starttime', - 'label' => t('Start Time'), - 'value' => $now->getTimestamp(), - 'patterns' => $this->getValidDateTimeFormats(), - 'helptext' => t('Set the start date/time for the downtime.') - ) - ) - ); - $this->addElement( - new DateTimePicker( - array( - 'name' => 'endtime', - 'label' => t('End Time'), - 'value' => $now->getTimestamp() + 3600, - 'patterns' => $this->getValidDateTimeFormats(), - 'helptext' => t('Set the end date/time for the downtime.') - ) - ) - ); - - $this->addElement( - 'select', - 'type', - array( - 'label' => t('Downtime Type'), - 'multiOptions' => $this->getDowntimeTypeOptions(), - 'required' => true, - 'validators' => array( - array( - 'InArray', - true, - array( - array_keys($this->getDowntimeTypeOptions()) - ) - ) - ), - 'helptext' => t( - 'If you select the fixed option, the downtime will be in effect between the start and end ' - . 'times you specify whereas a flexible downtime starts when the service enters a non-OK state ' - . '(sometime between the start and end times you specified) and lasts as long as the duration ' - . 'of time you enter. The duration fields do not apply for fixed downtime.' - ) - ) - ); - $this->enableAutoSubmit(array('type')); - - if ($this->getRequest()->getPost('type') === self::TYPE_FLEXIBLE) { - $hoursText = new Zend_Form_Element_Text('hours'); - $hoursText->setLabel(t('Flexible Duration')); - $hoursText->setAttrib('style', 'width: 40px;'); - $hoursText->setValue(1); - $hoursText->addDecorator('HtmlTag', array('tag' => 'dd', 'openOnly' => true)); - $hoursText->addDecorator( - 'Callback', - array( - 'callback' => function () { - return t('Hours'); - } - ) - ); - $minutesText = new Zend_Form_Element_Text('minutes'); - $minutesText->setLabel(t('Minutes')); - $minutesText->setAttrib('style', 'width: 40px;'); - $minutesText->setValue(0); - $minutesText->removeDecorator('HtmlTag'); - $minutesText->removeDecorator('Label'); - $minutesText->addDecorator( - 'Callback', - array( - 'callback' => function () { - return t('Minutes'); - } - ) - ); - $this->addElements(array($hoursText, $minutesText)); - $this->addNote( - t( - 'Enter here the duration of the downtime. Icinga will automatically delete the downtime ' - . 'after this time expired.' - ) - ); - } - - // TODO: As of the time of writing it's possible to set hosts AND services as affected by this command but - // with children only makes sense on hosts - if ($this->getWithChildren() === true) { - $this->addNote(t('TODO: Help message when with children is enabled')); - } else { - $this->addElement( - 'select', - 'childobjects', - array( - 'label' => t('Child Objects'), - 'required' => true, - 'multiOptions' => array( - 0 => t('Do nothing with child objects'), - 1 => t('Schedule triggered downtime for all child objects'), - 2 => t('Schedule non-triggered downtime for all child objects') - ), - 'validators' => array( - array( - 'Digits', - true - ), - array( - 'InArray', - true, - array( - array(0, 1, 2) - ) - ) - ) - ) - ); - $this->addNote(t('TODO: Help message when with children is disabled')); - } - - $this->setSubmitLabel(t('Schedule Downtime')); - - parent::create(); - } - - /** - * Change validators at runtime - * - * @param array $data The user provided data that will go into validation - * - * @see Form::preValidation - */ - protected function preValidation(array $data) - { - /* - * Other values needed when downtime type change to flexible - */ - if (isset($data['type']) && $data['type'] === self::TYPE_FLEXIBLE) { - $greaterThanValidator = new Zend_Validate_GreaterThan(-1); - $digitsValidator = new Zend_Validate_Digits(); - - $hours = $this->getElement('hours'); - $hours->setRequired(true); - $hours->addValidator($digitsValidator, true); - $hours->addValidator($greaterThanValidator, true); - - $minutes = $this->getElement('minutes'); - $minutes->setRequired(true); - $minutes->addValidator($digitsValidator, true); - $minutes->addValidator($greaterThanValidator, true); - } - } - - /** - * Create ScheduleDowntimeCommand object - * - * @return ScheduleDowntimeCommand - */ - public function createCommand() - { - // TODO: Add support for host-/servicegroups and services only (#4588) - $command = new ScheduleDowntimeCommand( - $this->getValue('starttime'), - $this->getValue('endtime'), - new Comment( - $this->getRequest()->getUser()->getUsername(), - $this->getValue('comment') - ), - $this->getValue('type') === self::TYPE_FIXED, - $this->getValue('hours') * 3600 + $this->getValue('minutes') * 60, - $this->getValue('triggered') - ); - - return $command->includeChildren( - $this->getWithChildren(), - $this->getValue('childobjects') === 1 - ); - } -} diff --git a/modules/monitoring/application/forms/Command/Service/ScheduleServiceDowntimeCommandForm.php b/modules/monitoring/application/forms/Command/Service/ScheduleServiceDowntimeCommandForm.php deleted file mode 100644 index 7f13034a0..000000000 --- a/modules/monitoring/application/forms/Command/Service/ScheduleServiceDowntimeCommandForm.php +++ /dev/null @@ -1,113 +0,0 @@ -service = $service; - return $this; - } - - /** - * Get the service to set in downtime - * - * @return Service - */ - public function getService() - { - return $this->service; - } - - /** - * (non-PHPDoc) - * @see \Zend_Form::init() For the method documentation. - */ - public function init() - { - $this->setSubmitLabel(mt('monitoring', 'Schedule Service Downtime')); - } - - /** - * (non-PHPDoc) - * @see \Icinga\Web\Form::createElements() For the method documentation. - */ - public function createElements(array $formData = array()) - { - $this->addElement( - 'note', - 'command-info', - array( - 'value' => mt( - 'monitoring', - 'This command is used to schedule a service downtime. During the specified downtime,' - . ' Icinga will not send notifications out about the service. When the scheduled downtime' - . ' expires, Icinga will send out notifications for the service as it normally would.' - . ' Scheduled downtimes are preserved across program shutdowns and restarts.' - ) - ) - ); - parent::createElements($formData); - return $this; - } - - /** - * Get the command which is to be sent to an Icinga instance - * - * @return ScheduleServiceDowntimeCommand - */ - public function getCommand() - { - return new ScheduleServiceDowntimeCommand(); - } - - /** - * (non-PHPDoc) - * @see \Icinga\Web\Form::onSuccess() For the method documentation. - */ - public function onSuccess(Request $request) - { - $scheduleDowntime = $this->getCommand(); - $scheduleDowntime->setService($this->service); - $scheduleDowntime->setComment($this->getElement('comment')->getValue()); - $scheduleDowntime->setAuthor($request->getUser()); - $scheduleDowntime->setStart($this->getElement('start')->getValue()); - $scheduleDowntime->setEnd($this->getElement('end')->getValue()); - if ($this->getElement('type')->getValue() === self::FLEXIBLE) { - $scheduleDowntime->setFlexible(); - $scheduleDowntime->setDuration( - (float) $this->getElement('hours')->getValue() * 3600 - + (float) $this->getElement('minutes')->getValue() * 60 - ); - } - $this->getTransport($request)->send($scheduleDowntime); - Notification::success(mt('monitoring', 'Scheduling service downtime..')); - return true; - } -} diff --git a/modules/monitoring/application/forms/Command/SingleArgumentCommandForm.php b/modules/monitoring/application/forms/Command/SingleArgumentCommandForm.php deleted file mode 100644 index d7228ebdf..000000000 --- a/modules/monitoring/application/forms/Command/SingleArgumentCommandForm.php +++ /dev/null @@ -1,169 +0,0 @@ -hostCommand = $hostCommand; - - if ($serviceCommand !== null) { - $this->serviceCommand = $serviceCommand; - } - } - - /** - * Setter for global commands - * - * @param string $hostOrGenericGlobalCommand Generic command or one for host - * @param string $serviceGlobalCommand If any (leave blank if you need a global global) - */ - public function setGlobalCommands($hostOrGenericGlobalCommand, $serviceGlobalCommand = null) - { - $this->globalCommands[] = $hostOrGenericGlobalCommand; - - if ($serviceGlobalCommand !== null) { - $this->globalCommands[] = $serviceGlobalCommand; - } - } - - /** - * Use an explicit value to send with command - * - * @param mixed $parameterValue - */ - public function setParameterValue($parameterValue) - { - $this->parameterValue = $parameterValue; - } - - /** - * Use a form field to take the value from - * - * @param string $parameterName - */ - public function setParameterName($parameterName) - { - $this->parameterName = $parameterName; - } - - /** - * Flag to ignore every objects - * - * @param bool $flag - */ - public function setObjectIgnoreFlag($flag = true) - { - $this->ignoreObject = (bool) $flag; - } - - /** - * - */ - protected function create() - { - if ($this->parameterName) { - $field = new Zend_Form_Element_Hidden($this->parameterName); - $value = $this->getRequest()->getParam($field->getName()); - $field->setValue($value); - $this->addElement($field); - } - parent::create(); - } - - public function setRequest(Zend_Controller_Request_Abstract $request) - { - parent::setRequest($request); - - if ($this->globalCommand === true) { - $this->setParameterName('global'); - } - } - - - /** - * Create command object for CommandPipe protocol - * - * @return SingleArgumentCommand - */ - public function createCommand() - { - $command = new SingleArgumentCommand(); - - if ($this->parameterValue !== null) { - $command->setValue($this->parameterValue); - } else { - $command->setValue($this->getValue($this->parameterName)); - } - - if ($this->provideGlobalCommand() == true) { - $command->setGlobalCommands($this->globalCommands); - $this->ignoreObject = true; - } else { - $command->setCommand($this->hostCommand, $this->serviceCommand); - } - - $command->setObjectIgnoreFlag($this->ignoreObject); - - return $command; - } -} diff --git a/modules/monitoring/application/forms/Command/SubmitPassiveCheckResultForm.php b/modules/monitoring/application/forms/Command/SubmitPassiveCheckResultForm.php deleted file mode 100644 index c2c9151f3..000000000 --- a/modules/monitoring/application/forms/Command/SubmitPassiveCheckResultForm.php +++ /dev/null @@ -1,177 +0,0 @@ - array( - 0 => t('UP'), - 1 => t('DOWN'), - 2 => t('UNREACHABLE') - ), - self::TYPE_SERVICE => array( - 0 => t('OK'), - 1 => t('WARNING'), - 2 => t('CRITICAL'), - 3 => t('UNKNOWN') - ) - ); - } - - parent::init(); - } - - /** - * Setter for type - * - * @param string $type - */ - public function setType($type) - { - $this->type = $type; - } - - /** - * Getter for type - * - * @return string - */ - public function getType() - { - return $this->type; - } - - /** - * Return array of options - * - * @return array - * @throws \Icinga\Exception\ProgrammingError - */ - public function getOptions() - { - if (in_array($this->getType(), array(self::TYPE_HOST, self::TYPE_SERVICE)) === false) { - throw new ProgrammingError('Type is not valid'); - } - - return self::$options[$this->getType()]; - } - - /** - * Create the form's elements - */ - protected function create() - { - $this->setName('form_submit_passive_checkresult'); - - $this->addNote( - t( - 'This command is used to submit a passive check result for particular hosts/services. It is ' - . 'particularly useful for resetting security-related objects to OK states once they have been ' - . 'dealt with.' - ) - ); - - $this->addElement( - 'select', - 'pluginstate', - array( - 'label' => t('Check Result'), - 'multiOptions' => $this->getOptions(), - 'required' => true, - 'validators' => array( - array( - 'Digits', - true - ), - array( - 'InArray', - true, - array( - array_keys($this->getOptions()) - ) - ) - ), - 'helptext' => t('Set the state which should be send to Icinga for this objects.') - ) - ); - - $this->addElement( - 'textarea', - 'checkoutput', - array( - 'label' => t('Check Output'), - 'rows' => 2, - 'cols' => 72, - 'required' => true, - 'helptext' => t('Fill in the check output string which should be send to Icinga.') - ) - ); - - $this->addElement( - 'textarea', - 'performancedata', - array( - 'label' => t('Performance Data'), - 'rows' => 2, - 'cols' => 72, - 'helptext' => t('Fill in the performance data string which should be send to Icinga.') - ) - ); - - $this->setSubmitLabel(t('Submit Passive Check Result')); - - parent::create(); - } - - /** - * Create the submit passive checkresult command object - * - * @return SubmitPassiveCheckresultCommand - */ - public function createCommand() - { - return new SubmitPassiveCheckresultCommand( - $this->getValue('pluginstate'), - $this->getValue('checkoutput'), - $this->getValue('performancedata') - ); - } -} diff --git a/modules/monitoring/application/forms/Command/WithChildrenCommandForm.php b/modules/monitoring/application/forms/Command/WithChildrenCommandForm.php deleted file mode 100644 index 5ae69173e..000000000 --- a/modules/monitoring/application/forms/Command/WithChildrenCommandForm.php +++ /dev/null @@ -1,37 +0,0 @@ -withChildren = $flag; - } - - /** - * Getter for withChildren - * - * @return bool - */ - public function getWithChildren() - { - return $this->withChildren; - } -} diff --git a/modules/monitoring/library/Monitoring/Command/AcknowledgeCommand.php b/modules/monitoring/library/Monitoring/Command/AcknowledgeCommand.php deleted file mode 100644 index 641a2ae73..000000000 --- a/modules/monitoring/library/Monitoring/Command/AcknowledgeCommand.php +++ /dev/null @@ -1,164 +0,0 @@ -expireTime = $expire; - $this->comment = $comment; - $this->notify = $notify; - $this->sticky = $sticky; - } - - /** - * Set the time when this acknowledgement should expire - * - * @param int $expireTime The time as UNIX timestamp or -1 if it shouldn't expire - * - * @return self - */ - public function setExpire($expireTime) - { - $this->expireTime = (int) $expireTime; - return $this; - } - - /** - * Set the comment for this acknowledgement - * - * @param Comment $comment - * - * @return self - */ - public function setComment(Comment $comment) - { - $this->comment = $comment; - return $this; - } - - /** - * Set whether the notify flag of this acknowledgment should be set - * - * @param bool $state - * - * @return self - */ - public function setNotify($state) - { - $this->notify = (bool) $state; - return $this; - } - - /** - * Set whether this acknowledgement is of type sticky - * - * @param bool $state - * - * @return self - */ - public function setSticky($state) - { - $this->sticky = (bool) $state; - return $this; - } - - /** - * Return this command's parameters properly arranged in an array - * - * @return array - * @see Command::getArguments() - */ - public function getArguments() - { - $parameters = array_merge( - array( - $this->sticky ? '2' : '0', - $this->notify ? '1' : '0' - ), - $this->comment->getArguments() - ); - - if ($this->expireTime > -1) { - array_splice($parameters, 3, 0, array($this->expireTime)); - } - - return $parameters; - } - - /** - * Return the command as a string with the given host being inserted - * - * @param string $hostname The name of the host to insert - * - * @return string The string representation of the command - * @see Command::getHostCommand() - */ - public function getHostCommand($hostname) - { - $parameters = $this->getArguments(); - return sprintf('ACKNOWLEDGE_HOST_PROBLEM%s;', $this->expireTime > -1 ? '_EXPIRE' : '') - . implode(';', array_merge(array($hostname), $parameters)); - } - - /** - * Return the command as a string with the given host and service being inserted - * - * @param string $hostname The name of the host to insert - * @param string $servicename The name of the service to insert - * - * @return string The string representation of the command - * @see Command::getServiceCommand() - */ - public function getServiceCommand($hostname, $servicename) - { - $parameters = $this->getArguments(); - return sprintf('ACKNOWLEDGE_SVC_PROBLEM%s;', $this->expireTime > -1 ? '_EXPIRE' : '') - . implode(';', array_merge(array($hostname, $servicename), $parameters)); - } -} diff --git a/modules/monitoring/library/Monitoring/Command/AddCommentCommand.php b/modules/monitoring/library/Monitoring/Command/AddCommentCommand.php deleted file mode 100644 index 0464d5cb2..000000000 --- a/modules/monitoring/library/Monitoring/Command/AddCommentCommand.php +++ /dev/null @@ -1,79 +0,0 @@ -comment = $comment; - } - - /** - * Set the comment for this command - * - * @param Comment $comment - * - * @return self - */ - public function setComment(Comment $comment) - { - $this->comment = $comment; - return $this; - } - - public function getArguments() - { - return $this->comment->getArguments(); - } - - /** - * Return the command as a string with the given host being inserted - * - * @param string $hostname The name of the host to insert - * - * @return string The string representation of the command - * @see Command::getHostCommand() - */ - public function getHostCommand($hostname) - { - return sprintf('ADD_HOST_COMMENT;%s;', $hostname) . implode(';', $this->getArguments()); - } - - /** - * Return the command as a string with the given host and service being inserted - * - * @param string $hostname The name of the host to insert - * @param string $servicename The name of the service to insert - * - * @return string The string representation of the command - * @see Command::getServiceCommand() - */ - public function getServiceCommand($hostname, $servicename) - { - return sprintf('ADD_SVC_COMMENT;%s;%s;', $hostname, $servicename) - . implode(';', $this->getArguments()); - } -} diff --git a/modules/monitoring/library/Monitoring/Command/CommandPipe.php b/modules/monitoring/library/Monitoring/Command/CommandPipe.php deleted file mode 100644 index 8d149dd20..000000000 --- a/modules/monitoring/library/Monitoring/Command/CommandPipe.php +++ /dev/null @@ -1,603 +0,0 @@ -getTransportForConfiguration($config); - $this->name = $config->name; - } - - /** - * Setup the @see Icinga\Protocol\Commandpipe\Transport.php class that will be used for accessing the command pipe - * - * Currently this method uses SecureShell when a host is given, otherwise it assumes the pipe is accessible - * via the machines filesystem - * - * @param \Zend_Config $config The configuration as defined in the instances.ini - */ - private function getTransportForConfiguration(\Zend_Config $config) - { - if (isset($config->host)) { - $this->transport = new SecureShell(); - $this->transport->setEndpoint($config); - } else { - $this->transport = new LocalPipe(); - $this->transport->setEndpoint($config); - } - } - - /** - * Send the command string $command to the icinga pipe - * - * This method just delegates the send command to the underlying transport - * - * @param String $command The command string to send, without the timestamp - */ - public function send($command) - { - $this->transport->send($this->escape($command)); - } - - /** - * Return the given command string with escaped newlines - * - * @param string $command The command string to escape - * - * @return string The escaped command string - */ - public function escape($command) - { - return str_replace(array("\r", "\n"), array('\r', '\n'), $command); - } - - /** - * Send a command to the icinga pipe - * - * @param Command $command - * @param array $objects - */ - public function sendCommand(Command $command, array $objects = array()) - { - if ($command->provideGlobalCommand() === true) { - $this->send($command->getGlobalCommand()); - } else { - foreach ($objects as $object) { - $objectType = $this->getObjectType($object); - if ($objectType === self::TYPE_SERVICE) { - $this->send($command->getServiceCommand($object->host_name, $object->service_description)); - } else { - $this->send($command->getHostCommand($object->host_name)); - } - } - } - } - - /** - * Remove the acknowledgements of the provided objects - * - * @param array $objects An array of mixed service and host objects whose acknowledgments will be removed - */ - public function removeAcknowledge($objects) - { - foreach ($objects as $object) { - if (isset($object->service_description)) { - $this->send("REMOVE_SVC_ACKNOWLEDGEMENT;$object->host_name;$object->service_description"); - } else { - $this->send("REMOVE_HOST_ACKNOWLEDGEMENT;$object->host_name"); - } - } - } - - /** - * Removes the submitted comments - * - * @param array $objectsOrComments An array of hosts and services (to remove all their comments) - * or single comment objects to remove - */ - public function removeComment($objectsOrComments) - { - foreach ($objectsOrComments as $object) { - if (isset($object->comment_id)) { - if (isset($object->service_description)) { - $type = "SERVICE_COMMENT"; - } else { - $type = "HOST_COMMENT"; - } - $this->send("DEL_{$type};" . intval($object->comment_id)); - } else { - if (isset($object->service_description)) { - $type = "SERVICE_COMMENT"; - } else { - $type = "HOST_COMMENT"; - } - $cmd = "DEL_ALL_{$type}S;" . $object->host_name; - if ($type == "SERVICE_COMMENT") { - $cmd .= ";" . $object->service_description; - } - $this->send($cmd); - } - } - } - - /** - * Globally enable notifications for this instance - * - */ - public function enableGlobalNotifications() - { - $this->send("ENABLE_NOTIFICATIONS"); - } - - /** - * Globally disable notifications for this instance - * - */ - public function disableGlobalNotifications() - { - $this->send("DISABLE_NOTIFICATIONS"); - } - - /** - * Return the object type of the provided object (TYPE_SERVICE or TYPE_HOST) - * - * @param $object The object to identify - * @return string TYPE_SERVICE or TYPE_HOST - */ - private function getObjectType($object) - { - //@TODO: This must be refactored once more commands are supported - if (isset($object->service_description)) { - return self::TYPE_SERVICE; - } - return self::TYPE_HOST; - } - - /** - * Remove downtimes for objects - * - * @param array $objects An array containing hosts, service or downtime objects - * @param int $starttime An optional starttime to use for the DEL_DOWNTIME_BY_HOST_NAME command - */ - public function removeDowntime($objects, $starttime = 0) - { - foreach ($objects as $object) { - $type = $this->getObjectType($object); - if (isset($object->downtime_id)) { - $this->send("DEL_" . $type . "_DOWNTIME;" . $object->downtime_id); - continue; - } - $cmd = "DEL_DOWNTIME_BY_HOST_NAME;" . $object->host_name; - if ($type == self::TYPE_SERVICE) { - $cmd .= ";" . $object->service_description; - } - if ($starttime != 0) { - $cmd .= ";" . $starttime; - } - $this->send($cmd); - } - } - - /** - * Restart the icinga instance - * - */ - public function restartIcinga() - { - $this->send("RESTART_PROCESS"); - } - - /** - * Modify monitoring flags for the provided objects - * - * @param array $objects An arry of service and/or host objects to modify - * @param PropertyModifier $flags The Monitoring attributes to modify - */ - public function setMonitoringProperties($objects, PropertyModifier $flags) - { - foreach ($objects as $object) { - $type = $this->getObjectType($object); - $formatArray = $flags->getFormatString($type); - foreach ($formatArray as $format) { - $format .= ";" - . $object->host_name - . ($type == self::TYPE_SERVICE ? ";" . $object->service_description : ""); - $this->send($format); - } - } - } - - /** - * Enable active checks for all provided objects - * - * @param array $objects An array containing services and hosts to enable active checks for - */ - public function enableActiveChecks($objects) - { - $this->setMonitoringProperties( - $objects, - new PropertyModifier( - array( - PropertyModifier::ACTIVE => PropertyModifier::STATE_ENABLE - ) - ) - ); - } - - /** - * Disable active checks for all provided objects - * - * @param array $objects An array containing services and hosts to disable active checks - */ - public function disableActiveChecks($objects) - { - $this->setMonitoringProperties( - $objects, - new PropertyModifier( - array( - PropertyModifier::ACTIVE => PropertyModifier::STATE_DISABLE - ) - ) - ); - } - - /** - * Enable passive checks for all provided objects - * - * @param array $objects An array containing services and hosts to enable passive checks for - */ - public function enablePassiveChecks($objects) - { - $this->setMonitoringProperties( - $objects, - new PropertyModifier( - array( - PropertyModifier::PASSIVE => PropertyModifier::STATE_ENABLE - ) - ) - ); - } - - /** - * Enable passive checks for all provided objects - * - * @param array $objects An array containing services and hosts to enable passive checks for - */ - public function disablePassiveChecks($objects) - { - $this->setMonitoringProperties( - $objects, - new PropertyModifier( - array( - PropertyModifier::PASSIVE => PropertyModifier::STATE_DISABLE - ) - ) - ); - } - - /** - * Enable flap detection for all provided objects - * - * @param array $objects An array containing services and hosts to enable flap detection - * - */ - public function enableFlappingDetection($objects) - { - $this->setMonitoringProperties( - $objects, - new PropertyModifier( - array( - PropertyModifier::FLAPPING => PropertyModifier::STATE_ENABLE - ) - ) - ); - } - - /** - * Disable flap detection for all provided objects - * - * @param array $objects An array containing services and hosts to disable flap detection - * - */ - public function disableFlappingDetection($objects) - { - $this->setMonitoringProperties( - $objects, - new PropertyModifier( - array( - PropertyModifier::FLAPPING => PropertyModifier::STATE_DISABLE - ) - ) - ); - } - - /** - * Enable notifications for all provided objects - * - * @param array $objects An array containing services and hosts to enable notification - * - */ - public function enableNotifications($objects) - { - $this->setMonitoringProperties( - $objects, - new PropertyModifier( - array( - PropertyModifier::NOTIFICATIONS => PropertyModifier::STATE_ENABLE - ) - ) - ); - } - - /** - * Disable flap detection for all provided objects - * - * @param array $objects An array containing services and hosts to disable notifications - * - */ - public function disableNotifications($objects) - { - $this->setMonitoringProperties( - $objects, - new PropertyModifier( - array( - PropertyModifier::NOTIFICATIONS => PropertyModifier::STATE_DISABLE - ) - ) - ); - } - - /** - * Enable freshness checks for all provided objects - * - * @param array $objects An array of hosts and/or services - */ - public function enableFreshnessChecks($objects) - { - $this->setMonitoringProperties( - $objects, - new PropertyModifier( - array( - PropertyModifier::FRESHNESS => PropertyModifier::STATE_ENABLE - ) - ) - ); - } - - /** - * Disable freshness checks for all provided objects - * - * @param array $objects An array of hosts and/or services - */ - public function disableFreshnessChecks($objects) - { - $this->setMonitoringProperties( - $objects, - new PropertyModifier( - array( - PropertyModifier::FRESHNESS => PropertyModifier::STATE_DISABLE - ) - ) - ); - } - - /** - * Enable event handler for all provided objects - * - * @param array $objects An array of hosts and/or services - */ - public function enableEventHandler($objects) - { - $this->setMonitoringProperties( - $objects, - new PropertyModifier( - array( - PropertyModifier::EVENTHANDLER => PropertyModifier::STATE_ENABLE - ) - ) - ); - } - - /** - * Disable event handler for all provided objects - * - * @param array $objects An array of hosts and/or services - */ - public function disableEventHandler($objects) - { - $this->setMonitoringProperties( - $objects, - new PropertyModifier( - array( - PropertyModifier::EVENTHANDLER => PropertyModifier::STATE_DISABLE - ) - ) - ); - } - - /** - * Enable performance data parsing for all provided objects - * - * @param array $objects An array of hosts and/or services - */ - public function enablePerfdata($objects) - { - $this->setMonitoringProperties( - $objects, - new PropertyModifier( - array( - PropertyModifier::PERFDATA => PropertyModifier::STATE_ENABLE - ) - ) - ); - } - - /** - * Disable performance data parsing for all provided objects - * - * @param array $objects An array of hosts and/or services - */ - public function disablePerfdata($objects) - { - $this->setMonitoringProperties( - $objects, - new PropertyModifier( - array( - PropertyModifier::PERFDATA => PropertyModifier::STATE_DISABLE - ) - ) - ); - } - - /** - * Disable notifications for all services of the provided hosts - * - * @param array $objects An array of hosts - */ - public function disableNotificationsForServices($objects) - { - foreach ($objects as $host) { - $msg = 'DISABLE_HOST_SVC_NOTIFICATIONS;'.$host->host_name; - $this->send($msg); - } - } - - /** - * Enable notifications for all services of the provided hosts - * - * @param array $objects An array of hosts - */ - public function enableNotificationsForServices($objects) - { - foreach ($objects as $host) { - $msg = 'ENABLE_HOST_SVC_NOTIFICATIONS;'.$host->host_name; - $this->send($msg); - } - } - - /** - * Disable active checks for all services of the provided hosts - * - * @param array $objects An array of hosts - */ - public function disableActiveChecksWithChildren($objects) - { - foreach ($objects as $host) { - $msg = 'DISABLE_HOST_SVC_CHECKS;'.$host->host_name; - $this->send($msg); - } - } - - /** - * Enable active checks for all services of the provided hosts - * - * @param array $objects An array of hosts - */ - public function enableActiveChecksWithChildren($objects) - { - foreach ($objects as $host) { - $msg = 'ENABLE_HOST_SVC_CHECKS;'.$host->host_name; - $this->send($msg); - } - } - - /** - * Reset modified attributes for all provided objects - * - * @param array $objects An array of hosts and services - */ - 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'); - } - } - } - - /** - * Return the transport handler that handles actual sending of commands - * - * @return Transport - */ - public function getTransport() - { - return $this->transport; - } -} diff --git a/modules/monitoring/library/Monitoring/Command/Comment.php b/modules/monitoring/library/Monitoring/Command/Comment.php deleted file mode 100644 index 2b8caf52b..000000000 --- a/modules/monitoring/library/Monitoring/Command/Comment.php +++ /dev/null @@ -1,61 +0,0 @@ -author = $author; - $this->content = $content; - $this->persistent = $persistent; - } - - /** - * Return this comment's properties as list of command parameters - * - * @param bool $ignorePersistentFlag Whether the persistent flag should be included or not - * @return array - */ - public function getArguments($ignorePersistentFlag = false) - { - if ($ignorePersistentFlag) { - return array($this->author, $this->content); - } else { - return array($this->persistent ? '1' : '0', $this->author, $this->content); - } - } -} diff --git a/modules/monitoring/library/Monitoring/Command/Common/AddCommentCommand.php b/modules/monitoring/library/Monitoring/Command/Common/AddCommentCommand.php deleted file mode 100644 index 5d56011ae..000000000 --- a/modules/monitoring/library/Monitoring/Command/Common/AddCommentCommand.php +++ /dev/null @@ -1,50 +0,0 @@ -persistent = $persistent; - return $this; - } - - /** - * Is the comment persistent? - * - * @return bool - */ - public function getPersistent() - { - return $this->persistent; - } -} diff --git a/modules/monitoring/library/Monitoring/Command/Common/ObjectCommand.php b/modules/monitoring/library/Monitoring/Command/Common/ObjectCommand.php deleted file mode 100644 index 8727c237b..000000000 --- a/modules/monitoring/library/Monitoring/Command/Common/ObjectCommand.php +++ /dev/null @@ -1,62 +0,0 @@ -assertOneOf($this->allowedObjects); - $this->object = $object; - return $this; - } - - /** - * Get the involved object - * - * @return MonitoredObject - */ - public function getObject() - { - return $this->object; - } -} diff --git a/modules/monitoring/library/Monitoring/Command/Common/ScheduleDowntimeCommand.php b/modules/monitoring/library/Monitoring/Command/Common/ScheduleDowntimeCommand.php deleted file mode 100644 index 0afb4087a..000000000 --- a/modules/monitoring/library/Monitoring/Command/Common/ScheduleDowntimeCommand.php +++ /dev/null @@ -1,193 +0,0 @@ -start = $start; - return $this; - } - - /** - * Get the date and time when the downtime should start - * - * @return DateTime - */ - public function getStart() - { - return $this->start; - } - - /** - * Set the date and time when the downtime should end - * - * @param DateTime $end - * - * @return $this - */ - public function setEnd(DateTime $end) - { - $this->end = $end; - return $this; - } - - /** - * Get the date and time when the downtime should end - * - * @return DateTime - */ - public function getEnd() - { - return $this->end; - } - - /** - * Set whether is flexible or fixed - * - * @param boolean $flexible - * - * @return $this - */ - public function setFlexible($flexible = true) - { - $this->flexible = (bool) $flexible; - return $this; - } - - /** - * Is the downtime flexible? - * - * @return boolean - */ - public function getFlexible() - { - return $this->flexible; - } - - /** - * Set the ID of the downtime which triggers this downtime - * - * @param int $triggerId - * - * @return $this - */ - public function setTriggerId($triggerId) - { - $this->triggerId = (int) $triggerId; - return $this; - } - - /** - * Get the ID of the downtime which triggers this downtime - * - * @return int|null - */ - public function getTriggerId() - { - return $this->triggerId; - } - - /** - * Set the duration in seconds the downtime must last if it's a flexible downtime - * - * @param int $duration - * - * @return $this - */ - public function setDuration($duration) - { - $this->duration = (int) $duration; - return $this; - } - - /** - * Get the duration in seconds the downtime must last if it's a flexible downtime - * - * @return int|null - */ - public function getDuration() - { - return $this->duration; - } - - /** - * (non-PHPDoc) - * @see \Icinga\Module\Monitoring\Command\IcingaCommand::getCommandString() For the method documentation. - */ - public function getCommandString() - { - return sprintf( - '%u;%u;%u;%u;%u;%s', - $this->start->getTimestamp(), - $this->end->getTimestamp(), - ! $this->flexible, - $this->triggerId, - $this->duration, - parent::getCommandString() - ); - } -} diff --git a/modules/monitoring/library/Monitoring/Command/Common/ToggleFeature.php b/modules/monitoring/library/Monitoring/Command/Common/ToggleFeature.php deleted file mode 100644 index 7002cd1e4..000000000 --- a/modules/monitoring/library/Monitoring/Command/Common/ToggleFeature.php +++ /dev/null @@ -1,42 +0,0 @@ -enable = true; - return $this; - } - - /** - * Disable the feature - * - * @return $this - */ - public function disable() - { - $this->enable = false; - return $this; - } -} diff --git a/modules/monitoring/library/Monitoring/Command/Common/WithCommentCommand.php b/modules/monitoring/library/Monitoring/Command/Common/WithCommentCommand.php deleted file mode 100644 index c913e5bd3..000000000 --- a/modules/monitoring/library/Monitoring/Command/Common/WithCommentCommand.php +++ /dev/null @@ -1,71 +0,0 @@ -author = (string) $author; - return $this; - } - - /** - * Get the author - * - * @return string - */ - public function getAuthor() - { - return $this->author; - } - - /** - * Set the comment - * - * @param string $comment - * - * @return $this - */ - public function setComment($comment) - { - $this->comment = (string) $comment; - return $this; - } - - /** - * Get the comment - * - * @return string - */ - public function getComment() - { - return $this->comment; - } -} diff --git a/modules/monitoring/library/Monitoring/Command/CustomNotificationCommand.php b/modules/monitoring/library/Monitoring/Command/CustomNotificationCommand.php deleted file mode 100644 index 21cf22520..000000000 --- a/modules/monitoring/library/Monitoring/Command/CustomNotificationCommand.php +++ /dev/null @@ -1,139 +0,0 @@ -comment = $comment; - $this->forced = $forced; - $this->broadcast = $broadcast; - } - - /** - * Set the comment for this notification - * - * @param Comment $comment - * - * @return self - */ - public function setComment(Comment $comment) - { - $this->comment = $comment; - return $this; - } - - /** - * Set whether this notification is forced - * - * @param bool $state - * - * @return self - */ - public function setForced($state) - { - $this->forced = (bool) $state; - return $this; - } - - /** - * Set whether this notification is sent to all contacts - * - * @param bool $state - * - * @return self - */ - public function setBroadcast($state) - { - $this->broadcast = (bool) $state; - return $this; - } - - /** - * Return this command's parameters properly arranged in an array - * - * @return array - * @see Command::getArguments() - */ - public function getArguments() - { - $options = 0; - if ($this->forced) { - $options |= 2; - } - if ($this->broadcast) { - $options |= 1; - } - return array_merge(array($options), $this->comment->getArguments(true)); - } - - /** - * Return the command as a string with the given host being inserted - * - * @param string $hostname The name of the host to insert - * - * @return string The string representation of the command - * @see Command::getHostCommand() - */ - public function getHostCommand($hostname) - { - return 'SEND_CUSTOM_HOST_NOTIFICATION;' . implode(';', array_merge(array($hostname), $this->getArguments())); - } - - /** - * Return the command as a string with the given host and service being inserted - * - * @param string $hostname The name of the host to insert - * @param string $servicename The name of the service to insert - * - * @return string The string representation of the command - * @see Command::getServiceCommand() - */ - public function getServiceCommand($hostname, $servicename) - { - return 'SEND_CUSTOM_SVC_NOTIFICATION;' . implode( - ';', - array_merge( - array($hostname, $servicename), - $this->getArguments() - ) - ); - } -} diff --git a/modules/monitoring/library/Monitoring/Command/DelayNotificationCommand.php b/modules/monitoring/library/Monitoring/Command/DelayNotificationCommand.php deleted file mode 100644 index 7f8dcf749..000000000 --- a/modules/monitoring/library/Monitoring/Command/DelayNotificationCommand.php +++ /dev/null @@ -1,87 +0,0 @@ -delay = $delay; - } - - /** - * Set how long notifications should be delayed - * - * @param int $seconds In seconds - * - * @return self - */ - public function setDelay($seconds) - { - $this->delay = (int) $seconds; - return $this; - } - - /** - * Return this command's parameters properly arranged in an array - * - * @return array - * @see Command::getArguments() - */ - public function getArguments() - { - return array($this->delay); - } - - /** - * Return the command as a string with the given host being inserted - * - * @param string $hostname The name of the host to insert - * - * @return string The string representation of the command - * @see Command::getHostCommand() - */ - public function getHostCommand($hostname) - { - return 'DELAY_HOST_NOTIFICATION;' . implode(';', array_merge(array($hostname), $this->getArguments())); - } - - /** - * Return the command as a string with the given host and service being inserted - * - * @param string $hostname The name of the host to insert - * @param string $servicename The name of the service to insert - * - * @return string The string representation of the command - * @see Command::getServiceCommand() - */ - public function getServiceCommand($hostname, $servicename) - { - return 'DELAY_SVC_NOTIFICATION;' . implode( - ';', - array_merge( - array($hostname, $servicename), - $this->getArguments() - ) - ); - } -} diff --git a/modules/monitoring/library/Monitoring/Command/DisableNotificationWithExpireCommand.php b/modules/monitoring/library/Monitoring/Command/DisableNotificationWithExpireCommand.php deleted file mode 100644 index d6fb6322a..000000000 --- a/modules/monitoring/library/Monitoring/Command/DisableNotificationWithExpireCommand.php +++ /dev/null @@ -1,92 +0,0 @@ -globalCommand = true; - } - - /** - * Setter for expiration timestamp - * - * @param integer $timestamp - */ - public function setExpirationTimestamp($timestamp) - { - $this->expirationTimestamp = $timestamp; - } - - /** - * Return this command's arguments in the order expected by the actual command definition - * - * @return array - */ - public function getArguments() - { - return array($this->expirationTimestamp); - } - - /** - * Return the command as a string with the given host being inserted - * - * @param string $hostname The name of the host to insert - * @throws ProgrammingError - * - * @return string The string representation of the command - */ - public function getHostCommand($hostname) - { - throw new ProgrammingError('This is not supported for single objects'); - } - - /** - * Return the command as a string with the given host and service being inserted - * - * @param string $hostname The name of the host to insert - * @param string $servicename The name of the service to insert - * @throws ProgrammingError - * @return string The string representation of the command# - */ - public function getServiceCommand($hostname, $servicename) - { - throw new ProgrammingError('This is not supported for single objects'); - } - - /** - * Create a global command - * - * @param string $instance - * - * @return string - */ - public function getGlobalCommand($instance = null) - { - return sprintf( - 'DISABLE_NOTIFICATIONS_EXPIRE_TIME;%d;%s', - time(), - implode(';', $this->getArguments()) - ); - } -} diff --git a/modules/monitoring/library/Monitoring/Command/Exception/InvalidCommandException.php b/modules/monitoring/library/Monitoring/Command/Exception/InvalidCommandException.php deleted file mode 100644 index 662a156e9..000000000 --- a/modules/monitoring/library/Monitoring/Command/Exception/InvalidCommandException.php +++ /dev/null @@ -1,12 +0,0 @@ - self::STATE_KEEP, - self::ACTIVE => self::STATE_KEEP, - self::PASSIVE => self::STATE_KEEP, - self::NOTIFICATIONS => self::STATE_KEEP, - self::FRESHNESS => self::STATE_KEEP, - self::EVENTHANDLER => self::STATE_KEEP - ); - - /** - * Create a new PropertyModified object using the given flags - * - * @param array $flags Flags to enable/disable/keep different monitoring attributes - */ - public function __construct(array $flags) - { - foreach ($flags as $type => $value) { - if (isset($this->flags[$type])) { - $this->flags[$type] = $value; - } - } - } - - /** - * Return this object as a template for the given object type - * - * @param $type Either CommandPipe::TYPE_HOST or CommandPipe::TYPE_SERVICE - * @return array An array of external command templates for the given type representing the containers state - */ - public function getFormatString($type) - { - $cmd = array(); - foreach ($this->flags as $cmdTemplate => $setting) { - if ($setting == self::STATE_KEEP) { - continue; - } - $commandString = ($setting == self::STATE_ENABLE ? "ENABLE_" : "DISABLE_"); - $targetString = $type; - if ($type == CommandPipe::TYPE_SERVICE && $cmdTemplate == self::FRESHNESS) { - // the external command definition is inconsistent here.. - $targetString = "SERVICE"; - } - $commandString .= sprintf($cmdTemplate, $targetString); - $cmd[] = $commandString; - } - return $cmd; - } -} diff --git a/modules/monitoring/library/Monitoring/Command/ScheduleCheckCommand.php b/modules/monitoring/library/Monitoring/Command/ScheduleCheckCommand.php deleted file mode 100644 index 7908e637d..000000000 --- a/modules/monitoring/library/Monitoring/Command/ScheduleCheckCommand.php +++ /dev/null @@ -1,108 +0,0 @@ -checkTime = $checkTime; - $this->forced = $forced; - } - - /** - * Set when to schedule this check - * - * @param int $checkTime The time as UNIX timestamp - * - * @return self - */ - public function setCheckTime($checkTime) - { - $this->checkTime = (int) $checkTime; - return $this; - } - - /** - * Set whether this check is forced - * - * @param bool $state - * - * @return self - */ - public function setForced($state) - { - $this->forced = (bool) $state; - return $this; - } - - /** - * Return this command's parameters properly arranged in an array - * - * @return array - * @see Command::getArguments() - */ - public function getArguments() - { - return array($this->checkTime); - } - - /** - * Return the command as a string for the given host or all of it's services - * - * @param string $hostname The name of the host to insert - * - * @return string The string representation of the command - * @see Command::getHostCommand() - */ - public function getHostCommand($hostname) - { - return sprintf( - 'SCHEDULE%s_HOST_%s;', - $this->forced ? '_FORCED' : '', - $this->onlyServices ? 'SVC_CHECKS' : 'CHECK' - ) . implode(';', array_merge(array($hostname), $this->getArguments())); - } - - /** - * Return the command as a string for the given service - * - * @param string $hostname The name of the host to insert - * @param string $servicename The name of the service to insert - * - * @return string The string representation of the command - * @see Command::getServiceCommand() - */ - public function getServiceCommand($hostname, $servicename) - { - return sprintf('SCHEDULE%s_SVC_CHECK;', $this->forced ? '_FORCED' : '') - . implode(';', array_merge(array($hostname, $servicename), $this->getArguments())); - } -} diff --git a/modules/monitoring/library/Monitoring/Command/Service/AddServiceComment.php b/modules/monitoring/library/Monitoring/Command/Service/AddServiceComment.php deleted file mode 100644 index 926084bbf..000000000 --- a/modules/monitoring/library/Monitoring/Command/Service/AddServiceComment.php +++ /dev/null @@ -1,34 +0,0 @@ -serivce = (string) $service; - } - - public function getCommand() - { - return sprintf( - 'ADD_SVC_COMMENT;%s;%u;%s', - $this->host, - $this->persistent, - parent::getCommand() - ); - } -} diff --git a/modules/monitoring/library/Monitoring/Command/Service/ScheduleServiceDowntimeCommand.php b/modules/monitoring/library/Monitoring/Command/Service/ScheduleServiceDowntimeCommand.php deleted file mode 100644 index 4697be36b..000000000 --- a/modules/monitoring/library/Monitoring/Command/Service/ScheduleServiceDowntimeCommand.php +++ /dev/null @@ -1,59 +0,0 @@ -service = $service; - return $this; - } - - /** - * Get the service to set in downtime - * - * @return Service - */ - public function getService() - { - return $this->service; - } - - /** - * (non-PHPDoc) - * @see \Icinga\Module\Monitoring\Command\IcingaCommand::getCommandString() For the method documentation. - */ - public function getCommandString() - { - return sprintf( - '%s;%s;%s;%s', - 'SCHEDULE_SVC_DOWNTIME', - $this->service->getHostName(), - $this->service->getName(), - parent::getCommandString() - ); - } -} diff --git a/modules/monitoring/library/Monitoring/Command/SingleArgumentCommand.php b/modules/monitoring/library/Monitoring/Command/SingleArgumentCommand.php deleted file mode 100644 index 27fecd48d..000000000 --- a/modules/monitoring/library/Monitoring/Command/SingleArgumentCommand.php +++ /dev/null @@ -1,183 +0,0 @@ -value = $value; - } - - /** - * Setter for command names - * - * @param string $hostCommand - * @param string $serviceCommand - */ - public function setCommand($hostCommand, $serviceCommand) - { - $this->hostCommand = $hostCommand; - $this->serviceCommand = $serviceCommand; - } - - /** - * Set a bunch of global commands - * - * @param array $commands One or more commands to control global parameters - */ - public function setGlobalCommands(array $commands) - { - $this->globalCommands = $commands; - $this->globalCommand = true; - } - - /** - * Ignore object values upon command creation - * - * @param bool $flag - */ - public function setObjectIgnoreFlag($flag = true) - { - $this->ignoreObject = (bool) $flag; - } - - /** - * Return this command's arguments in the order expected by the actual command definition - * - * @return array - */ - public function getArguments() - { - if ($this->value !== null) { - return array($this->value); - } else { - return array(); - } - } - - /** - * Build the argument string based on objects and arguments - * - * @param array $objectNames - * - * @return string String to append to command - */ - private function getArgumentString(array $objectNames) - { - $data = array(); - if ($this->ignoreObject === true) { - $data = $this->getArguments(); - } else { - $data = array_merge($objectNames, $this->getArguments()); - } - - return implode(';', $data); - } - - /** - * Return the command as a string with the given host being inserted - * - * @param string $hostname The name of the host to insert - * - * @return string The string representation of the command - */ - public function getHostCommand($hostname) - { - return strtoupper($this->hostCommand). ';' . $this->getArgumentString(array($hostname)); - } - - /** - * Return the command as a string with the given host and service being inserted - * - * @param string $hostname The name of the host to insert - * @param string $servicename The name of the service to insert - * - * @return string The string representation of the command - */ - public function getServiceCommand($hostname, $servicename) - { - return strtoupper($this->serviceCommand) - . ';' - . $this->getArgumentString(array($hostname, $servicename)); - } - - /** - * Getter for global command if configured - * - * @param string $instance - * - * @throws ProgrammingError - * @return string - */ - public function getGlobalCommand($instance = null) - { - if (!count($this->globalCommands)) { - // This throws exception for us that globalCommand - // is not implemented properly - parent::getGlobalCommand(); - } - - if ($this->value === 'host') { - return strtoupper($this->globalCommands[0]); - } - - if ($this->value === 'service') { - if (count($this->globalCommands) < 2) { - throw new ProgrammingError('If use global values you need at least 2 global commands'); - } - - return strtoupper($this->globalCommands[1]); - } - - return strtoupper(implode(';', $this->globalCommands)); - } -} diff --git a/modules/monitoring/library/Monitoring/Command/SubmitPassiveCheckresultCommand.php b/modules/monitoring/library/Monitoring/Command/SubmitPassiveCheckresultCommand.php deleted file mode 100644 index 262987de1..000000000 --- a/modules/monitoring/library/Monitoring/Command/SubmitPassiveCheckresultCommand.php +++ /dev/null @@ -1,133 +0,0 @@ -state = $state; - $this->output = $output; - $this->perfData = $perfData; - } - - /** - * Set which plugin-state is being reported - * - * @param int $state - * - * @return self - */ - public function setState($state) - { - $this->state = (int) $state; - return $this; - } - - /** - * Set the plugin-output to include in the result - * - * @param string $output - * - * @return self - */ - public function setOutput($output) - { - $this->output = (string) $output; - return $this; - } - - /** - * Set the performance data to include in the result - * - * @param string $perfData - * @return self - */ - public function setPerformanceData($perfData) - { - $this->perfData = (string) $perfData; - return $this; - } - - /** - * Return this command's parameters properly arranged in an array - * - * @return array - * @see Command::getArguments() - */ - public function getArguments() - { - return array( - $this->state, - $this->perfData ? $this->output . '|' . $this->perfData : $this->output - ); - } - - /** - * Return the command as a string with the given host being inserted - * - * @param string $hostname The name of the host to insert - * - * @return string The string representation of the command - * @see Command::getHostCommand() - */ - public function getHostCommand($hostname) - { - return 'PROCESS_HOST_CHECK_RESULT;' . implode(';', array_merge(array($hostname), $this->getArguments())); - } - - /** - * Return the command as a string with the given host and service being inserted - * - * @param string $hostname The name of the host to insert - * @param string $servicename The name of the service to insert - * - * @return string The string representation of the command - * @see Command::getServiceCommand() - */ - public function getServiceCommand($hostname, $servicename) - { - return 'PROCESS_SERVICE_CHECK_RESULT;' . implode( - ';', - array_merge( - array($hostname, $servicename), - $this->getArguments() - ) - ); - } -}