Skip to content

Commit

Permalink
Properly visualize unreachable services
Browse files Browse the repository at this point in the history
* Lists show it in their visual and title area
* The tatical view includes a slice for them
* State badges (list footers, host-/servicegroups) also show a badge
  • Loading branch information
nilmerg committed Jul 20, 2023
1 parent 31a9d85 commit 842165c
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 49 deletions.
27 changes: 18 additions & 9 deletions library/Icingadb/Model/Hostgroupsummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ public function getColumns()
'hosts_severity' => new Expression('MAX(host_severity)'),
'name' => 'hostgroup_name',
'services_critical_handled' => new Expression(
'SUM(CASE WHEN service_state = 2 AND service_handled = \'y\' THEN 1 ELSE 0 END)'
'SUM(CASE WHEN service_state = 2'
. ' AND (service_handled = \'y\' OR service_reachable = \'n\') THEN 1 ELSE 0 END)'
),
'services_critical_unhandled' => new Expression(
'SUM(CASE WHEN service_state = 2 AND service_handled = \'n\' THEN 1 ELSE 0 END)'
'SUM(CASE WHEN service_state = 2'
. ' AND service_handled = \'n\' AND service_reachable = \'y\' THEN 1 ELSE 0 END)'
),
'services_ok' => new Expression(
'SUM(CASE WHEN service_state = 0 THEN 1 ELSE 0 END)'
Expand All @@ -91,16 +93,20 @@ public function getColumns()
'SUM(CASE WHEN service_id IS NOT NULL THEN 1 ELSE 0 END)'
),
'services_unknown_handled' => new Expression(
'SUM(CASE WHEN service_state = 3 AND service_handled = \'y\' THEN 1 ELSE 0 END)'
'SUM(CASE WHEN service_state = 3'
. ' AND (service_handled = \'y\' OR service_reachable = \'n\') THEN 1 ELSE 0 END)'
),
'services_unknown_unhandled' => new Expression(
'SUM(CASE WHEN service_state = 3 AND service_handled = \'n\' THEN 1 ELSE 0 END)'
'SUM(CASE WHEN service_state = 3'
. ' AND service_handled = \'n\' AND service_reachable = \'y\' THEN 1 ELSE 0 END)'
),
'services_warning_handled' => new Expression(
'SUM(CASE WHEN service_state = 1 AND service_handled = \'y\' THEN 1 ELSE 0 END)'
'SUM(CASE WHEN service_state = 1'
. ' AND (service_handled = \'y\' OR service_reachable = \'n\') THEN 1 ELSE 0 END)'
),
'services_warning_unhandled' => new Expression(
'SUM(CASE WHEN service_state = 1 AND service_handled = \'n\' THEN 1 ELSE 0 END)'
'SUM(CASE WHEN service_state = 1'
. ' AND service_handled = \'n\' AND service_reachable = \'y\' THEN 1 ELSE 0 END)'
)
];
}
Expand Down Expand Up @@ -135,7 +141,8 @@ public function getUnions()
'host_severity' => 'state.severity',
'service_id' => new Expression('NULL'),
'service_state' => new Expression('NULL'),
'service_handled' => new Expression('NULL')
'service_handled' => new Expression('NULL'),
'service_reachable' => new Expression('NULL')
]
],
[
Expand All @@ -155,7 +162,8 @@ public function getUnions()
'host_severity' => new Expression('0'),
'service_id' => 'service.id',
'service_state' => 'state.soft_state',
'service_handled' => 'state.is_handled'
'service_handled' => 'state.is_handled',
'service_reachable' => 'state.is_reachable'
]
],
[
Expand All @@ -172,7 +180,8 @@ public function getUnions()
'host_severity' => new Expression('0'),
'service_id' => new Expression('NULL'),
'service_state' => new Expression('NULL'),
'service_handled' => new Expression('NULL')
'service_handled' => new Expression('NULL'),
'service_reachable' => new Expression('NULL')
]
]
];
Expand Down
20 changes: 14 additions & 6 deletions library/Icingadb/Model/ServicegroupSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ public function getColumns()
'display_name' => 'servicegroup_display_name',
'name' => 'servicegroup_name',
'services_critical_handled' => new Expression(
'SUM(CASE WHEN service_state = 2 AND service_handled = \'y\' THEN 1 ELSE 0 END)'
'SUM(CASE WHEN service_state = 2'
. ' AND (service_handled = \'y\' OR service_reachable = \'n\') THEN 1 ELSE 0 END)'
),
'services_critical_unhandled' => new Expression(
'SUM(CASE WHEN service_state = 2 AND service_handled = \'n\' THEN 1 ELSE 0 END)'
'SUM(CASE WHEN service_state = 2'
. ' AND service_handled = \'n\' AND service_reachable = \'y\' THEN 1 ELSE 0 END)'
),
'services_ok' => new Expression(
'SUM(CASE WHEN service_state = 0 THEN 1 ELSE 0 END)'
Expand All @@ -73,16 +75,20 @@ public function getColumns()
'SUM(CASE WHEN service_id IS NOT NULL THEN 1 ELSE 0 END)'
),
'services_unknown_handled' => new Expression(
'SUM(CASE WHEN service_state = 3 AND service_handled = \'y\' THEN 1 ELSE 0 END)'
'SUM(CASE WHEN service_state = 3'
. ' AND (service_handled = \'y\' OR service_reachable = \'n\') THEN 1 ELSE 0 END)'
),
'services_unknown_unhandled' => new Expression(
'SUM(CASE WHEN service_state = 3 AND service_handled = \'n\' THEN 1 ELSE 0 END)'
'SUM(CASE WHEN service_state = 3'
. ' AND service_handled = \'n\' AND service_reachable = \'y\' THEN 1 ELSE 0 END)'
),
'services_warning_handled' => new Expression(
'SUM(CASE WHEN service_state = 1 AND service_handled = \'y\' THEN 1 ELSE 0 END)'
'SUM(CASE WHEN service_state = 1'
. ' AND (service_handled = \'y\' OR service_reachable = \'n\') THEN 1 ELSE 0 END)'
),
'services_warning_unhandled' => new Expression(
'SUM(CASE WHEN service_state = 1 AND service_handled = \'n\' THEN 1 ELSE 0 END)'
'SUM(CASE WHEN service_state = 1'
. ' AND service_handled = \'n\' AND service_reachable = \'y\' THEN 1 ELSE 0 END)'
),
'services_severity' => new Expression('MAX(service_severity)')
];
Expand Down Expand Up @@ -114,6 +120,7 @@ public function getUnions()
'service_id' => 'service.id',
'service_state' => 'state.soft_state',
'service_handled' => 'state.is_handled',
'service_reachable' => 'state.is_reachable',
'service_severity' => 'state.severity'
]
],
Expand All @@ -127,6 +134,7 @@ public function getUnions()
'service_id' => new Expression('NULL'),
'service_state' => new Expression('NULL'),
'service_handled' => new Expression('NULL'),
'service_reachable' => new Expression('NULL'),
'service_severity' => new Expression('0')
]
]
Expand Down
12 changes: 6 additions & 6 deletions library/Icingadb/Model/ServicestateSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public function getSummaryColumns()
),
'services_critical_handled' => new Expression(
'SUM(CASE WHEN service_state.soft_state = 2'
. ' AND service_state.is_handled = \'y\' THEN 1 ELSE 0 END)'
. ' AND (service_state.is_handled = \'y\' OR service_state.is_reachable = \'n\') THEN 1 ELSE 0 END)'
),
'services_critical_unhandled' => new Expression(
'SUM(CASE WHEN service_state.soft_state = 2'
. ' AND service_state.is_handled = \'n\' THEN 1 ELSE 0 END)'
. ' AND service_state.is_handled = \'n\' AND service_state.is_reachable = \'y\' THEN 1 ELSE 0 END)'
),
'services_event_handler_enabled' => new Expression(
'SUM(CASE WHEN service.event_handler_enabled = \'y\' THEN 1 ELSE 0 END)'
Expand All @@ -53,19 +53,19 @@ public function getSummaryColumns()
),
'services_unknown_handled' => new Expression(
'SUM(CASE WHEN service_state.soft_state = 3'
. ' AND service_state.is_handled = \'y\' THEN 1 ELSE 0 END)'
. ' AND (service_state.is_handled = \'y\' OR service_state.is_reachable = \'n\') THEN 1 ELSE 0 END)'
),
'services_unknown_unhandled' => new Expression(
'SUM(CASE WHEN service_state.soft_state = 3'
. ' AND service_state.is_handled = \'n\' THEN 1 ELSE 0 END)'
. ' AND service_state.is_handled = \'n\' AND service_state.is_reachable = \'y\' THEN 1 ELSE 0 END)'
),
'services_warning_handled' => new Expression(
'SUM(CASE WHEN service_state.soft_state = 1'
. ' AND service_state.is_handled = \'y\' THEN 1 ELSE 0 END)'
. ' AND (service_state.is_handled = \'y\' OR service_state.is_reachable = \'n\') THEN 1 ELSE 0 END)'
),
'services_warning_unhandled' => new Expression(
'SUM(CASE WHEN service_state.soft_state = 1'
. ' AND service_state.is_handled = \'n\' THEN 1 ELSE 0 END)'
. ' AND service_state.is_handled = \'n\' AND service_state.is_reachable = \'y\' THEN 1 ELSE 0 END)'
)
];
}
Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Widget/ItemList/ServiceDetailHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function assembleVisual(BaseHtmlElement $visual)
}

$stateChange->setIcon($this->state->getIcon());
$stateChange->setHandled($this->state->is_handled);
$stateChange->setHandled($this->state->is_handled || ! $this->state->is_reachable);

$visual->addHtml($stateChange);
}
Expand Down
73 changes: 46 additions & 27 deletions library/Icingadb/Widget/ItemTable/ServicegroupGridCell.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Icinga\Module\Icingadb\Widget\ItemTable;

use ipl\Stdlib\Filter;
use ipl\Web\Filter\QueryString;
use ipl\Web\Url;
use ipl\Web\Widget\Link;
use ipl\Web\Widget\StateBadge;
Expand All @@ -16,15 +18,17 @@ class ServicegroupGridCell extends BaseServiceGroupItem

protected function createGroupBadge(): Link
{
$url = Url::fromPath('icingadb/services/grid')->addParams(['servicegroup.name' => $this->item->name]);
$url = Url::fromPath('icingadb/services/grid');
$urlFilter = Filter::all(Filter::equal('servicegroup.name', $this->item->name));

if ($this->item->services_critical_unhandled > 0) {
$urlFilter->add(Filter::equal('service.state.soft_state', 2))
->add(Filter::equal('service.state.is_handled', 'n'))
->add(Filter::equal('service.state.is_reachable', 'y'));

return new Link(
new StateBadge($this->item->services_critical_unhandled, 'critical'),
$url->addParams([
'state.soft_state' => 2,
'state.is_handled' => 'n'
]),
$url->setQueryString(QueryString::render($urlFilter)),
[
'title' => sprintf(
$this->translatePlural(
Expand All @@ -38,12 +42,15 @@ protected function createGroupBadge(): Link
]
);
} elseif ($this->item->services_critical_handled > 0) {
$urlFilter->add(Filter::equal('service.state.soft_state', 2))
->add(Filter::any(
Filter::equal('service.state.is_handled', 'y'),
Filter::equal('service.state.is_reachable', 'n')
));

return new Link(
new StateBadge($this->item->services_critical_handled, 'critical', true),
$url->addParams([
'state.soft_state' => 2,
'state.is_handled' => 'y'
]),
$url->setQueryString(QueryString::render($urlFilter)),
[
'title' => sprintf(
$this->translatePlural(
Expand All @@ -59,12 +66,13 @@ protected function createGroupBadge(): Link
]
);
} elseif ($this->item->services_warning_unhandled > 0) {
$urlFilter->add(Filter::equal('service.state.soft_state', 1))
->add(Filter::equal('service.state.is_handled', 'n'))
->add(Filter::equal('service.state.is_reachable', 'y'));

return new Link(
new StateBadge($this->item->services_warning_unhandled, 'warning'),
$url->addParams([
'state.soft_state' => 1,
'state.is_handled' => 'n'
]),
$url->setQueryString(QueryString::render($urlFilter)),
[
'title' => sprintf(
$this->translatePlural(
Expand All @@ -78,12 +86,15 @@ protected function createGroupBadge(): Link
]
);
} elseif ($this->item->services_warning_handled > 0) {
$urlFilter->add(Filter::equal('service.state.soft_state', 1))
->add(Filter::any(
Filter::equal('service.state.is_handled', 'y'),
Filter::equal('service.state.is_reachable', 'n')
));

return new Link(
new StateBadge($this->item->services_warning_handled, 'warning', true),
$url->addParams([
'state.soft_state' => 1,
'state.is_handled' => 'y'
]),
$url->setQueryString(QueryString::render($urlFilter)),
[
'title' => sprintf(
$this->translatePlural(
Expand All @@ -99,12 +110,13 @@ protected function createGroupBadge(): Link
]
);
} elseif ($this->item->services_unknown_unhandled > 0) {
$urlFilter->add(Filter::equal('service.state.soft_state', 3))
->add(Filter::equal('service.state.is_handled', 'n'))
->add(Filter::equal('service.state.is_reachable', 'y'));

return new Link(
new StateBadge($this->item->services_unknown_unhandled, 'unknown'),
$url->addParams([
'state.soft_state' => 3,
'state.is_handled' => 'n'
]),
$url->setQueryString(QueryString::render($urlFilter)),
[
'title' => sprintf(
$this->translatePlural(
Expand All @@ -118,12 +130,15 @@ protected function createGroupBadge(): Link
]
);
} elseif ($this->item->services_unknown_handled > 0) {
$urlFilter->add(Filter::equal('service.state.soft_state', 3))
->add(Filter::any(
Filter::equal('service.state.is_handled', 'y'),
Filter::equal('service.state.is_reachable', 'n')
));

return new Link(
new StateBadge($this->item->services_unknown_handled, 'unknown', true),
$url->addParams([
'state.soft_state' => 3,
'state.is_handled' => 'y'
]),
$url->setQueryString(QueryString::render($urlFilter)),
[
'title' => sprintf(
$this->translatePlural(
Expand All @@ -139,9 +154,11 @@ protected function createGroupBadge(): Link
]
);
} elseif ($this->item->services_pending > 0) {
$urlFilter->add(Filter::equal('service.state.soft_state', 99));

return new Link(
new StateBadge($this->item->services_pending, 'pending'),
$url->addParams(['state.soft_state' => 99]),
$url->setQueryString(QueryString::render($urlFilter)),
[
'title' => sprintf(
$this->translatePlural(
Expand All @@ -155,9 +172,11 @@ protected function createGroupBadge(): Link
]
);
} elseif ($this->item->services_ok > 0) {
$urlFilter->add(Filter::equal('service.state.soft_state', 0));

return new Link(
new StateBadge($this->item->services_ok, 'ok'),
$url->addParams(['state.soft_state' => 0]),
$url->setQueryString(QueryString::render($urlFilter)),
[
'title' => sprintf(
$this->translatePlural(
Expand Down

0 comments on commit 842165c

Please sign in to comment.