Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command send custom notification to monitoring module
refs #8644
- Loading branch information
Showing
9 changed files
with
311 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
modules/monitoring/application/forms/Command/Object/SendCustomNotificationCommandForm.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */ | ||
|
||
namespace Icinga\Module\Monitoring\Forms\Command\Object; | ||
|
||
use Icinga\Module\Monitoring\Command\Object\SendCustomNotificationCommand; | ||
use Icinga\Web\Notification; | ||
|
||
/** | ||
* Form to send custom notifications | ||
*/ | ||
class SendCustomNotificationCommandForm extends ObjectsCommandForm | ||
{ | ||
/** | ||
* Initialize this form | ||
*/ | ||
public function init() | ||
{ | ||
$this->addDescription( | ||
$this->translate( | ||
'This command is used to send custom notifications for hosts or' | ||
. ' services.' | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* (non-PHPDoc) | ||
* @see \Icinga\Web\Form::getSubmitLabel() For the method documentation. | ||
*/ | ||
public function getSubmitLabel() | ||
{ | ||
return $this->translatePlural( | ||
'Send custom notification', | ||
'Send custom notifications', | ||
count($this->objects) | ||
); | ||
} | ||
|
||
/** | ||
* (non-PHPDoc) | ||
* @see \Icinga\Web\Form::createElements() For the method documentation. | ||
*/ | ||
public function createElements(array $formData = array()) | ||
{ | ||
$this->addElements(array( | ||
array( | ||
'textarea', | ||
'comment', | ||
array( | ||
'required' => true, | ||
'label' => $this->translate('Comment'), | ||
'description' => $this->translate( | ||
'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', | ||
'forced', | ||
array( | ||
'label' => $this->translate('Forced'), | ||
'value' => false, | ||
'description' => $this->translate( | ||
'If you check this option, a notification is sent' | ||
. 'regardless of the current time and whether' | ||
. ' notifications are enabled.' | ||
) | ||
) | ||
), | ||
array( | ||
'checkbox', | ||
'broadcast', | ||
array( | ||
'label' => $this->translate('Broadcast'), | ||
'value' => false, | ||
'description' => $this->translate( | ||
'If you check this option, a notification is sent to' | ||
. ' all normal and escalated contacts.' | ||
) | ||
) | ||
) | ||
)); | ||
return $this; | ||
} | ||
|
||
/** | ||
* (non-PHPDoc) | ||
* @see \Icinga\Web\Form::onSuccess() For the method documentation. | ||
*/ | ||
public function onSuccess() | ||
{ | ||
foreach ($this->objects as $object) { | ||
/** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */ | ||
$comment = new SendCustomNotificationCommand(); | ||
$comment->setObject($object); | ||
$comment->setComment($this->getElement('comment')->getValue()); | ||
$comment->setAuthor($this->request->getUser()->getUsername()); | ||
$comment->setForced($this->getElement('forced')->isChecked()); | ||
$comment->setBroadcast($this->getElement('broadcast')->isChecked()); | ||
$this->getTransport($this->request)->send($comment); | ||
} | ||
Notification::success($this->translatePlural( | ||
'Send custom notification..', | ||
'Send custom notifications..', | ||
count($this->objects) | ||
)); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 49 additions & 25 deletions
74
modules/monitoring/application/views/scripts/show/components/notifications.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,59 @@ | ||
<?php | ||
|
||
// We are not interested in notifications for OK or pending objects | ||
if (in_array((int) $object->state, array(0, 99))) { | ||
return; | ||
} | ||
|
||
?> | ||
<tr> | ||
<th><?= $this->translate('Notifications') ?></th> | ||
<td> | ||
<?php if ($this->hasPermission('monitoring/command/send-custom-notification')) { | ||
if ($object->getType() === $object::TYPE_HOST) { | ||
$ackLink = $this->href( | ||
'monitoring/host/send-custom-notification', | ||
array('host' => $object->getName()) | ||
); | ||
} else { | ||
$ackLink = $this->href( | ||
'monitoring/service/send-custom-notification', | ||
array('host' => $object->getHost()->getName(), 'service' => $object->getName()) | ||
); | ||
} | ||
?> | ||
<?= $this->qlink( | ||
$this->translate('Send Custom Notification'), | ||
$ackLink, | ||
null, | ||
array( | ||
'icon' => 'comment', | ||
'data-base-target' => '_self', | ||
'title' => $this->translate( | ||
'Send a custom notification, share information about the' | ||
. ' object to contacts.' | ||
) | ||
) | ||
); ?> | ||
<?php } ?> | ||
<?php | ||
// We are not interested in notifications for OK or pending objects | ||
if (! in_array((int) $object->state, array(0, 99))) { | ||
|
||
if ($object->current_notification_number > 0) { | ||
if ((int) $object->current_notification_number === 1) { | ||
$msg = sprintf( | ||
$this->translate('A notication has been sent for this issue %s ago'), | ||
$this->timeSince($object->last_notification) | ||
); | ||
if ($object->current_notification_number > 0) { | ||
if ((int) $object->current_notification_number === 1) { | ||
$msg = sprintf( | ||
$this->translate('A notication has been sent for this issue %s ago'), | ||
$this->timeSince($object->last_notification) | ||
); | ||
} else { | ||
$msg = sprintf( | ||
$this->translate('%s notications have been sent for this issue'), | ||
$object->current_notification_number | ||
) . '<br />' . sprintf( | ||
$this->translate('The last one occured %s ago'), | ||
$this->timeSince($object->last_notification) | ||
); | ||
} | ||
echo '- ' . $msg; | ||
} else { | ||
$msg = sprintf( | ||
$this->translate('%s notications have been sent for this issue'), | ||
$object->current_notification_number | ||
) . '<br />' . sprintf( | ||
$this->translate('The last one occured %s ago'), | ||
$this->timeSince($object->last_notification) | ||
); | ||
echo '(' | ||
. $this->translate('No notification has been sent for this issue') | ||
. ')'; | ||
} | ||
echo $msg; | ||
} else { | ||
echo $this->translate('No notification has been sent for this issue'); | ||
} | ||
?> | ||
</td> | ||
</tr> | ||
</tr> |
Oops, something went wrong.