mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-23 05:44:36 +02:00
monitoring/commands: Remove superseded command forms and command objects
refs #6593
This commit is contained in:
parent
beecf16ad0
commit
3f216f26ff
@ -1,154 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Form\Command;
|
||||
|
||||
use Icinga\Web\Form\Element\DateTimePicker;
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
use Icinga\Module\Monitoring\Command\AcknowledgeCommand;
|
||||
|
||||
/**
|
||||
* Form for problem acknowledgements
|
||||
*/
|
||||
class AcknowledgeForm extends CommandForm
|
||||
{
|
||||
/**
|
||||
* Create the form's elements
|
||||
*/
|
||||
protected function create()
|
||||
{
|
||||
$this->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')
|
||||
);
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Form\Command;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
use Icinga\Module\Monitoring\Command\AddCommentCommand;
|
||||
|
||||
/**
|
||||
* Form for adding comment commands
|
||||
*/
|
||||
class CommentForm extends CommandForm
|
||||
{
|
||||
/**
|
||||
* Create the form's elements
|
||||
*/
|
||||
protected function create()
|
||||
{
|
||||
$this->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')
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,153 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Form\Command\Common;
|
||||
|
||||
use DateTime;
|
||||
use DateInterval;
|
||||
use Icinga\Module\Monitoring\Form\Command\CommandForm;
|
||||
use Icinga\Web\Form\Element\DateTimePicker;
|
||||
use Icinga\Web\Form\Element\Number;
|
||||
|
||||
/**
|
||||
* Base class for downtime command forms on an Icinga instance
|
||||
*/
|
||||
abstract class ScheduleDowntimeCommandForm extends CommandForm
|
||||
{
|
||||
/**
|
||||
* Fixed downtime
|
||||
*/
|
||||
const FIXED = 'fixed';
|
||||
|
||||
/**
|
||||
* Flexible downtime
|
||||
*/
|
||||
const FLEXIBLE = 'flexible';
|
||||
|
||||
/**
|
||||
* (non-PHPDoc)
|
||||
* @see \Icinga\Web\Form::createElements() For the method documentation.
|
||||
*/
|
||||
public function createElements(array $formData = array())
|
||||
{
|
||||
$start = new DateTime;
|
||||
$end = clone $start;
|
||||
$end->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;
|
||||
}
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Form\Command;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
use Icinga\Module\Monitoring\Command\CustomNotificationCommand;
|
||||
|
||||
/**
|
||||
* For for command CustomNotification
|
||||
*/
|
||||
class CustomNotificationForm extends CommandForm
|
||||
{
|
||||
/**
|
||||
* Create the form's elements
|
||||
*/
|
||||
protected function create()
|
||||
{
|
||||
$this->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')
|
||||
);
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Form\Command;
|
||||
|
||||
use Icinga\Module\Monitoring\Command\DelayNotificationCommand;
|
||||
|
||||
/**
|
||||
* Form for the delay notification command
|
||||
*/
|
||||
class DelayNotificationForm extends CommandForm
|
||||
{
|
||||
/**
|
||||
* Maximum delay amount in minutes
|
||||
*/
|
||||
const MAX_DELAY = 1440; // 1 day
|
||||
|
||||
/**
|
||||
* Create the form's elements
|
||||
*/
|
||||
protected function create()
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Form\Command;
|
||||
|
||||
use Icinga\Module\Monitoring\Command\DisableNotificationWithExpireCommand;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
use Icinga\Web\Form\Element\DateTimePicker;
|
||||
|
||||
/**
|
||||
* Provide expiration when notifications should be disabled
|
||||
*/
|
||||
class DisableNotificationWithExpireForm extends CommandForm
|
||||
{
|
||||
/**
|
||||
* Build form content
|
||||
*/
|
||||
protected function create()
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
@ -1,147 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Form\Command;
|
||||
|
||||
use Icinga\Web\Form\Element\TriStateCheckbox;
|
||||
use Icinga\Web\Form;
|
||||
use Zend_Form_Element_Hidden;
|
||||
use Zend_Form;
|
||||
|
||||
/**
|
||||
* A form to edit multiple command flags of multiple commands at once. When some commands have
|
||||
* different flag values, these flags will be displayed as an undefined state,
|
||||
* in a tri-state checkbox.
|
||||
*/
|
||||
class MultiCommandFlagForm extends Form {
|
||||
|
||||
/**
|
||||
* The Suffix used to mark the old values in the form-field
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const OLD_VALUE_MARKER = '_old_value';
|
||||
|
||||
/**
|
||||
* The object properties to change
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $flags;
|
||||
|
||||
/**
|
||||
* The current values of this form
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $values;
|
||||
|
||||
/**
|
||||
* Create a new MultiCommandFlagForm
|
||||
*
|
||||
* @param array $flags The flags that will be used. Should contain the
|
||||
* names of the used property keys.
|
||||
*/
|
||||
public function __construct(array $flags)
|
||||
{
|
||||
$this->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');
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Form\Command;
|
||||
|
||||
use Zend_Form_Element_Checkbox;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
use Icinga\Web\Form\Element\DateTimePicker;
|
||||
use Icinga\Module\Monitoring\Command\ScheduleCheckCommand;
|
||||
|
||||
/**
|
||||
* Form for scheduling checks
|
||||
*/
|
||||
class RescheduleNextCheckForm extends WithChildrenCommandForm
|
||||
{
|
||||
/**
|
||||
* Create the form's elements
|
||||
*/
|
||||
protected function create()
|
||||
{
|
||||
$this->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());
|
||||
}
|
||||
}
|
@ -1,336 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Form\Command;
|
||||
|
||||
use Icinga\Module\Monitoring\Object\MonitoredObject;
|
||||
use Zend_Form_Element_Text;
|
||||
use Zend_Validate_GreaterThan;
|
||||
use Zend_Validate_Digits;
|
||||
use Icinga\Web\Form\Element\DateTimePicker;
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
use Icinga\Module\Monitoring\Command\ScheduleDowntimeCommand;
|
||||
use Icinga\Module\Monitoring\Object\Service;
|
||||
use Icinga\Web\Url;
|
||||
|
||||
/**
|
||||
* Form for scheduling downtimes
|
||||
*/
|
||||
class ScheduleDowntimeForm extends WithChildrenCommandForm
|
||||
{
|
||||
/**
|
||||
* Type constant for fixed downtimes
|
||||
*/
|
||||
const TYPE_FIXED = 'fixed';
|
||||
|
||||
/**
|
||||
* Type constant for flexible downtimes
|
||||
*/
|
||||
const TYPE_FLEXIBLE = 'flexible';
|
||||
|
||||
private $downtimes;
|
||||
|
||||
/**
|
||||
* Initialize form
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->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
|
||||
);
|
||||
}
|
||||
}
|
@ -1,113 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Form\Command\Service;
|
||||
|
||||
use Icinga\Module\Monitoring\Command\Service\ScheduleServiceDowntimeCommand;
|
||||
use Icinga\Module\Monitoring\Form\Command\Common\ScheduleDowntimeCommandForm;
|
||||
use Icinga\Module\Monitoring\Object\Service;
|
||||
use Icinga\Web\Notification;
|
||||
use Icinga\Web\Request;
|
||||
|
||||
/**
|
||||
* Form for scheduling a service downtime on an Icinga instance
|
||||
*/
|
||||
class ScheduleServiceDowntimeCommandForm extends ScheduleDowntimeCommandForm
|
||||
{
|
||||
/**
|
||||
* Service to set in downtime
|
||||
*
|
||||
* @var Service
|
||||
*/
|
||||
protected $service;
|
||||
|
||||
/**
|
||||
* Set the service to set in downtime
|
||||
*
|
||||
* @param Service $service
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setService(Service $service)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
@ -1,169 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Form\Command;
|
||||
|
||||
use Zend_Controller_Request_Abstract;
|
||||
use Zend_Form_Element_Hidden;
|
||||
use Icinga\Module\Monitoring\Command\AcknowledgeCommand;
|
||||
use Icinga\Module\Monitoring\Command\SingleArgumentCommand;
|
||||
|
||||
/**
|
||||
* Sending commands to core which only have one value
|
||||
*/
|
||||
class SingleArgumentCommandForm extends CommandForm
|
||||
{
|
||||
/**
|
||||
* Name of host command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $hostCommand;
|
||||
|
||||
/**
|
||||
* Name of service command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $serviceCommand;
|
||||
|
||||
/**
|
||||
* Name of global command
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $globalCommands = array();
|
||||
|
||||
/**
|
||||
* Name of the parameter used as value
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $parameterName;
|
||||
|
||||
/**
|
||||
* Value of used parameter
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private $parameterValue;
|
||||
|
||||
/**
|
||||
* Flag to ignore object name
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $ignoreObject = false;
|
||||
|
||||
/**
|
||||
* Set command names
|
||||
*
|
||||
* @param string $hostCommand Name of host command
|
||||
* @param string $serviceCommand Name of service command
|
||||
*/
|
||||
public function setCommand($hostCommand, $serviceCommand = null)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
@ -1,177 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Form\Command;
|
||||
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
|
||||
/**
|
||||
* Form for submitting passive check results
|
||||
*/
|
||||
class SubmitPassiveCheckResultForm extends CommandForm
|
||||
{
|
||||
/**
|
||||
* Type constant for host form
|
||||
*/
|
||||
const TYPE_HOST = 'host';
|
||||
|
||||
/**
|
||||
* Type constant for service form
|
||||
*/
|
||||
const TYPE_SERVICE = 'service';
|
||||
|
||||
/**
|
||||
* List of choices for plugin states
|
||||
* @var array
|
||||
*/
|
||||
private static $options = array();
|
||||
|
||||
/**
|
||||
* Type of form
|
||||
* @var string
|
||||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* Setup plugin states
|
||||
*
|
||||
* @see Zend_Form::init
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if (!count(self::$options)) {
|
||||
self::$options = array(
|
||||
self::TYPE_HOST => 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')
|
||||
);
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Form\Command;
|
||||
|
||||
/**
|
||||
* Base class for command forms which allow to propagate the command to child objects too
|
||||
*/
|
||||
abstract class WithChildrenCommandForm extends CommandForm
|
||||
{
|
||||
/**
|
||||
* Whether to include all objects beyond as well
|
||||
* @var bool
|
||||
*/
|
||||
private $withChildren = false;
|
||||
|
||||
/**
|
||||
* Setter for withChildren
|
||||
*
|
||||
* @param bool $flag
|
||||
*/
|
||||
public function setWithChildren($flag = true)
|
||||
{
|
||||
$this->withChildren = $flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for withChildren
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getWithChildren()
|
||||
{
|
||||
return $this->withChildren;
|
||||
}
|
||||
}
|
@ -1,164 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Command;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Command;
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
|
||||
/**
|
||||
* Command for acknowledging an object
|
||||
*/
|
||||
class AcknowledgeCommand extends Command
|
||||
{
|
||||
/**
|
||||
* When this acknowledgement should expire
|
||||
*
|
||||
* @var int The time as UNIX timestamp or -1 if it shouldn't expire
|
||||
*/
|
||||
private $expireTime = -1;
|
||||
|
||||
/**
|
||||
* The comment associated to this acknowledgment
|
||||
*
|
||||
* @var Comment
|
||||
*/
|
||||
private $comment;
|
||||
|
||||
/**
|
||||
* Whether to set the notify flag of this acknowledgment
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $notify;
|
||||
|
||||
/**
|
||||
* Whether this acknowledgement is of type sticky
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $sticky;
|
||||
|
||||
/**
|
||||
* Initialise a new acknowledgement command object
|
||||
*
|
||||
* @param Comment $comment The comment to use for this acknowledgement
|
||||
* @param int $expire The expire time or -1 of not expiring
|
||||
* @param bool $notify Whether to set the notify flag
|
||||
* @param bool $sticky Whether to set the sticky flag
|
||||
*/
|
||||
public function __construct(Comment $comment, $expire = -1, $notify = false, $sticky = false)
|
||||
{
|
||||
$this->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));
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Command;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Command;
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
|
||||
/**
|
||||
* Icinga Command for adding comments
|
||||
*
|
||||
* @see Command
|
||||
*/
|
||||
class AddCommentCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The comment associated to this command
|
||||
*
|
||||
* @var Comment
|
||||
*/
|
||||
private $comment;
|
||||
|
||||
/**
|
||||
* Initialise a new command object to add comments
|
||||
*
|
||||
* @param Comment $comment The comment to use for this acknowledgement
|
||||
*/
|
||||
public function __construct(Comment $comment)
|
||||
{
|
||||
$this->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());
|
||||
}
|
||||
}
|
@ -1,603 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Protocol\Commandpipe;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Transport\Transport;
|
||||
use Icinga\Protocol\Commandpipe\Transport\LocalPipe;
|
||||
use Icinga\Protocol\Commandpipe\Transport\SecureShell;
|
||||
|
||||
/**
|
||||
* Class to the access icinga CommandPipe via a @see Icinga\Protocol\Commandpipe\Transport.php
|
||||
*
|
||||
* Will be configured using the instances.ini
|
||||
*/
|
||||
class CommandPipe
|
||||
{
|
||||
/**
|
||||
* The name of this class as defined in the instances.ini
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $name = "";
|
||||
|
||||
/**
|
||||
* The underlying @see Icinga\Protocol\Commandpipe\Transport.php class handling communication with icinga
|
||||
*
|
||||
* @var Icinga\Protocol\Commandpipe\Transport
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* Create a new CommandPipe class which accesses the icinga.cmd pipe as defined in $config
|
||||
*
|
||||
* @param \Zend_Config $config
|
||||
*/
|
||||
public function __construct(\Zend_Config $config)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Protocol\Commandpipe;
|
||||
|
||||
/**
|
||||
* Container for comment information that can be send to Icinga's external command pipe
|
||||
*/
|
||||
class Comment
|
||||
{
|
||||
/**
|
||||
* Whether this comment is persistent or not
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $persistent;
|
||||
|
||||
/**
|
||||
* The author of this comment
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $author;
|
||||
|
||||
/**
|
||||
* The text of this comment
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $content;
|
||||
|
||||
/**
|
||||
* Create a new comment object
|
||||
*
|
||||
* @param string $author The name of the comment's author
|
||||
* @param string $content The text for this comment
|
||||
* @param bool $persistent Whether this comment should be persistent or not
|
||||
*/
|
||||
public function __construct($author, $content, $persistent = false)
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Command\Common;
|
||||
|
||||
/**
|
||||
* Add a comment to a host or service
|
||||
*/
|
||||
class AddCommentCommand extends WithCommentCommand
|
||||
{
|
||||
/**
|
||||
* (non-PHPDoc)
|
||||
* @see \Icinga\Module\Monitoring\Command\Common\ObjectCommand::$allowedObjects For the property documentation.
|
||||
*/
|
||||
protected $allowedObjects = array(
|
||||
self::TYPE_HOST,
|
||||
self::TYPE_SERVICE
|
||||
);
|
||||
|
||||
/**
|
||||
* Whether the comment is persistent
|
||||
*
|
||||
* Persistent comments are not lost the next time the monitoring host restarts.
|
||||
*/
|
||||
protected $persistent;
|
||||
|
||||
/**
|
||||
* Set whether the comment is persistent
|
||||
*
|
||||
* @param bool $persistent
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPersistent($persistent = true)
|
||||
{
|
||||
$this->persistent = $persistent;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the comment persistent?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getPersistent()
|
||||
{
|
||||
return $this->persistent;
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Command\Common;
|
||||
|
||||
use Icinga\Module\Monitoring\Command\IcingaCommand;
|
||||
use Icinga\Module\Monitoring\Object\MonitoredObject;
|
||||
|
||||
/**
|
||||
* Base class for commands that involve a monitored object, i.e. a host or service
|
||||
*/
|
||||
abstract class ObjectCommand extends IcingaCommand
|
||||
{
|
||||
/**
|
||||
* Type host
|
||||
*/
|
||||
const TYPE_HOST = MonitoredObject::TYPE_HOST;
|
||||
|
||||
/**
|
||||
* Type service
|
||||
*/
|
||||
const TYPE_SERVICE = MonitoredObject::TYPE_SERVICE;
|
||||
|
||||
/**
|
||||
* Allowed Icinga object types for the command
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $allowedObjects = array();
|
||||
|
||||
/**
|
||||
* Involved object
|
||||
*
|
||||
* @var MonitoredObject
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Set the involved object
|
||||
*
|
||||
* @param MonitoredObject $object
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setObject(MonitoredObject $object)
|
||||
{
|
||||
$object->assertOneOf($this->allowedObjects);
|
||||
$this->object = $object;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the involved object
|
||||
*
|
||||
* @return MonitoredObject
|
||||
*/
|
||||
public function getObject()
|
||||
{
|
||||
return $this->object;
|
||||
}
|
||||
}
|
@ -1,193 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Command\Common;
|
||||
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
* Base class for commands scheduling downtimes
|
||||
*/
|
||||
abstract class ScheduleDowntimeCommand extends AddCommentCommand
|
||||
{
|
||||
/**
|
||||
* Downtime starts at the exact time specified
|
||||
*
|
||||
* If `Downtime::$flexible' is set to true, the time between `Downtime::$start' and `Downtime::$end' at which a
|
||||
* host or service transitions to a problem state determines the time at which the downtime actually starts.
|
||||
* The downtime will then last for `Downtime::$duration' seconds.
|
||||
*
|
||||
* @var DateTime
|
||||
*/
|
||||
protected $start;
|
||||
|
||||
/**
|
||||
* Downtime ends at the exact time specified
|
||||
*
|
||||
* If `Downtime::$flexible' is set to true, the time between `Downtime::$start' and `Downtime::$end' at which a
|
||||
* host or service transitions to a problem state determines the time at which the downtime actually starts.
|
||||
* The downtime will then last for `Downtime::$duration' seconds.
|
||||
*
|
||||
* @var DateTime
|
||||
*/
|
||||
protected $end;
|
||||
|
||||
/**
|
||||
* Whether it's a flexible downtime
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $flexible = false;
|
||||
|
||||
/**
|
||||
* ID of the downtime which triggers this downtime
|
||||
*
|
||||
* The start of this downtime is triggered by the start of the other scheduled host or service downtime.
|
||||
*
|
||||
* @var int|null
|
||||
*/
|
||||
protected $triggerId;
|
||||
|
||||
/**
|
||||
* The duration in seconds the downtime must last if it's a flexible downtime
|
||||
*
|
||||
* If `Downtime::$flexible' is set to true, the downtime will last for the duration in seconds specified, even
|
||||
* if the host or service recovers before the downtime expires.
|
||||
*
|
||||
* @var int|null
|
||||
*/
|
||||
protected $duration;
|
||||
|
||||
/**
|
||||
* Set the date and time when the downtime should start
|
||||
*
|
||||
* @param DateTime $start
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setStart(DateTime $start)
|
||||
{
|
||||
$this->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()
|
||||
);
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Command\Common;
|
||||
|
||||
use Icinga\Module\Monitoring\Command\IcingaCommand;
|
||||
|
||||
/**
|
||||
* Enable/disable features of an Icinga instance
|
||||
*/
|
||||
abstract class ToggleFeature extends IcingaCommand
|
||||
{
|
||||
/**
|
||||
* Whether the feature should be enabled or disabled
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $enable = true;
|
||||
|
||||
/**
|
||||
* Enable the feature
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function enable()
|
||||
{
|
||||
$this->enable = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the feature
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function disable()
|
||||
{
|
||||
$this->enable = false;
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Command\Common;
|
||||
|
||||
/**
|
||||
* Base class for commands adding comments
|
||||
*/
|
||||
abstract class WithCommentCommand extends ObjectCommand
|
||||
{
|
||||
/**
|
||||
* Author of the comment
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $author;
|
||||
|
||||
/**
|
||||
* Comment
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $comment;
|
||||
|
||||
/**
|
||||
* Set the author
|
||||
*
|
||||
* @param string $author
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAuthor($author)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
@ -1,139 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Command;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Command;
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
|
||||
/**
|
||||
* Command to send a custom notification
|
||||
*/
|
||||
class CustomNotificationCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The comment associated with this notification
|
||||
*
|
||||
* @var Comment
|
||||
*/
|
||||
private $comment;
|
||||
|
||||
/**
|
||||
* Whether this notification is forced
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $forced;
|
||||
|
||||
/**
|
||||
* Whether this notification is also sent to escalation-contacts
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $broadcast;
|
||||
|
||||
/**
|
||||
* Initialise a new custom notification command object
|
||||
*
|
||||
* @param Comment $comment The comment for this notification
|
||||
* @param bool $forced Whether this notificatin is forced
|
||||
* @param bool $broadcast Whether this notification is sent to all contacts
|
||||
*/
|
||||
public function __construct(Comment $comment, $forced = false, $broadcast = false)
|
||||
{
|
||||
$this->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()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Command;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Command;
|
||||
|
||||
/**
|
||||
* Command to delay a notification
|
||||
*/
|
||||
class DelayNotificationCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The delay in seconds
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $delay;
|
||||
|
||||
/**
|
||||
* Initialise a new delay notification command object
|
||||
*
|
||||
* @param int $delay How long, in seconds, notifications should be delayed
|
||||
*/
|
||||
public function __construct($delay)
|
||||
{
|
||||
$this->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()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Command;
|
||||
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Protocol\Commandpipe\Command;
|
||||
|
||||
/**
|
||||
* Disable notifications with expire
|
||||
*/
|
||||
class DisableNotificationWithExpireCommand extends Command
|
||||
{
|
||||
/**
|
||||
* Timestamp when deactivation should expire
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $expirationTimestamp;
|
||||
|
||||
/**
|
||||
* Create a new instance of this command
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// There is now object specific implementation, only global
|
||||
$this->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())
|
||||
);
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Protocol\Commandpipe\Exception;
|
||||
|
||||
/**
|
||||
* Exception class for unknown/invalid external commands
|
||||
*/
|
||||
class InvalidCommandException extends \Exception
|
||||
{
|
||||
}
|
@ -1,110 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Protocol\Commandpipe;
|
||||
|
||||
/**
|
||||
* Container class to modify a few monitoring attributes at oncee
|
||||
*
|
||||
*/
|
||||
class PropertyModifier
|
||||
{
|
||||
/**
|
||||
* Set an attribute to be enabled in the command
|
||||
*/
|
||||
const STATE_ENABLE = 1;
|
||||
|
||||
/**
|
||||
* Set an attribute to be disabled in the command
|
||||
*/
|
||||
const STATE_DISABLE = 0;
|
||||
|
||||
/**
|
||||
* Set an attribute to not be modified in the command
|
||||
*/
|
||||
const STATE_KEEP = -1;
|
||||
|
||||
/**
|
||||
* Template for enabling/disabling flap detection
|
||||
*/
|
||||
const FLAPPING = "%s_FLAP_DETECTION";
|
||||
|
||||
/**
|
||||
* Template for enabling/disabling active checks
|
||||
*/
|
||||
const ACTIVE = "%s_CHECK";
|
||||
|
||||
/**
|
||||
* Template for enabling/disabling passive checks
|
||||
*/
|
||||
const PASSIVE = "PASSIVE_%s_CHECKS";
|
||||
|
||||
/**
|
||||
* Template for enabling/disabling notification
|
||||
*/
|
||||
const NOTIFICATIONS = "%s_NOTIFICATIONS";
|
||||
|
||||
/**
|
||||
* Template for enabling/disabling freshness checks
|
||||
*/
|
||||
const FRESHNESS = "%s_FRESHNESS_CHECKS";
|
||||
|
||||
/**
|
||||
* Template for enabling/disabling event handler
|
||||
*/
|
||||
const EVENTHANDLER = "%s_EVENT_HANDLER";
|
||||
|
||||
/**
|
||||
* The state that will be applied when fetching this container for an object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $flags = array(
|
||||
self::FLAPPING => 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;
|
||||
}
|
||||
}
|
@ -1,108 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Command;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Command;
|
||||
|
||||
/**
|
||||
* Command to schedule checks
|
||||
*/
|
||||
class ScheduleCheckCommand extends Command
|
||||
{
|
||||
/**
|
||||
* When this check is scheduled
|
||||
*
|
||||
* @var int The time as UNIX timestamp
|
||||
*/
|
||||
private $checkTime;
|
||||
|
||||
/**
|
||||
* Whether this check is forced
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $forced;
|
||||
|
||||
/**
|
||||
* Initialises a new command object to schedule checks
|
||||
*
|
||||
* @param int $checkTime The time as UNIX timestamp
|
||||
* @param bool $forced Whether this check is forced
|
||||
*/
|
||||
public function __construct($checkTime, $forced = false)
|
||||
{
|
||||
$this->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()));
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Command\Service;
|
||||
|
||||
use Icinga\Module\Monitoring\Command\Common\Comment;
|
||||
|
||||
class AddServiceComment extends Comment
|
||||
{
|
||||
protected $service;
|
||||
|
||||
/**
|
||||
* Whether the comment is persistent
|
||||
*
|
||||
* Persistent comments are not lost the next time the monitoring host restarts.
|
||||
*/
|
||||
protected $persistent;
|
||||
|
||||
public function __construct($service)
|
||||
{
|
||||
$this->serivce = (string) $service;
|
||||
}
|
||||
|
||||
public function getCommand()
|
||||
{
|
||||
return sprintf(
|
||||
'ADD_SVC_COMMENT;%s;%u;%s',
|
||||
$this->host,
|
||||
$this->persistent,
|
||||
parent::getCommand()
|
||||
);
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Command\Service;
|
||||
|
||||
use Icinga\Module\Monitoring\Command\Common\ScheduleDowntimeCommand;
|
||||
use Icinga\Module\Monitoring\Object\Service;
|
||||
|
||||
/**
|
||||
* Schedule a service downtime on an Icinga instance
|
||||
*/
|
||||
class ScheduleServiceDowntimeCommand extends ScheduleDowntimeCommand
|
||||
{
|
||||
/**
|
||||
* Service to set in downtime
|
||||
*
|
||||
* @var Service
|
||||
*/
|
||||
protected $service;
|
||||
|
||||
/**
|
||||
* Set the service to set in downtime
|
||||
*
|
||||
* @param Service $service
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setService(Service $service)
|
||||
{
|
||||
$this->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()
|
||||
);
|
||||
}
|
||||
}
|
@ -1,183 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Command;
|
||||
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Protocol\Commandpipe\Command;
|
||||
|
||||
/**
|
||||
* Configurable simple command
|
||||
*/
|
||||
class SingleArgumentCommand extends Command
|
||||
{
|
||||
/**
|
||||
* Value used for this command
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* Name of host command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $hostCommand;
|
||||
|
||||
/**
|
||||
* Name of service command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $serviceCommand;
|
||||
|
||||
/**
|
||||
* Name of global command
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $globalCommands = array();
|
||||
|
||||
/**
|
||||
* Ignore host in command string
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $ignoreObject = false;
|
||||
|
||||
/**
|
||||
* Setter for this value
|
||||
*
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->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));
|
||||
}
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Command;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Command;
|
||||
|
||||
/**
|
||||
* Command to submit passive check results
|
||||
*/
|
||||
class SubmitPassiveCheckresultCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The plugin-state that is being reported
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $state;
|
||||
|
||||
/**
|
||||
* The output that is included
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $output;
|
||||
|
||||
/**
|
||||
* The performance data that is included
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $perfData;
|
||||
|
||||
/**
|
||||
* Initialises a new command object to submit a passive check result
|
||||
*
|
||||
* @param int $state The plugin-state to report
|
||||
* @param string $output The plugin-output to include
|
||||
* @param string $perfData The performance data to include
|
||||
*/
|
||||
public function __construct($state, $output, $perfData)
|
||||
{
|
||||
$this->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()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user