/usr/share/icingaweb2/modules/monitoring/application/forms/Command/Instance/ToggleInstanceFeaturesCommandForm.php is in icingaweb2-module-monitoring 2.1.0-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | <?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Forms\Command\Instance;
use Icinga\Module\Monitoring\Command\Instance\ToggleInstanceFeatureCommand;
use Icinga\Module\Monitoring\Forms\Command\CommandForm;
use Icinga\Web\Notification;
/**
* Form for enabling or disabling features of Icinga instances
*/
class ToggleInstanceFeaturesCommandForm extends CommandForm
{
/**
* Instance status
*
* @var object
*/
protected $status;
/**
* (non-PHPDoc)
* @see \Zend_Form::init() For the method documentation.
*/
public function init()
{
$this->setUseFormAutosubmit();
$this->setTitle($this->translate('Feature Commands'));
$this->setAttrib('class', 'inline instance-features');
$this->loadDefaultDecorators()->getDecorator('description')->setTag('h2');
}
/**
* Set the instance status
*
* @param object $status
*
* @return $this
*/
public function setStatus($status)
{
$this->status = (object) $status;
return $this;
}
/**
* Get the instance status
*
* @return object
*/
public function getStatus()
{
return $this->status;
}
/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::createElements() For the method documentation.
*/
public function createElements(array $formData = array())
{
if ((bool) $this->status->notifications_enabled) {
if ($this->hasPermission('monitoring/command/feature/instance')) {
$notificationDescription = sprintf(
'<a aria-label="%1$s" class="action-link" title="%1$s" href="%2$s" data-base-target="_next">%3$s</a>',
$this->translate('Disable notifications for a specific time on a program-wide basis'),
$this->getView()->href('monitoring/health/disable-notifications'),
$this->translate('Disable temporarily')
);
} else {
$notificationDescription = null;
}
} elseif ($this->status->disable_notif_expire_time) {
$notificationDescription = sprintf(
$this->translate('Notifications will be re-enabled in <strong>%s</strong>'),
$this->getView()->timeUntil($this->status->disable_notif_expire_time)
);
} else {
$notificationDescription = null;
}
$toggleDisabled = $this->hasPermission('monitoring/command/feature/instance') ? null : '';
$this->addElement(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_ACTIVE_HOST_CHECKS,
array(
'label' => $this->translate('Active Host Checks'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
);
$this->addElement(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_ACTIVE_SERVICE_CHECKS,
array(
'label' => $this->translate('Active Service Checks'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
);
$this->addElement(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_EVENT_HANDLERS,
array(
'label' => $this->translate('Event Handlers'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
);
$this->addElement(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_FLAP_DETECTION,
array(
'label' => $this->translate('Flap Detection'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
);
$this->addElement(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_NOTIFICATIONS,
array(
'label' => $this->translate('Notifications'),
'autosubmit' => true,
'description' => $notificationDescription,
'decorators' => array(
array('Label', array('tag'=>'span', 'separator' => '', 'class' => 'control-label')),
array(
'Description',
array('tag' => 'span', 'class' => 'description', 'escape' => false)
),
array(array('labelWrap' => 'HtmlTag'), array('tag' => 'div', 'class' => 'control-label-group')),
array('ViewHelper', array('separator' => '')),
array('Errors', array('separator' => '')),
array('HtmlTag', array('tag' => 'div', 'class' => 'control-group'))
),
'disabled' => $toggleDisabled
)
);
if (! preg_match('~^v2\.\d+\.\d+.*$~', $this->status->program_version)) {
$this->addElement(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_HOST_OBSESSING,
array(
'label' => $this->translate('Obsessing Over Hosts'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
);
$this->addElement(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_SERVICE_OBSESSING,
array(
'label' => $this->translate('Obsessing Over Services'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
);
$this->addElement(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_PASSIVE_HOST_CHECKS,
array(
'label' => $this->translate('Passive Host Checks'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
);
$this->addElement(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_PASSIVE_SERVICE_CHECKS,
array(
'label' => $this->translate('Passive Service Checks'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
);
}
$this->addElement(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_PERFORMANCE_DATA,
array(
'label' => $this->translate('Performance Data'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
);
}
/**
* Load feature status
*
* @param object $instanceStatus
*
* @return $this
*/
public function load($instanceStatus)
{
$this->create();
foreach ($this->getValues() as $feature => $enabled) {
$this->getElement($feature)->setChecked($instanceStatus->{$feature});
}
return $this;
}
/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::onSuccess() For the method documentation.
*/
public function onSuccess()
{
$this->assertPermission('monitoring/command/feature/instance');
$notifications = array(
ToggleInstanceFeatureCommand::FEATURE_ACTIVE_HOST_CHECKS => array(
$this->translate('Enabling active host checks..'),
$this->translate('Disabling active host checks..')
),
ToggleInstanceFeatureCommand::FEATURE_ACTIVE_SERVICE_CHECKS => array(
$this->translate('Enabling active service checks..'),
$this->translate('Disabling active service checks..')
),
ToggleInstanceFeatureCommand::FEATURE_EVENT_HANDLERS => array(
$this->translate('Enabling event handlers..'),
$this->translate('Disabling event handlers..')
),
ToggleInstanceFeatureCommand::FEATURE_FLAP_DETECTION => array(
$this->translate('Enabling flap detection..'),
$this->translate('Disabling flap detection..')
),
ToggleInstanceFeatureCommand::FEATURE_NOTIFICATIONS => array(
$this->translate('Enabling notifications..'),
$this->translate('Disabling notifications..')
),
ToggleInstanceFeatureCommand::FEATURE_HOST_OBSESSING => array(
$this->translate('Enabling obsessing over hosts..'),
$this->translate('Disabling obsessing over hosts..')
),
ToggleInstanceFeatureCommand::FEATURE_SERVICE_OBSESSING => array(
$this->translate('Enabling obsessing over services..'),
$this->translate('Disabling obsessing over services..')
),
ToggleInstanceFeatureCommand::FEATURE_PASSIVE_HOST_CHECKS => array(
$this->translate('Enabling passive host checks..'),
$this->translate('Disabling passive host checks..')
),
ToggleInstanceFeatureCommand::FEATURE_PASSIVE_SERVICE_CHECKS => array(
$this->translate('Enabling passive service checks..'),
$this->translate('Disabling passive service checks..')
),
ToggleInstanceFeatureCommand::FEATURE_PERFORMANCE_DATA => array(
$this->translate('Enabling performance data..'),
$this->translate('Disabling performance data..')
)
);
foreach ($this->getValues() as $feature => $enabled) {
if ((bool) $this->status->{$feature} !== (bool) $enabled) {
$toggleFeature = new ToggleInstanceFeatureCommand();
$toggleFeature
->setFeature($feature)
->setEnabled($enabled);
$this->getTransport($this->request)->send($toggleFeature);
Notification::success(
$notifications[$feature][$enabled ? 0 : 1]
);
}
}
return true;
}
}
|