Skip to content

Commit

Permalink
Add new Host from Filter and Service from Filter in AddNodeForm.php
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg authored and ValeDaRold committed Aug 3, 2021
1 parent 65849bd commit 0a01aae
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 0 deletions.
116 changes: 116 additions & 0 deletions application/forms/AddNodeForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public function setup()
case 'new-process':
$this->addNewProcess();
break;
case 'hosts_from_filter':
$this->selectHostsFromFilter();
break;
case 'services_from_filter':
$this->selectServicesFromFilter();
break;
case null:
$this->setSubmitLabel($this->translate('Next'));
return;
Expand Down Expand Up @@ -157,6 +163,8 @@ protected function selectNodeType()
if ($this->hasParentNode()) {
$types['host'] = $this->translate('Host');
$types['service'] = $this->translate('Service');
$types['hosts_from_filter'] = $this->translate('Hosts from filter');
$types['services_from_filter'] = $this->translate('Services from filter');
} elseif (! $this->hasProcesses()) {
$this->addElement('hidden', 'node_type', array(
'ignore' => true,
Expand Down Expand Up @@ -248,6 +256,53 @@ protected function addServicesElement($host)
]);
}

protected function addFilteredHostsElement($filter)
{
$this->addElement('submit', 'refresh', [
'label' => $this->translate('Refresh'),
'class' => 'refresh-filter'
]);
$this->addElement('multiselect', 'children', [
'label' => $this->translate('Hosts'),
'required' => true,
'size' => 8,
'style' => 'width: 25em',
'multiOptions' => $this->enumHostListByFilter($filter),
'description' => $this->translate(
'Hosts that should be part of this business process node'
),
'validators' => [[new NoDuplicateChildrenValidator($this, $this->bp, $this->parent), true]]
]);
}

protected function addFilteredServicesElement($filter)
{
$this->addElement('submit', 'refresh', [
'label' => $this->translate('Refresh'),
'class' => 'refresh-filter'
]);
$this->addElement('multiselect', 'children', [
'label' => $this->translate('Services'),
'required' => true,
'size' => 8,
'style' => 'width: 25em',
'multiOptions' => $this->enumServiceListByFilter($filter),
'description' => $this->translate(
'Services that should be part of this business process node'
),
'validators' => [[new NoDuplicateChildrenValidator($this, $this->bp, $this->parent), true]]
]);
}

protected function addFilterElement()
{
$this->addElement('text', 'filter', array(
'label' => $this->translate('Filter'),
'required' => true,
'ignore' => true
));
}

protected function addFileElement()
{
$this->addElement('select', 'file', [
Expand Down Expand Up @@ -301,6 +356,26 @@ protected function addServiceOverrideElement()
]);
}

protected function selectHostsFromFilter()
{
$this->addFilterElement();
if ($filter = $this->getSentValue('filter')) {
$this->addFilteredHostsElement($filter);
} else {
$this->setSubmitLabel($this->translate('Next'));
}
}

protected function selectServicesFromFilter()
{
$this->addFilterElement();
if ($filter = $this->getSentValue('filter')) {
$this->addFilteredServicesElement($filter);
} else {
$this->setSubmitLabel($this->translate('Next'));
}
}

protected function selectProcess()
{
if ($this->hasParentNode()) {
Expand Down Expand Up @@ -463,6 +538,45 @@ protected function enumServiceStateList()
return $serviceStateList;
}

protected function enumHostListByFilter($filter)
{
$names = $this->backend
->select()
->from('hostStatus', ['hostname' => 'host_name'])
->applyFilter($this->getCustomFilterWithRestriction('monitoring/filter/objects', $filter))
->order('host_name')
->getQuery()
->fetchColumn();

// fetchPairs doesn't seem to work when using the same column with
// different aliases twice
$res = array();
$suffix = ';Hoststatus';
foreach ($names as $name) {
$res[$name . $suffix] = $name;
}

return $res;
}

protected function enumServiceListByFilter($filter)
{
$objects = $this->backend
->select()
->from('serviceStatus', ['host' => 'host_name', 'service' => 'service_description'])
->applyFilter($this->getCustomFilterWithRestriction('monitoring/filter/objects', $filter))
->order('service_description')
->getQuery()
->fetchAll();

$services = array();
foreach ($objects as $object) {
$services[$object->host . ';' . $object->service] = $object->host . ':' . $object->service;
}

return $services;
}

protected function hasProcesses()
{
return count($this->enumProcesses()) > 0;
Expand Down Expand Up @@ -552,6 +666,8 @@ public function onSuccess()

// Fallthrough
case 'process':
case 'hosts_from_filter':
case 'services_from_filter':
if ($this->hasParentNode()) {
$changes->addChildrenToNode($this->getValue('children'), $this->parent);
} else {
Expand Down
Binary file modified application/locale/de_DE/LC_MESSAGES/businessprocess.mo
Binary file not shown.
12 changes: 12 additions & 0 deletions application/locale/de_DE/LC_MESSAGES/businessprocess.po
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,18 @@ msgid "You are lacking permission to access service \"%s\" on host \"%s\""
msgstr ""
"Nicht genügend Berechtigungen für Zugriff auf Service \"%s\" in Host \"%s\""

msgid "Hosts from filter"
msgstr "Hosts aus Filter"

msgid "Services from filter"
msgstr "Services aus Filter"

msgid "Refresh"
msgstr "Aktualisieren"

msgid "Filter"
msgstr "Filter"

#~ msgid "(no process config chosen)"
#~ msgstr "(keine Prozess-Konfiguration gewählt)"

Expand Down
Binary file modified application/locale/it_IT/LC_MESSAGES/businessprocess.mo
Binary file not shown.
27 changes: 27 additions & 0 deletions application/locale/it_IT/LC_MESSAGES/businessprocess.po
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,30 @@ msgstr "Avvisi"
#: /usr/local/icingaweb-modules/businessprocess/application/forms/ProcessForm.php:40
msgid "min"
msgstr "min"

msgid "Hosts from filter"
msgstr "Host selezionati tramite filtro"

msgid "Services from filter"
msgstr "Servizi selezionati tramite filtro"

msgid "Refresh"
msgstr "Aggiorna"

msgid "Hosts"
msgstr "Host"

msgid "Services"
msgstr "Servizi"

msgid "Hosts that should be part of this business process node"
msgstr "Host che devono far parte di questo nodo del processo business"

msgid "Services that should be part of this business process node"
msgstr "Servizi che devono far parte di questo nodo del processo business"

msgid "Filter"
msgstr "Filtro"

msgid "Next"
msgstr "Avanti"
28 changes: 28 additions & 0 deletions library/Businessprocess/MonitoringRestrictions.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,32 @@ function ($c) {

return $restriction;
}

public function getCustomFilterWithRestriction($restrictionName, $filterQueryString) {
$filter = $this->getRestriction($restrictionName);

try {
$filter->addFilter(Filter::fromQueryString($filterQueryString));
} catch (QueryException $e) {
throw new ConfigurationError(
mt(
'monitoring',
'Cannot apply restriction %s using the filter %s. You can only use the following columns: %s'
),
$restrictionName,
$filterQueryString,
implode(', ', array(
'instance_name',
'host_name',
'hostgroup_name',
'service_description',
'servicegroup_name',
'_(host|service)_<customvar-name>'
)),
$e
);
}

return $filter;
}
}

0 comments on commit 0a01aae

Please sign in to comment.