mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 07:44:04 +02:00
Hide feature commands which are not supported by Icinga 2 from the user
fixes #7930
This commit is contained in:
parent
3e5e6ec64e
commit
74a916d72a
@ -8,7 +8,7 @@ use Icinga\Module\Monitoring\Forms\Command\CommandForm;
|
|||||||
use Icinga\Web\Notification;
|
use Icinga\Web\Notification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form for enabling or disabling features of Icinga objects, i.e. hosts or services
|
* Form for enabling or disabling features of Icinga instances
|
||||||
*/
|
*/
|
||||||
class ToggleInstanceFeaturesCommandForm extends CommandForm
|
class ToggleInstanceFeaturesCommandForm extends CommandForm
|
||||||
{
|
{
|
||||||
@ -79,65 +79,68 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
|
|||||||
} else {
|
} else {
|
||||||
$notificationDescription = null;
|
$notificationDescription = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$toggleDisabled = $this->hasPermission('monitoring/command/feature/instance') ? null : '';
|
$toggleDisabled = $this->hasPermission('monitoring/command/feature/instance') ? null : '';
|
||||||
$this->addElements(array(
|
|
||||||
|
$this->addElement(
|
||||||
|
'checkbox',
|
||||||
|
ToggleInstanceFeatureCommand::FEATURE_ACTIVE_HOST_CHECKS,
|
||||||
array(
|
array(
|
||||||
'checkbox',
|
'label' => $this->translate('Active Host Checks'),
|
||||||
ToggleInstanceFeatureCommand::FEATURE_ACTIVE_HOST_CHECKS,
|
'autosubmit' => true,
|
||||||
array(
|
'disabled' => $toggleDisabled
|
||||||
'label' => $this->translate('Active Host Checks'),
|
)
|
||||||
'autosubmit' => true,
|
);
|
||||||
'disabled' => $toggleDisabled
|
$this->addElement(
|
||||||
)
|
'checkbox',
|
||||||
),
|
ToggleInstanceFeatureCommand::FEATURE_ACTIVE_SERVICE_CHECKS,
|
||||||
array(
|
array(
|
||||||
'checkbox',
|
'label' => $this->translate('Active Service Checks'),
|
||||||
ToggleInstanceFeatureCommand::FEATURE_ACTIVE_SERVICE_CHECKS,
|
'autosubmit' => true,
|
||||||
array(
|
'disabled' => $toggleDisabled
|
||||||
'label' => $this->translate('Active Service Checks'),
|
)
|
||||||
'autosubmit' => true,
|
);
|
||||||
'disabled' => $toggleDisabled
|
$this->addElement(
|
||||||
)
|
'checkbox',
|
||||||
),
|
ToggleInstanceFeatureCommand::FEATURE_EVENT_HANDLERS,
|
||||||
array(
|
array(
|
||||||
'checkbox',
|
'label' => $this->translate('Event Handlers'),
|
||||||
ToggleInstanceFeatureCommand::FEATURE_EVENT_HANDLERS,
|
'autosubmit' => true,
|
||||||
array(
|
'disabled' => $toggleDisabled
|
||||||
'label' => $this->translate('Event Handlers'),
|
)
|
||||||
'autosubmit' => true,
|
);
|
||||||
'disabled' => $toggleDisabled
|
$this->addElement(
|
||||||
)
|
'checkbox',
|
||||||
),
|
ToggleInstanceFeatureCommand::FEATURE_FLAP_DETECTION,
|
||||||
array(
|
array(
|
||||||
'checkbox',
|
'label' => $this->translate('Flap Detection'),
|
||||||
ToggleInstanceFeatureCommand::FEATURE_FLAP_DETECTION,
|
'autosubmit' => true,
|
||||||
array(
|
'disabled' => $toggleDisabled
|
||||||
'label' => $this->translate('Flap Detection'),
|
)
|
||||||
'autosubmit' => true,
|
);
|
||||||
'disabled' => $toggleDisabled
|
$this->addElement(
|
||||||
)
|
'checkbox',
|
||||||
),
|
ToggleInstanceFeatureCommand::FEATURE_NOTIFICATIONS,
|
||||||
array(
|
array(
|
||||||
'checkbox',
|
'label' => $this->translate('Notifications'),
|
||||||
ToggleInstanceFeatureCommand::FEATURE_NOTIFICATIONS,
|
'autosubmit' => true,
|
||||||
array(
|
'description' => $notificationDescription,
|
||||||
'label' => $this->translate('Notifications'),
|
'decorators' => array(
|
||||||
'autosubmit' => true,
|
'ViewHelper',
|
||||||
'description' => $notificationDescription,
|
'Errors',
|
||||||
'decorators' => array(
|
array(
|
||||||
'ViewHelper',
|
'Description',
|
||||||
'Errors',
|
array('tag' => 'span', 'class' => 'description', 'escape' => false)
|
||||||
array(
|
|
||||||
'Description',
|
|
||||||
array('tag' => 'span', 'class' => 'description', 'escape' => false)
|
|
||||||
),
|
|
||||||
'Label',
|
|
||||||
array('HtmlTag', array('tag' => 'div'))
|
|
||||||
),
|
),
|
||||||
'disabled' => $toggleDisabled
|
'Label',
|
||||||
)
|
array('HtmlTag', array('tag' => 'div'))
|
||||||
),
|
),
|
||||||
array(
|
'disabled' => $toggleDisabled
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (! preg_match('~^v2\.\d+\.\d+.*$~', $this->status->program_version)) {
|
||||||
|
$this->addElement(
|
||||||
'checkbox',
|
'checkbox',
|
||||||
ToggleInstanceFeatureCommand::FEATURE_HOST_OBSESSING,
|
ToggleInstanceFeatureCommand::FEATURE_HOST_OBSESSING,
|
||||||
array(
|
array(
|
||||||
@ -145,8 +148,8 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
|
|||||||
'autosubmit' => true,
|
'autosubmit' => true,
|
||||||
'disabled' => $toggleDisabled
|
'disabled' => $toggleDisabled
|
||||||
)
|
)
|
||||||
),
|
);
|
||||||
array(
|
$this->addElement(
|
||||||
'checkbox',
|
'checkbox',
|
||||||
ToggleInstanceFeatureCommand::FEATURE_SERVICE_OBSESSING,
|
ToggleInstanceFeatureCommand::FEATURE_SERVICE_OBSESSING,
|
||||||
array(
|
array(
|
||||||
@ -154,8 +157,8 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
|
|||||||
'autosubmit' => true,
|
'autosubmit' => true,
|
||||||
'disabled' => $toggleDisabled
|
'disabled' => $toggleDisabled
|
||||||
)
|
)
|
||||||
),
|
);
|
||||||
array(
|
$this->addElement(
|
||||||
'checkbox',
|
'checkbox',
|
||||||
ToggleInstanceFeatureCommand::FEATURE_PASSIVE_HOST_CHECKS,
|
ToggleInstanceFeatureCommand::FEATURE_PASSIVE_HOST_CHECKS,
|
||||||
array(
|
array(
|
||||||
@ -163,8 +166,8 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
|
|||||||
'autosubmit' => true,
|
'autosubmit' => true,
|
||||||
'disabled' => $toggleDisabled
|
'disabled' => $toggleDisabled
|
||||||
)
|
)
|
||||||
),
|
);
|
||||||
array(
|
$this->addElement(
|
||||||
'checkbox',
|
'checkbox',
|
||||||
ToggleInstanceFeatureCommand::FEATURE_PASSIVE_SERVICE_CHECKS,
|
ToggleInstanceFeatureCommand::FEATURE_PASSIVE_SERVICE_CHECKS,
|
||||||
array(
|
array(
|
||||||
@ -172,18 +175,18 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
|
|||||||
'autosubmit' => true,
|
'autosubmit' => true,
|
||||||
'disabled' => $toggleDisabled
|
'disabled' => $toggleDisabled
|
||||||
)
|
)
|
||||||
),
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->addElement(
|
||||||
|
'checkbox',
|
||||||
|
ToggleInstanceFeatureCommand::FEATURE_PERFORMANCE_DATA,
|
||||||
array(
|
array(
|
||||||
'checkbox',
|
'label' => $this->translate('Performance Data'),
|
||||||
ToggleInstanceFeatureCommand::FEATURE_PERFORMANCE_DATA,
|
'autosubmit' => true,
|
||||||
array(
|
'disabled' => $toggleDisabled
|
||||||
'label' => $this->translate('Performance Data'),
|
|
||||||
'autosubmit' => true,
|
|
||||||
'disabled' => $toggleDisabled
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
));
|
);
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -199,6 +202,7 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
|
|||||||
foreach ($this->getValues() as $feature => $enabled) {
|
foreach ($this->getValues() as $feature => $enabled) {
|
||||||
$this->getElement($feature)->setChecked($instanceStatus->{$feature});
|
$this->getElement($feature)->setChecked($instanceStatus->{$feature});
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,26 +31,28 @@ class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
|
|||||||
public function createElements(array $formData = array())
|
public function createElements(array $formData = array())
|
||||||
{
|
{
|
||||||
$toggleDisabled = $this->hasPermission('monitoring/command/feature/object') ? null : '';
|
$toggleDisabled = $this->hasPermission('monitoring/command/feature/object') ? null : '';
|
||||||
$this->addElements(array(
|
|
||||||
|
$this->addElement(
|
||||||
|
'checkbox',
|
||||||
|
ToggleObjectFeatureCommand::FEATURE_ACTIVE_CHECKS,
|
||||||
array(
|
array(
|
||||||
'checkbox',
|
'label' => $this->translate('Active Checks'),
|
||||||
ToggleObjectFeatureCommand::FEATURE_ACTIVE_CHECKS,
|
'autosubmit' => true,
|
||||||
array(
|
'disabled' => $toggleDisabled
|
||||||
'label' => $this->translate('Active Checks'),
|
)
|
||||||
'autosubmit' => true,
|
);
|
||||||
'disabled' => $toggleDisabled
|
$this->addElement(
|
||||||
)
|
'checkbox',
|
||||||
),
|
ToggleObjectFeatureCommand::FEATURE_PASSIVE_CHECKS,
|
||||||
array(
|
|
||||||
'checkbox',
|
|
||||||
ToggleObjectFeatureCommand::FEATURE_PASSIVE_CHECKS,
|
|
||||||
array(
|
|
||||||
'label' => $this->translate('Passive Checks'),
|
|
||||||
'autosubmit' => true,
|
|
||||||
'disabled' => $toggleDisabled
|
|
||||||
)
|
|
||||||
),
|
|
||||||
array(
|
array(
|
||||||
|
'label' => $this->translate('Passive Checks'),
|
||||||
|
'autosubmit' => true,
|
||||||
|
'disabled' => $toggleDisabled
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (! preg_match('~^v2\.\d+\.\d+.*$~', $this->getIcingaVersion())) {
|
||||||
|
$this->addElement(
|
||||||
'checkbox',
|
'checkbox',
|
||||||
ToggleObjectFeatureCommand::FEATURE_OBSESSING,
|
ToggleObjectFeatureCommand::FEATURE_OBSESSING,
|
||||||
array(
|
array(
|
||||||
@ -58,36 +60,36 @@ class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
|
|||||||
'autosubmit' => true,
|
'autosubmit' => true,
|
||||||
'disabled' => $toggleDisabled
|
'disabled' => $toggleDisabled
|
||||||
)
|
)
|
||||||
),
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->addElement(
|
||||||
|
'checkbox',
|
||||||
|
ToggleObjectFeatureCommand::FEATURE_NOTIFICATIONS,
|
||||||
array(
|
array(
|
||||||
'checkbox',
|
'label' => $this->translate('Notifications'),
|
||||||
ToggleObjectFeatureCommand::FEATURE_NOTIFICATIONS,
|
'autosubmit' => true,
|
||||||
array(
|
'disabled' => $toggleDisabled
|
||||||
'label' => $this->translate('Notifications'),
|
|
||||||
'autosubmit' => true,
|
|
||||||
'disabled' => $toggleDisabled
|
|
||||||
)
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'checkbox',
|
|
||||||
ToggleObjectFeatureCommand::FEATURE_EVENT_HANDLER,
|
|
||||||
array(
|
|
||||||
'label' => $this->translate('Event Handler'),
|
|
||||||
'autosubmit' => true,
|
|
||||||
'disabled' => $toggleDisabled
|
|
||||||
)
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'checkbox',
|
|
||||||
ToggleObjectFeatureCommand::FEATURE_FLAP_DETECTION,
|
|
||||||
array(
|
|
||||||
'label' => $this->translate('Flap Detection'),
|
|
||||||
'autosubmit' => true,
|
|
||||||
'disabled' => $toggleDisabled
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
));
|
);
|
||||||
return $this;
|
$this->addElement(
|
||||||
|
'checkbox',
|
||||||
|
ToggleObjectFeatureCommand::FEATURE_EVENT_HANDLER,
|
||||||
|
array(
|
||||||
|
'label' => $this->translate('Event Handler'),
|
||||||
|
'autosubmit' => true,
|
||||||
|
'disabled' => $toggleDisabled
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->addElement(
|
||||||
|
'checkbox',
|
||||||
|
ToggleObjectFeatureCommand::FEATURE_FLAP_DETECTION,
|
||||||
|
array(
|
||||||
|
'label' => $this->translate('Flap Detection'),
|
||||||
|
'autosubmit' => true,
|
||||||
|
'disabled' => $toggleDisabled
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,6 +109,7 @@ class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
|
|||||||
$element->setDescription($this->translate('changed'));
|
$element->setDescription($this->translate('changed'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,6 +165,17 @@ class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch and return the program version of the current instance
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function getIcingaVersion()
|
||||||
|
{
|
||||||
|
return $this->getBackend()->select()->from('programstatus', array('program_version'))->fetchOne();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,6 +76,7 @@ abstract class MonitoredObjectController extends Controller
|
|||||||
$this->object->populate();
|
$this->object->populate();
|
||||||
$toggleFeaturesForm = new ToggleObjectFeaturesCommandForm();
|
$toggleFeaturesForm = new ToggleObjectFeaturesCommandForm();
|
||||||
$toggleFeaturesForm
|
$toggleFeaturesForm
|
||||||
|
->setBackend($this->backend)
|
||||||
->load($this->object)
|
->load($this->object)
|
||||||
->setObjects($this->object)
|
->setObjects($this->object)
|
||||||
->handleRequest();
|
->handleRequest();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user