Skip to content

Commit

Permalink
monitoring/commands: Add object command forms
Browse files Browse the repository at this point in the history
refs #6593
  • Loading branch information
lippserd committed Sep 11, 2014
1 parent 746e75e commit b4faa01
Show file tree
Hide file tree
Showing 10 changed files with 939 additions and 0 deletions.
@@ -0,0 +1,166 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}

namespace Icinga\Module\Monitoring\Form\Command\Object;

use DateTime;
use DateInterval;
use Icinga\Module\Monitoring\Command\Object\AcknowledgeProblemCommand;
use Icinga\Web\Form\Element\DateTimePicker;
use Icinga\Web\Notification;
use Icinga\Web\Request;

/**
* Form for acknowledging host or service problems
*/
class AcknowledgeProblemCommandForm extends ObjectsCommandForm
{
/**
* (non-PHPDoc)
* @see \Zend_Form::init() For the method documentation.
*/
public function init()
{
$this->setSubmitLabel(mt('monitoring', 'Acknowledge Problem'));
}

/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::createElements() For the method documentation.
*/
public function createElements(array $formData = array())
{
$this->addElements(array(
array(
'note',
'command-info',
array(
'value' => mt(
'monitoring',
'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 or service'
. ' recovers.'
)
)
),
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.'
)
)
),
array(
'checkbox',
'persistent',
array(
'label' => mt('monitoring', 'Persistent Comment'),
'description' => mt(
'monitoring',
'If you would like the comment to remain even when the acknowledgement is removed, check this'
. ' option.'
)
)
),
array(
'checkbox',
'expire',
array(
'label' => mt('monitoring', 'Use Expire Time'),
'description' => mt('monitoring', 'If the acknowledgement should expire, check this option.'),
'autosubmit' => true
)
)
));
if (isset($formData['expire']) && (bool) $formData['expire'] === true) {
$expireTime = new DateTime();
$expireTime->add(new DateInterval('PT1H'));
$this->addElement(
new DateTimePicker(
'expire_time',
array(
'label' => mt('monitoring', 'Expire Time'),
'value' => $expireTime,
'description' => mt(
'monitoring',
'Enter the expire date and time for this acknowledgement here. Icinga will delete the'
. ' acknowledgement after this time expired.'
)
)
)
);
$this->addDisplayGroup(
array('expire', 'expire_time'),
'expire-expire_time',
array(
'decorators' => array(
'FormElements',
array('HtmlTag', array('tag' => 'div', 'class' => 'control-group'))
)
)
);
}
$this->addElements(array(
array(
'checkbox',
'sticky',
array(
'label' => mt('monitoring', 'Sticky Acknowledgement'),
'value' => true,
'description' => mt(
'monitoring',
'If you want the acknowledgement to disable notifications until the host or service recovers,'
. 'check this option.'
)
)
),
array(
'checkbox',
'notify',
array(
'label' => mt('monitoring', 'Send Notification'),
'value' => true,
'description' => mt(
'monitoring',
'If you do not want an acknowledgement notification to be sent out to the appropriate contacts,'
. 'uncheck this option.'
)
)
)
));
return $this;
}

/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::onSuccess() For the method documentation.
*/
public function onSuccess(Request $request)
{
foreach ($this->objects as $object) {
/** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
$ack = new AcknowledgeProblemCommand();
$ack
->setObject($object)
->setComment($this->getElement('comment')->getValue())
->setAuthor($request->getUser()->getUsername())
->setPersistent($this->getElement('persistent')->isChecked())
->setSticky($this->getElement('sticky')->isChecked())
->setNotify($this->getElement('notify')->isChecked());
if ($this->getElement('expire')->isChecked()) {
$ack->setExpireTime($this->getElement('expire_time')->getValue()->getTimestamp());
}
$this->getTransport($request)->send($ack);
}
Notification::success(mt('monitoring', 'Acknowledging problem..'));
return true;
}
}
@@ -0,0 +1,91 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}

namespace Icinga\Module\Monitoring\Form\Command\Object;

use Icinga\Module\Monitoring\Command\Object\AddCommentCommand;
use Icinga\Web\Notification;
use Icinga\Web\Request;

/**
* Form for adding host or service comments
*/
class AddCommentCommandForm extends ObjectsCommandForm
{
/**
* (non-PHPDoc)
* @see \Zend_Form::init() For the method documentation.
*/
public function init()
{
$this->setSubmitLabel(mt('monitoring', 'Add Comment'));
}

/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::createElements() For the method documentation.
*/
public function createElements(array $formData = array())
{
$this->addElements(array(
array(
'note',
'command-info',
array(
'value' => mt(
'monitoring',
'This command is used to add host or service comments.'
)
)
),
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.'
)
)
),
array(
'checkbox',
'persistent',
array(
'label' => mt('monitoring', 'Persistent'),
'value' => true,
'description' => mt(
'monitoring',
'If you uncheck this option, the comment will automatically be deleted the next time Icinga is'
. ' restarted.'
)
)
)
));
return $this;
}

/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::onSuccess() For the method documentation.
*/
public function onSuccess(Request $request)
{
foreach ($this->objects as $object) {
/** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
$comment = new AddCommentCommand();
$comment->setObject($object);
$comment->setComment($this->getElement('comment')->getValue());
$comment->setAuthor($request->getUser()->getUsername());
$comment->setPersistent((bool) $this->getElement('persistent')->getValue());
$this->getTransport($request)->send($comment);
}
Notification::success(mt('monitoring', 'Adding comment..'));
return true;
}
}
@@ -0,0 +1,51 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}

namespace Icinga\Module\Monitoring\Form\Command\Object;

use Icinga\Module\Monitoring\Command\Object\ScheduleHostCheckCommand;
use Icinga\Module\Monitoring\Command\Object\ScheduleServiceCheckCommand;
use Icinga\Module\Monitoring\Form\Command\Object\ObjectsCommandForm;
use Icinga\Web\Notification;
use Icinga\Web\Request;

/**
* Form for immediately checking hosts or services
*/
class CheckNowCommandForm extends ObjectsCommandForm
{

/**
* (non-PHPDoc)
* @see \Zend_Form::init() For the method documentation.
*/
public function init()
{
$this->setSubmitLabel(mt('monitoring', 'Check Now'));
$this->setAttrib('class', 'inline link-like');
}

/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::onSuccess() For the method documentation.
*/
public function onSuccess(Request $request)
{
foreach ($this->objects as $object) {
/** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
if ($object->getType() === $object::TYPE_HOST) {
$check = new ScheduleHostCheckCommand();
} else {
$check = new ScheduleServiceCheckCommand();
}
$check
->setObject($object)
->setForced()
->setCheckTime(time());
$this->getTransport($request)->send($check);
}
Notification::success(mt('monitoring', 'Scheduling check..'));
return true;
}
}
@@ -0,0 +1,61 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}

namespace Icinga\Module\Monitoring\Form\Command\Object;

use Icinga\Module\Monitoring\Command\Object\DeleteCommentCommand;
use Icinga\Web\Notification;
use Icinga\Web\Request;

/**
* Form for deleting host or service comments
*/
class DeleteCommentCommandForm extends ObjectsCommandForm
{
/**
* (non-PHPDoc)
* @see \Zend_Form::init() For the method documentation.
*/
public function init()
{
$this->setSubmitLabel(mt('monitoring', 'X'));
$this->setAttrib('class', 'inline link-like');
}

/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::createElements() For the method documentation.
*/
public function createElements(array $formData = array())
{
$this->addElements(array(
array(
'hidden',
'comment_id',
array(
'required' => true
)
)
));
return $this;
}

/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::onSuccess() For the method documentation.
*/
public function onSuccess(Request $request)
{
foreach ($this->objects as $object) {
/** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
$delComment = new DeleteCommentCommand();
$delComment
->setObject($object)
->setCommentId($this->getElement('comment_id')->getValue());
$this->getTransport($request)->send($delComment);
}
Notification::success(mt('monitoring', 'Deleting comment..'));
return true;
}
}

0 comments on commit b4faa01

Please sign in to comment.