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;
|
||||
|
||||
/**
|
||||
* 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,9 +79,10 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
|
||||
} else {
|
||||
$notificationDescription = null;
|
||||
}
|
||||
|
||||
$toggleDisabled = $this->hasPermission('monitoring/command/feature/instance') ? null : '';
|
||||
$this->addElements(array(
|
||||
array(
|
||||
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
ToggleInstanceFeatureCommand::FEATURE_ACTIVE_HOST_CHECKS,
|
||||
array(
|
||||
@ -89,8 +90,8 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
|
||||
'autosubmit' => true,
|
||||
'disabled' => $toggleDisabled
|
||||
)
|
||||
),
|
||||
array(
|
||||
);
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
ToggleInstanceFeatureCommand::FEATURE_ACTIVE_SERVICE_CHECKS,
|
||||
array(
|
||||
@ -98,8 +99,8 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
|
||||
'autosubmit' => true,
|
||||
'disabled' => $toggleDisabled
|
||||
)
|
||||
),
|
||||
array(
|
||||
);
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
ToggleInstanceFeatureCommand::FEATURE_EVENT_HANDLERS,
|
||||
array(
|
||||
@ -107,8 +108,8 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
|
||||
'autosubmit' => true,
|
||||
'disabled' => $toggleDisabled
|
||||
)
|
||||
),
|
||||
array(
|
||||
);
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
ToggleInstanceFeatureCommand::FEATURE_FLAP_DETECTION,
|
||||
array(
|
||||
@ -116,8 +117,8 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
|
||||
'autosubmit' => true,
|
||||
'disabled' => $toggleDisabled
|
||||
)
|
||||
),
|
||||
array(
|
||||
);
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
ToggleInstanceFeatureCommand::FEATURE_NOTIFICATIONS,
|
||||
array(
|
||||
@ -136,8 +137,10 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
|
||||
),
|
||||
'disabled' => $toggleDisabled
|
||||
)
|
||||
),
|
||||
array(
|
||||
);
|
||||
|
||||
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,8 +175,10 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
|
||||
'autosubmit' => true,
|
||||
'disabled' => $toggleDisabled
|
||||
)
|
||||
),
|
||||
array(
|
||||
);
|
||||
}
|
||||
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
ToggleInstanceFeatureCommand::FEATURE_PERFORMANCE_DATA,
|
||||
array(
|
||||
@ -181,9 +186,7 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
|
||||
'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;
|
||||
}
|
||||
|
||||
|
@ -31,8 +31,8 @@ class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
|
||||
public function createElements(array $formData = array())
|
||||
{
|
||||
$toggleDisabled = $this->hasPermission('monitoring/command/feature/object') ? null : '';
|
||||
$this->addElements(array(
|
||||
array(
|
||||
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
ToggleObjectFeatureCommand::FEATURE_ACTIVE_CHECKS,
|
||||
array(
|
||||
@ -40,8 +40,8 @@ class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
|
||||
'autosubmit' => true,
|
||||
'disabled' => $toggleDisabled
|
||||
)
|
||||
),
|
||||
array(
|
||||
);
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
ToggleObjectFeatureCommand::FEATURE_PASSIVE_CHECKS,
|
||||
array(
|
||||
@ -49,8 +49,10 @@ class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
|
||||
'autosubmit' => true,
|
||||
'disabled' => $toggleDisabled
|
||||
)
|
||||
),
|
||||
array(
|
||||
);
|
||||
|
||||
if (! preg_match('~^v2\.\d+\.\d+.*$~', $this->getIcingaVersion())) {
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
ToggleObjectFeatureCommand::FEATURE_OBSESSING,
|
||||
array(
|
||||
@ -58,8 +60,10 @@ class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
|
||||
'autosubmit' => true,
|
||||
'disabled' => $toggleDisabled
|
||||
)
|
||||
),
|
||||
array(
|
||||
);
|
||||
}
|
||||
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
ToggleObjectFeatureCommand::FEATURE_NOTIFICATIONS,
|
||||
array(
|
||||
@ -67,8 +71,8 @@ class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
|
||||
'autosubmit' => true,
|
||||
'disabled' => $toggleDisabled
|
||||
)
|
||||
),
|
||||
array(
|
||||
);
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
ToggleObjectFeatureCommand::FEATURE_EVENT_HANDLER,
|
||||
array(
|
||||
@ -76,8 +80,8 @@ class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
|
||||
'autosubmit' => true,
|
||||
'disabled' => $toggleDisabled
|
||||
)
|
||||
),
|
||||
array(
|
||||
);
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
ToggleObjectFeatureCommand::FEATURE_FLAP_DETECTION,
|
||||
array(
|
||||
@ -85,9 +89,7 @@ class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
|
||||
'autosubmit' => true,
|
||||
'disabled' => $toggleDisabled
|
||||
)
|
||||
)
|
||||
));
|
||||
return $this;
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user