mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2026-02-02 16:39:25 -05:00
state_overrides: Also fully support hosts
This commit is contained in:
parent
ec54b6df57
commit
1cc9187e0a
3 changed files with 84 additions and 6 deletions
|
|
@ -200,6 +200,11 @@ class AddNodeForm extends QuickForm
|
|||
),
|
||||
'validators' => [[new NoDuplicateChildrenValidator($this, $this->bp, $this->parent), true]]
|
||||
]);
|
||||
|
||||
$this->addHostOverrideCheckbox();
|
||||
if ($this->getSentValue('host_override') === '1') {
|
||||
$this->addHostOverrideElement();
|
||||
}
|
||||
}
|
||||
|
||||
protected function selectService()
|
||||
|
|
@ -258,6 +263,25 @@ class AddNodeForm extends QuickForm
|
|||
]);
|
||||
}
|
||||
|
||||
protected function addHostOverrideCheckbox()
|
||||
{
|
||||
$this->addElement('checkbox', 'host_override', [
|
||||
'ignore' => true,
|
||||
'class' => 'autosubmit',
|
||||
'label' => $this->translate('Override Host State'),
|
||||
'description' => $this->translate('Enable host state overrides')
|
||||
]);
|
||||
}
|
||||
|
||||
protected function addHostOverrideElement()
|
||||
{
|
||||
$this->addElement('stateOverrides', 'stateOverrides', [
|
||||
'required' => true,
|
||||
'label' => $this->translate('State Overrides'),
|
||||
'states' => $this->enumHostStateList()
|
||||
]);
|
||||
}
|
||||
|
||||
protected function addServiceOverrideCheckbox()
|
||||
{
|
||||
$this->addElement('checkbox', 'service_override', [
|
||||
|
|
@ -396,6 +420,17 @@ class AddNodeForm extends QuickForm
|
|||
return $res;
|
||||
}
|
||||
|
||||
protected function enumHostStateList()
|
||||
{
|
||||
$hostStateList = [
|
||||
0 => $this->translate('UP'),
|
||||
1 => $this->translate('DOWN'),
|
||||
99 => $this->translate('PENDING')
|
||||
];
|
||||
|
||||
return $hostStateList;
|
||||
}
|
||||
|
||||
protected function enumServiceList($host)
|
||||
{
|
||||
$names = $this->backend
|
||||
|
|
@ -501,19 +536,21 @@ class AddNodeForm extends QuickForm
|
|||
{
|
||||
$changes = ProcessChanges::construct($this->bp, $this->session);
|
||||
switch ($this->getValue('node_type')) {
|
||||
case 'host':
|
||||
case 'service':
|
||||
$stateOverrides = $this->getValue('stateOverrides');
|
||||
if (! empty($stateOverrides)) {
|
||||
$services = [];
|
||||
$childOverrides = [];
|
||||
foreach ($this->getValue('children') as $service) {
|
||||
$services[$service] = $stateOverrides;
|
||||
$childOverrides[$service] = $stateOverrides;
|
||||
}
|
||||
|
||||
$changes->modifyNode($this->parent, [
|
||||
'stateOverrides' => array_merge($this->parent->getStateOverrides(), $services)
|
||||
'stateOverrides' => array_merge($this->parent->getStateOverrides(), $childOverrides)
|
||||
]);
|
||||
}
|
||||
case 'host':
|
||||
|
||||
// Fallthrough
|
||||
case 'process':
|
||||
if ($this->hasParentNode()) {
|
||||
$changes->addChildrenToNode($this->getValue('children'), $this->parent);
|
||||
|
|
|
|||
|
|
@ -182,6 +182,14 @@ class EditNodeForm extends QuickForm
|
|||
'description' => $this->translate('The host for this business process node'),
|
||||
'validators' => [[new NoDuplicateChildrenValidator($this, $this->bp, $this->parent), true]]
|
||||
));
|
||||
|
||||
$this->addHostOverrideCheckbox();
|
||||
$hostOverrideSent = $this->getSentValue('host_override');
|
||||
if ($hostOverrideSent === '1'
|
||||
|| ($hostOverrideSent === null && $this->getElement('host_override')->isChecked())
|
||||
) {
|
||||
$this->addHostOverrideElement();
|
||||
}
|
||||
}
|
||||
|
||||
protected function selectService()
|
||||
|
|
@ -218,6 +226,27 @@ class EditNodeForm extends QuickForm
|
|||
$this->getElement('hosts')->setValue($this->host);
|
||||
}
|
||||
|
||||
protected function addHostOverrideCheckbox()
|
||||
{
|
||||
$this->addElement('checkbox', 'host_override', [
|
||||
'ignore' => true,
|
||||
'class' => 'autosubmit',
|
||||
'value' => ! empty($this->parent->getStateOverrides($this->node->getName())),
|
||||
'label' => $this->translate('Override Host State'),
|
||||
'description' => $this->translate('Enable host state overrides')
|
||||
]);
|
||||
}
|
||||
|
||||
protected function addHostOverrideElement()
|
||||
{
|
||||
$this->addElement('stateOverrides', 'stateOverrides', [
|
||||
'required' => true,
|
||||
'states' => $this->enumHostStateList(),
|
||||
'value' => $this->parent->getStateOverrides($this->node->getName()),
|
||||
'label' => $this->translate('State Overrides')
|
||||
]);
|
||||
}
|
||||
|
||||
protected function addServicesElement($host)
|
||||
{
|
||||
$this->addElement('select', 'children', array(
|
||||
|
|
@ -351,6 +380,17 @@ class EditNodeForm extends QuickForm
|
|||
return $res;
|
||||
}
|
||||
|
||||
protected function enumHostStateList()
|
||||
{
|
||||
$hostStateList = [
|
||||
0 => $this->translate('UP'),
|
||||
1 => $this->translate('DOWN'),
|
||||
99 => $this->translate('PENDING')
|
||||
];
|
||||
|
||||
return $hostStateList;
|
||||
}
|
||||
|
||||
protected function enumServiceList($host)
|
||||
{
|
||||
$names = $this->backend
|
||||
|
|
@ -447,6 +487,7 @@ class EditNodeForm extends QuickForm
|
|||
$changes->deleteNode($this->node, $this->parent->getName());
|
||||
|
||||
switch ($this->getValue('node_type')) {
|
||||
case 'host':
|
||||
case 'service':
|
||||
$stateOverrides = $this->getValue('stateOverrides') ?: [];
|
||||
if (! empty($stateOverrides)) {
|
||||
|
|
@ -460,7 +501,7 @@ class EditNodeForm extends QuickForm
|
|||
}
|
||||
|
||||
$changes->modifyNode($this->parent, ['stateOverrides' => $stateOverrides]);
|
||||
case 'host':
|
||||
// Fallthrough
|
||||
case 'process':
|
||||
$changes->addChildrenToNode($this->getValue('children'), $this->parent);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
Business processes utilize their children's states to calculate their own state.
|
||||
While you can influence this with [operators](09-Operators.md), it's also possible
|
||||
to override individual states. (Currently this applies only to service nodes.)
|
||||
to override individual states. (This applies to host and service nodes.)
|
||||
|
||||
## Configuring Overrides
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue