commit
31d0641658
|
@ -6,6 +6,7 @@ use Icinga\Module\Monitoring\Forms\Command\Object\AddCommentCommandForm;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm;
|
use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostCheckCommandForm;
|
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostCheckCommandForm;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostDowntimeCommandForm;
|
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostDowntimeCommandForm;
|
||||||
|
use Icinga\Module\Monitoring\Forms\Command\Object\SendCustomNotificationCommandForm;
|
||||||
use Icinga\Module\Monitoring\Object\Host;
|
use Icinga\Module\Monitoring\Object\Host;
|
||||||
use Icinga\Module\Monitoring\Web\Controller\MonitoredObjectController;
|
use Icinga\Module\Monitoring\Web\Controller\MonitoredObjectController;
|
||||||
use Icinga\Web\Hook;
|
use Icinga\Web\Hook;
|
||||||
|
@ -118,4 +119,16 @@ class Monitoring_HostController extends MonitoredObjectController
|
||||||
$form->setTitle($this->translate('Submit Passive Host Check Result'));
|
$form->setTitle($this->translate('Submit Passive Host Check Result'));
|
||||||
$this->handleCommandForm($form);
|
$this->handleCommandForm($form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a custom notification for host
|
||||||
|
*/
|
||||||
|
public function sendCustomNotificationAction()
|
||||||
|
{
|
||||||
|
$this->assertPermission('monitoring/command/send-custom-notification');
|
||||||
|
|
||||||
|
$form = new SendCustomNotificationCommandForm();
|
||||||
|
$form->setTitle($this->translate('Send Custom Host Notification'));
|
||||||
|
$this->handleCommandForm($form);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\RemoveAcknowledgementCommandForm;
|
use Icinga\Module\Monitoring\Forms\Command\Object\RemoveAcknowledgementCommandForm;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostCheckCommandForm;
|
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostCheckCommandForm;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostDowntimeCommandForm;
|
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostDowntimeCommandForm;
|
||||||
|
use Icinga\Module\Monitoring\Forms\Command\Object\SendCustomNotificationCommandForm;
|
||||||
use Icinga\Module\Monitoring\Object\Host;
|
use Icinga\Module\Monitoring\Object\Host;
|
||||||
use Icinga\Module\Monitoring\Object\HostList;
|
use Icinga\Module\Monitoring\Object\HostList;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
|
@ -157,6 +158,10 @@ class Monitoring_HostsController extends Controller
|
||||||
$this->translate('Host State'),
|
$this->translate('Host State'),
|
||||||
array('#44bb77', '#FF5566', '#E066FF', '#77AAFF')
|
array('#44bb77', '#FF5566', '#E066FF', '#77AAFF')
|
||||||
);
|
);
|
||||||
|
$this->view->sendCustomNotificationLink =
|
||||||
|
Url::fromRequest()->setPath(
|
||||||
|
'monitoring/hosts/send-custom-notification'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createPieChart(array $states, $title, array $colors)
|
protected function createPieChart(array $states, $title, array $colors)
|
||||||
|
@ -215,4 +220,16 @@ class Monitoring_HostsController extends Controller
|
||||||
$form->setTitle($this->translate('Submit Passive Host Check Results'));
|
$form->setTitle($this->translate('Submit Passive Host Check Results'));
|
||||||
$this->handleCommandForm($form);
|
$this->handleCommandForm($form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a custom notification for hosts
|
||||||
|
*/
|
||||||
|
public function sendCustomNotificationAction()
|
||||||
|
{
|
||||||
|
$this->assertPermission('monitoring/command/send-custom-notification');
|
||||||
|
|
||||||
|
$form = new SendCustomNotificationCommandForm();
|
||||||
|
$form->setTitle($this->translate('Send Custom Host Notification'));
|
||||||
|
$this->handleCommandForm($form);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ use Icinga\Module\Monitoring\Forms\Command\Object\AddCommentCommandForm;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm;
|
use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceCheckCommandForm;
|
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceCheckCommandForm;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceDowntimeCommandForm;
|
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceDowntimeCommandForm;
|
||||||
|
use Icinga\Module\Monitoring\Forms\Command\Object\SendCustomNotificationCommandForm;
|
||||||
use Icinga\Module\Monitoring\Object\Service;
|
use Icinga\Module\Monitoring\Object\Service;
|
||||||
use Icinga\Module\Monitoring\Web\Controller\MonitoredObjectController;
|
use Icinga\Module\Monitoring\Web\Controller\MonitoredObjectController;
|
||||||
|
|
||||||
|
@ -95,4 +96,16 @@ class Monitoring_ServiceController extends MonitoredObjectController
|
||||||
$form->setTitle($this->translate('Submit Passive Service Check Result'));
|
$form->setTitle($this->translate('Submit Passive Service Check Result'));
|
||||||
$this->handleCommandForm($form);
|
$this->handleCommandForm($form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a custom notification for a service
|
||||||
|
*/
|
||||||
|
public function sendCustomNotificationAction()
|
||||||
|
{
|
||||||
|
$this->assertPermission('monitoring/command/send-custom-notification');
|
||||||
|
|
||||||
|
$form = new SendCustomNotificationCommandForm();
|
||||||
|
$form->setTitle($this->translate('Send Custom Service Notification'));
|
||||||
|
$this->handleCommandForm($form);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\RemoveAcknowledgementCommandForm;
|
use Icinga\Module\Monitoring\Forms\Command\Object\RemoveAcknowledgementCommandForm;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceCheckCommandForm;
|
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceCheckCommandForm;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceDowntimeCommandForm;
|
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceDowntimeCommandForm;
|
||||||
|
use Icinga\Module\Monitoring\Forms\Command\Object\SendCustomNotificationCommandForm;
|
||||||
use Icinga\Module\Monitoring\Object\Host;
|
use Icinga\Module\Monitoring\Object\Host;
|
||||||
use Icinga\Module\Monitoring\Object\Service;
|
use Icinga\Module\Monitoring\Object\Service;
|
||||||
use Icinga\Module\Monitoring\Object\ServiceList;
|
use Icinga\Module\Monitoring\Object\ServiceList;
|
||||||
|
@ -206,6 +207,10 @@ class Monitoring_ServicesController extends Controller
|
||||||
$this->translate('Host State'),
|
$this->translate('Host State'),
|
||||||
array('#44bb77', '#FF5566', '#E066FF', '#77AAFF')
|
array('#44bb77', '#FF5566', '#E066FF', '#77AAFF')
|
||||||
);
|
);
|
||||||
|
$this->view->sendCustomNotificationLink =
|
||||||
|
Url::fromRequest()->setPath(
|
||||||
|
'monitoring/services/send-custom-notification'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createPieChart(array $states, $title, array $colors)
|
protected function createPieChart(array $states, $title, array $colors)
|
||||||
|
@ -264,4 +269,16 @@ class Monitoring_ServicesController extends Controller
|
||||||
$form->setTitle($this->translate('Submit Passive Service Check Results'));
|
$form->setTitle($this->translate('Submit Passive Service Check Results'));
|
||||||
$this->handleCommandForm($form);
|
$this->handleCommandForm($form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a custom notification for services
|
||||||
|
*/
|
||||||
|
public function sendCustomNotificationAction()
|
||||||
|
{
|
||||||
|
$this->assertPermission('monitoring/command/send-custom-notification');
|
||||||
|
|
||||||
|
$form = new SendCustomNotificationCommandForm();
|
||||||
|
$form->setTitle($this->translate('Send Custom Service Notification'));
|
||||||
|
$this->handleCommandForm($form);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,6 +31,14 @@
|
||||||
null,
|
null,
|
||||||
array('icon' => 'reply')
|
array('icon' => 'reply')
|
||||||
); ?></div>
|
); ?></div>
|
||||||
|
<?php if ($this->hasPermission('monitoring/command/send-custom-notification')): ?>
|
||||||
|
<div><?= $this->qlink(
|
||||||
|
sprintf($this->translate('Send a custom notification for all %u hosts'), $hostCount),
|
||||||
|
$sendCustomNotificationLink,
|
||||||
|
null,
|
||||||
|
array('icon' => 'comment')
|
||||||
|
); ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
<?php if (($unhandledCount = count($unhandledObjects)) > 0): ?>
|
<?php if (($unhandledCount = count($unhandledObjects)) > 0): ?>
|
||||||
<div>
|
<div>
|
||||||
<h3><?= sprintf(
|
<h3><?= sprintf(
|
||||||
|
|
|
@ -31,6 +31,14 @@
|
||||||
null,
|
null,
|
||||||
array('icon' => 'reply')
|
array('icon' => 'reply')
|
||||||
); ?></div>
|
); ?></div>
|
||||||
|
<?php if ($this->hasPermission('monitoring/command/send-custom-notification')): ?>
|
||||||
|
<div><?= $this->qlink(
|
||||||
|
sprintf($this->translate('Send a custom notification for all %u services'), $serviceCount),
|
||||||
|
$sendCustomNotificationLink,
|
||||||
|
null,
|
||||||
|
array('icon' => 'comment')
|
||||||
|
); ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
<?php if (($unhandledCount = count($unhandledObjects)) > 0): ?>
|
<?php if (($unhandledCount = count($unhandledObjects)) > 0): ?>
|
||||||
<div>
|
<div>
|
||||||
<h3><?= sprintf(
|
<h3><?= sprintf(
|
||||||
|
|
|
@ -1,15 +1,36 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
// We are not interested in notifications for OK or pending objects
|
|
||||||
if (in_array((int) $object->state, array(0, 99))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
<tr>
|
<tr>
|
||||||
<th><?= $this->translate('Notifications') ?></th>
|
<th><?= $this->translate('Notifications') ?></th>
|
||||||
<td>
|
<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
|
<?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 ($object->current_notification_number > 0) {
|
||||||
if ((int) $object->current_notification_number === 1) {
|
if ((int) $object->current_notification_number === 1) {
|
||||||
|
@ -26,9 +47,12 @@ if ($object->current_notification_number > 0) {
|
||||||
$this->timeSince($object->last_notification)
|
$this->timeSince($object->last_notification)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
echo $msg;
|
echo '- ' . $msg;
|
||||||
} else {
|
} else {
|
||||||
echo $this->translate('No notification has been sent for this issue');
|
echo '('
|
||||||
|
. $this->translate('No notification has been sent for this issue')
|
||||||
|
. ')';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -55,6 +55,10 @@ $this->providePermission(
|
||||||
'monitoring/command/feature/object',
|
'monitoring/command/feature/object',
|
||||||
$this->translate('Allow processing commands for toggling features on host and service objects')
|
$this->translate('Allow processing commands for toggling features on host and service objects')
|
||||||
);
|
);
|
||||||
|
$this->providesPermission(
|
||||||
|
'monitoring/command/send-custom-notification',
|
||||||
|
$this->translate('Allow sending custom notifications for hosts and services');
|
||||||
|
);
|
||||||
|
|
||||||
$this->provideRestriction(
|
$this->provideRestriction(
|
||||||
'monitoring/hosts/filter',
|
'monitoring/hosts/filter',
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
<?php
|
||||||
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
|
namespace Icinga\Module\Monitoring\Command\Object;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send custom notifications for a host or service
|
||||||
|
*/
|
||||||
|
class SendCustomNotificationCommand extends WithCommentCommand
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $allowedObjects = array(
|
||||||
|
self::TYPE_HOST,
|
||||||
|
self::TYPE_SERVICE
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a notification is forced to send
|
||||||
|
*
|
||||||
|
* Forced notifications are send regardless of time and if notifications
|
||||||
|
* are enabled.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $forced;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Broadcast the notification
|
||||||
|
*
|
||||||
|
* If broadcast is true, the notification is send to all normal and
|
||||||
|
* escalated contacts for the object
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $broadcast;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get notification force flag
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getForced()
|
||||||
|
{
|
||||||
|
return $this->forced;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether notification should be forced
|
||||||
|
*
|
||||||
|
* @param bool $forced
|
||||||
|
*/
|
||||||
|
public function setForced($forced = true)
|
||||||
|
{
|
||||||
|
$this->forced = $forced;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get notification broadcast flag
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getBroadcast()
|
||||||
|
{
|
||||||
|
return $this->broadcast;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set notification to broadcast
|
||||||
|
*
|
||||||
|
* @param bool $broadcast
|
||||||
|
*/
|
||||||
|
public function setBroadcast($broadcast = true)
|
||||||
|
{
|
||||||
|
$this->broadcast = $broadcast;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue