2016-02-28 17:02:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Forms;
|
|
|
|
|
|
|
|
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
|
|
|
|
|
|
|
class IcingaNotificationForm extends DirectorObjectForm
|
|
|
|
{
|
|
|
|
public function setup()
|
|
|
|
{
|
|
|
|
$this->addObjectTypeElement();
|
2016-03-07 14:20:58 +01:00
|
|
|
if (! $this->hasObjectType()) {
|
2016-03-10 20:44:12 +01:00
|
|
|
$this->groupMainProperties();
|
2016-03-07 14:20:58 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-02-28 17:02:28 +01:00
|
|
|
|
2017-03-14 20:48:36 +01:00
|
|
|
if ($this->isTemplate()) {
|
|
|
|
$this->addElement('text', 'object_name', array(
|
|
|
|
'label' => $this->translate('Notification Template'),
|
|
|
|
'required' => true,
|
|
|
|
'description' => $this->translate('Name for the Icinga notification template you are going to create')
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
$this->addElement('text', 'object_name', array(
|
|
|
|
'label' => $this->translate('Notification'),
|
|
|
|
'required' => true,
|
|
|
|
'description' => $this->translate('Name for the Icinga notification you are going to create')
|
|
|
|
));
|
2017-10-13 10:26:31 +02:00
|
|
|
|
2017-12-12 15:49:22 +01:00
|
|
|
$this->eventuallyAddNameRestriction(
|
|
|
|
'director/notification/apply/filter-by-name'
|
|
|
|
);
|
2017-03-14 20:48:36 +01:00
|
|
|
}
|
2017-03-14 20:47:02 +01:00
|
|
|
|
2016-03-10 20:44:12 +01:00
|
|
|
$this->addDisabledElement()
|
|
|
|
->addImportsElement()
|
2016-03-16 14:07:09 +01:00
|
|
|
->addUsersElement()
|
|
|
|
->addUsergroupsElement()
|
2016-03-12 01:35:24 +01:00
|
|
|
->addIntervalElement()
|
|
|
|
->addPeriodElement()
|
|
|
|
->addTimesElements()
|
2016-05-19 15:06:05 +02:00
|
|
|
->addAssignmentElements()
|
2016-03-10 20:44:12 +01:00
|
|
|
->addDisabledElement()
|
2016-03-12 01:35:24 +01:00
|
|
|
->addCommandElements()
|
2016-03-10 20:44:12 +01:00
|
|
|
->addEventFilterElements()
|
2017-03-14 20:47:02 +01:00
|
|
|
->addZoneElements()
|
2016-03-10 20:44:12 +01:00
|
|
|
->groupMainProperties()
|
|
|
|
->setButtons();
|
2016-02-28 17:02:28 +01:00
|
|
|
}
|
2016-03-12 01:35:24 +01:00
|
|
|
|
2017-03-14 20:47:02 +01:00
|
|
|
protected function addZoneElements()
|
|
|
|
{
|
|
|
|
if (! $this->isTemplate()) {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->addZoneElement();
|
|
|
|
$this->addDisplayGroup(array('zone_id'), 'clustering', array(
|
|
|
|
'decorators' => array(
|
|
|
|
'FormElements',
|
|
|
|
array('HtmlTag', array('tag' => 'dl')),
|
|
|
|
'Fieldset',
|
|
|
|
),
|
2020-11-30 12:39:48 +01:00
|
|
|
'order' => self::GROUP_ORDER_CLUSTERING,
|
2017-03-14 20:47:02 +01:00
|
|
|
'legend' => $this->translate('Zone settings')
|
|
|
|
));
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-11-01 18:28:36 +01:00
|
|
|
/**
|
|
|
|
* @return self
|
|
|
|
*/
|
2016-05-19 15:06:05 +02:00
|
|
|
protected function addAssignmentElements()
|
|
|
|
{
|
|
|
|
if (!$this->object || !$this->object->isApplyRule()) {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-10-24 05:41:37 +02:00
|
|
|
$this->addElement('select', 'apply_to', array(
|
|
|
|
'label' => $this->translate('Apply to'),
|
|
|
|
'description' => $this->translate(
|
|
|
|
'Whether this notification should affect hosts or services'
|
|
|
|
),
|
|
|
|
'required' => true,
|
|
|
|
'class' => 'autosubmit',
|
|
|
|
'multiOptions' => $this->optionalEnum(
|
|
|
|
array(
|
|
|
|
'host' => $this->translate('Hosts'),
|
|
|
|
'service' => $this->translate('Services'),
|
2016-06-09 23:49:02 +02:00
|
|
|
)
|
|
|
|
)
|
2016-10-24 05:41:37 +02:00
|
|
|
));
|
2016-06-09 23:49:02 +02:00
|
|
|
|
2016-10-24 05:41:37 +02:00
|
|
|
$applyTo = $this->getSentOrObjectValue('apply_to');
|
2016-05-19 15:06:05 +02:00
|
|
|
|
2017-10-12 14:56:13 +02:00
|
|
|
if (! $applyTo) {
|
2016-10-24 05:41:37 +02:00
|
|
|
return $this;
|
|
|
|
}
|
2016-05-19 15:06:05 +02:00
|
|
|
|
2017-10-12 14:56:13 +02:00
|
|
|
$suggestionContext = ucfirst($applyTo) . 'FilterColumns';
|
|
|
|
$this->addAssignFilter([
|
2016-10-24 05:41:37 +02:00
|
|
|
'required' => true,
|
2017-10-12 14:56:13 +02:00
|
|
|
'suggestionContext' => $suggestionContext,
|
2016-10-24 05:41:37 +02:00
|
|
|
'description' => $this->translate(
|
|
|
|
'This allows you to configure an assignment filter. Please feel'
|
2019-07-08 14:11:53 +02:00
|
|
|
. ' free to combine as many nested operators as you want. The'
|
|
|
|
. ' "contains" operator is valid for arrays only. Please use'
|
|
|
|
. ' wildcards and the = (equals) operator when searching for'
|
|
|
|
. ' partial string matches, like in *.example.com'
|
2016-10-24 05:41:37 +02:00
|
|
|
)
|
2017-10-12 14:56:13 +02:00
|
|
|
]);
|
|
|
|
|
2016-05-19 15:06:05 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-11-01 18:28:36 +01:00
|
|
|
/**
|
2017-01-13 19:47:54 +01:00
|
|
|
* @return $this
|
2016-11-01 18:28:36 +01:00
|
|
|
*/
|
2016-03-16 14:07:09 +01:00
|
|
|
protected function addUsersElement()
|
|
|
|
{
|
|
|
|
$users = $this->enumUsers();
|
|
|
|
if (empty($users)) {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'extensibleSet',
|
|
|
|
'users',
|
|
|
|
array(
|
|
|
|
'label' => $this->translate('Users'),
|
|
|
|
'description' => $this->translate(
|
|
|
|
'Users that should be notified by this notifications'
|
|
|
|
),
|
|
|
|
'multiOptions' => $this->optionalEnum($users)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-11-01 18:28:36 +01:00
|
|
|
/**
|
2017-01-13 19:47:54 +01:00
|
|
|
* @return $this
|
2016-11-01 18:28:36 +01:00
|
|
|
*/
|
2016-03-16 14:07:09 +01:00
|
|
|
protected function addUsergroupsElement()
|
|
|
|
{
|
|
|
|
$groups = $this->enumUsergroups();
|
|
|
|
if (empty($groups)) {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'extensibleSet',
|
|
|
|
'user_groups',
|
|
|
|
array(
|
|
|
|
'label' => $this->translate('User groups'),
|
|
|
|
'description' => $this->translate(
|
|
|
|
'User groups that should be notified by this notifications'
|
|
|
|
),
|
|
|
|
'multiOptions' => $this->optionalEnum($groups)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-11-01 18:28:36 +01:00
|
|
|
/**
|
|
|
|
* @return self
|
|
|
|
*/
|
2016-03-12 01:35:24 +01:00
|
|
|
protected function addIntervalElement()
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'notification_interval',
|
|
|
|
array(
|
|
|
|
'label' => $this->translate('Notification interval'),
|
|
|
|
'description' => $this->translate(
|
|
|
|
'The notification interval (in seconds). This interval is'
|
|
|
|
. ' used for active notifications. Defaults to 30 minutes.'
|
|
|
|
. ' If set to 0, re-notifications are disabled.'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-11-01 18:28:36 +01:00
|
|
|
/**
|
|
|
|
* @return self
|
|
|
|
*/
|
2016-03-12 01:35:24 +01:00
|
|
|
protected function addTimesElements()
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'times_begin',
|
|
|
|
array(
|
|
|
|
'label' => $this->translate('First notification delay'),
|
|
|
|
'description' => $this->translate(
|
|
|
|
'Delay unless the first notification should be sent'
|
2020-11-28 17:54:19 +01:00
|
|
|
) . '. ' . $this->getTimeValueInfo()
|
2016-03-12 01:35:24 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'times_end',
|
|
|
|
array(
|
2016-03-12 01:44:28 +01:00
|
|
|
'label' => $this->translate('Last notification'),
|
2016-03-12 01:35:24 +01:00
|
|
|
'description' => $this->translate(
|
|
|
|
'When the last notification should be sent'
|
2020-11-28 17:54:19 +01:00
|
|
|
) . '. ' . $this->getTimeValueInfo()
|
2016-03-12 01:35:24 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2020-11-28 17:54:19 +01:00
|
|
|
protected function getTimeValueInfo()
|
|
|
|
{
|
|
|
|
return $this->translate(
|
|
|
|
'Unit is seconds unless a suffix is given. Supported suffixes include'
|
|
|
|
. ' ms (milliseconds), s (seconds), m (minutes), h (hours) and d (days).'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-11-01 18:28:36 +01:00
|
|
|
/**
|
|
|
|
* @return self
|
|
|
|
*/
|
2016-03-12 01:35:24 +01:00
|
|
|
protected function addPeriodElement()
|
|
|
|
{
|
2016-04-03 21:36:41 +02:00
|
|
|
$periods = $this->db->enumTimeperiods();
|
|
|
|
if (empty($periods)) {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-03-12 01:35:24 +01:00
|
|
|
$this->addElement(
|
|
|
|
'select',
|
2016-05-23 13:00:32 +02:00
|
|
|
'period_id',
|
2016-03-12 01:35:24 +01:00
|
|
|
array(
|
|
|
|
'label' => $this->translate('Time period'),
|
|
|
|
'description' => $this->translate(
|
|
|
|
'The name of a time period which determines when this'
|
|
|
|
. ' notification should be triggered. Not set by default.'
|
2016-04-03 21:36:41 +02:00
|
|
|
),
|
|
|
|
'multiOptions' => $this->optionalEnum($periods),
|
2016-03-12 01:35:24 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-11-01 18:28:36 +01:00
|
|
|
/**
|
|
|
|
* @return self
|
|
|
|
*/
|
2016-03-12 01:35:24 +01:00
|
|
|
protected function addCommandElements()
|
|
|
|
{
|
|
|
|
if (! $this->isTemplate()) {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->addElement('select', 'command_id', array(
|
|
|
|
'label' => $this->translate('Notification command'),
|
|
|
|
'description' => $this->translate('Check command definition'),
|
|
|
|
'multiOptions' => $this->optionalEnum($this->db->enumNotificationCommands()),
|
|
|
|
'class' => 'autosubmit',
|
|
|
|
));
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2016-03-16 14:07:09 +01:00
|
|
|
|
|
|
|
protected function enumUsers()
|
|
|
|
{
|
|
|
|
$db = $this->db->getDbAdapter();
|
|
|
|
$select = $db->select()->from(
|
|
|
|
'icinga_user',
|
|
|
|
array(
|
|
|
|
'name' => 'object_name',
|
|
|
|
'display' => 'COALESCE(display_name, object_name)'
|
|
|
|
)
|
|
|
|
)->where('object_type = ?', 'object')->order('display');
|
|
|
|
|
|
|
|
return $db->fetchPairs($select);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function enumUsergroups()
|
|
|
|
{
|
|
|
|
$db = $this->db->getDbAdapter();
|
|
|
|
$select = $db->select()->from(
|
|
|
|
'icinga_usergroup',
|
|
|
|
array(
|
|
|
|
'name' => 'object_name',
|
|
|
|
'display' => 'COALESCE(display_name, object_name)'
|
|
|
|
)
|
|
|
|
)->where('object_type = ?', 'object')->order('display');
|
|
|
|
|
|
|
|
return $db->fetchPairs($select);
|
|
|
|
}
|
2017-01-13 19:47:54 +01:00
|
|
|
}
|