Hide feature commands which are not supported by Icinga 2 from the user

fixes #7930
This commit is contained in:
Johannes Meyer 2015-07-03 14:17:06 +02:00
parent 3e5e6ec64e
commit 74a916d72a
3 changed files with 134 additions and 115 deletions

View File

@ -8,7 +8,7 @@ use Icinga\Module\Monitoring\Forms\Command\CommandForm;
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
{
@ -79,65 +79,68 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
} else {
$notificationDescription = null;
}
$toggleDisabled = $this->hasPermission('monitoring/command/feature/instance') ? null : '';
$this->addElements(array(
$this->addElement(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_ACTIVE_HOST_CHECKS,
array(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_ACTIVE_HOST_CHECKS,
array(
'label' => $this->translate('Active Host Checks'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
),
'label' => $this->translate('Active Host Checks'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
);
$this->addElement(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_ACTIVE_SERVICE_CHECKS,
array(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_ACTIVE_SERVICE_CHECKS,
array(
'label' => $this->translate('Active Service Checks'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
),
'label' => $this->translate('Active Service Checks'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
);
$this->addElement(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_EVENT_HANDLERS,
array(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_EVENT_HANDLERS,
array(
'label' => $this->translate('Event Handlers'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
),
'label' => $this->translate('Event Handlers'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
);
$this->addElement(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_FLAP_DETECTION,
array(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_FLAP_DETECTION,
array(
'label' => $this->translate('Flap Detection'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
),
'label' => $this->translate('Flap Detection'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
);
$this->addElement(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_NOTIFICATIONS,
array(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_NOTIFICATIONS,
array(
'label' => $this->translate('Notifications'),
'autosubmit' => true,
'description' => $notificationDescription,
'decorators' => array(
'ViewHelper',
'Errors',
array(
'Description',
array('tag' => 'span', 'class' => 'description', 'escape' => false)
),
'Label',
array('HtmlTag', array('tag' => 'div'))
'label' => $this->translate('Notifications'),
'autosubmit' => true,
'description' => $notificationDescription,
'decorators' => array(
'ViewHelper',
'Errors',
array(
'Description',
array('tag' => 'span', 'class' => 'description', 'escape' => false)
),
'disabled' => $toggleDisabled
)
),
array(
'Label',
array('HtmlTag', array('tag' => 'div'))
),
'disabled' => $toggleDisabled
)
);
if (! preg_match('~^v2\.\d+\.\d+.*$~', $this->status->program_version)) {
$this->addElement(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_HOST_OBSESSING,
array(
@ -145,8 +148,8 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
'autosubmit' => true,
'disabled' => $toggleDisabled
)
),
array(
);
$this->addElement(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_SERVICE_OBSESSING,
array(
@ -154,8 +157,8 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
'autosubmit' => true,
'disabled' => $toggleDisabled
)
),
array(
);
$this->addElement(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_PASSIVE_HOST_CHECKS,
array(
@ -163,8 +166,8 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
'autosubmit' => true,
'disabled' => $toggleDisabled
)
),
array(
);
$this->addElement(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_PASSIVE_SERVICE_CHECKS,
array(
@ -172,18 +175,18 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
'autosubmit' => true,
'disabled' => $toggleDisabled
)
),
);
}
$this->addElement(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_PERFORMANCE_DATA,
array(
'checkbox',
ToggleInstanceFeatureCommand::FEATURE_PERFORMANCE_DATA,
array(
'label' => $this->translate('Performance Data'),
'autosubmit' => true,
'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) {
$this->getElement($feature)->setChecked($instanceStatus->{$feature});
}
return $this;
}

View File

@ -31,26 +31,28 @@ class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
public function createElements(array $formData = array())
{
$toggleDisabled = $this->hasPermission('monitoring/command/feature/object') ? null : '';
$this->addElements(array(
$this->addElement(
'checkbox',
ToggleObjectFeatureCommand::FEATURE_ACTIVE_CHECKS,
array(
'checkbox',
ToggleObjectFeatureCommand::FEATURE_ACTIVE_CHECKS,
array(
'label' => $this->translate('Active Checks'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
),
array(
'checkbox',
ToggleObjectFeatureCommand::FEATURE_PASSIVE_CHECKS,
array(
'label' => $this->translate('Passive Checks'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
),
'label' => $this->translate('Active Checks'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
);
$this->addElement(
'checkbox',
ToggleObjectFeatureCommand::FEATURE_PASSIVE_CHECKS,
array(
'label' => $this->translate('Passive Checks'),
'autosubmit' => true,
'disabled' => $toggleDisabled
)
);
if (! preg_match('~^v2\.\d+\.\d+.*$~', $this->getIcingaVersion())) {
$this->addElement(
'checkbox',
ToggleObjectFeatureCommand::FEATURE_OBSESSING,
array(
@ -58,36 +60,36 @@ class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
'autosubmit' => true,
'disabled' => $toggleDisabled
)
),
);
}
$this->addElement(
'checkbox',
ToggleObjectFeatureCommand::FEATURE_NOTIFICATIONS,
array(
'checkbox',
ToggleObjectFeatureCommand::FEATURE_NOTIFICATIONS,
array(
'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
)
'label' => $this->translate('Notifications'),
'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'));
}
}
return $this;
}
@ -162,6 +165,17 @@ class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
}
}
}
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();
}
}

View File

@ -76,6 +76,7 @@ abstract class MonitoredObjectController extends Controller
$this->object->populate();
$toggleFeaturesForm = new ToggleObjectFeaturesCommandForm();
$toggleFeaturesForm
->setBackend($this->backend)
->load($this->object)
->setObjects($this->object)
->handleRequest();