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 10, 2023
1 parent 5b473ed commit 74b5a5d
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 6 deletions.
12 changes: 9 additions & 3 deletions library/Icingadb/Model/Hostgroupsummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public function getColumns()
'services_total' => new Expression(
'SUM(CASE WHEN service_id IS NOT NULL THEN 1 ELSE 0 END)'
),
'services_unreachable' => new Expression(
'SUM(CASE WHEN service_reachable = \'n\' 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)'
),
Expand Down Expand Up @@ -136,7 +139,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 @@ -156,7 +160,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 @@ -173,7 +178,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
8 changes: 8 additions & 0 deletions library/Icingadb/Model/ServiceState.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public function createRelations(Relations $relations)
*/
public function getStateText(): string
{
if ($this->is_reachable === false) { // May be null, that's why it's strict
return 'unreachable';
}

return ServiceStates::text($this->soft_state);
}

Expand All @@ -81,6 +85,10 @@ public function getStateText(): string
*/
public function getStateTextTranslated(): string
{
if (! $this->is_reachable) { // May be null, that's why it's strict
return t('unreachable');
}

return ServiceStates::text($this->soft_state);
}
}
5 changes: 5 additions & 0 deletions library/Icingadb/Model/ServicegroupSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public function getColumns()
'services_total' => new Expression(
'SUM(CASE WHEN service_id IS NOT NULL THEN 1 ELSE 0 END)'
),
'services_unreachable' => new Expression(
'SUM(CASE WHEN service_reachable = \'n\' 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)'
),
Expand Down Expand Up @@ -114,6 +117,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 +131,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
3 changes: 3 additions & 0 deletions library/Icingadb/Model/ServicestateSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public function getSummaryColumns()
'services_total' => new Expression(
'SUM(CASE WHEN service.id IS NOT NULL THEN 1 ELSE 0 END)'
),
'services_unreachable' => new Expression(
'SUM(CASE WHEN service_state.is_reachable = \'n\' THEN 1 ELSE 0 END)'
),
'services_unknown_handled' => new Expression(
'SUM(CASE WHEN service_state.soft_state = 3'
. ' AND service_state.is_handled = \'y\' THEN 1 ELSE 0 END)'
Expand Down
15 changes: 12 additions & 3 deletions library/Icingadb/Widget/ItemList/ServiceDetailHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ protected function assembleVisual(BaseHtmlElement $visual)
}
}

$state = ServiceStates::text($this->state->$stateType);
$previousState = ServiceStates::text($this->state->$previousStateType);
$state = $this->state->getStateText();
if ($this->state->is_reachable) {
$previousState = ServiceStates::text($this->state->$previousStateType);
} else {
$previousState = ServiceStates::text($this->state->$stateType);
$previousStateType = "previous_$stateType";
$stateType = null;
}

$stateChange = new StateChange($state, $previousState);
if ($stateType === 'soft_state') {
Expand All @@ -50,7 +56,10 @@ protected function assembleVisual(BaseHtmlElement $visual)
}

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

if ($this->state->is_reachable) {
$stateChange->setHandled($this->state->is_handled);
}

$visual->addHtml($stateChange);
}
Expand Down
11 changes: 11 additions & 0 deletions library/Icingadb/Widget/ServiceStateBadges.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

use Icinga\Module\Icingadb\Common\Links;
use Icinga\Module\Icingadb\Common\ServiceStates;
use ipl\Html\HtmlElement;
use ipl\Web\Common\StateBadges;
use ipl\Web\Url;
use ipl\Web\Widget\StateBadge;

class ServiceStateBadges extends StateBadges
{
Expand Down Expand Up @@ -35,10 +37,19 @@ protected function assemble()
{
$this->addAttributes(['class' => 'service-state-badges']);

$unreachableServices = null;
if ($this->item->services_unreachable > 0) {
$unreachableServices = new HtmlElement('li', null, $this->createLink(
new StateBadge($this->item->services_unreachable, 'unreachable'),
[$this->type . '.state.is_reachable' => 'n']
));
}

$this->add(array_filter([
$this->createGroup('critical'),
$this->createGroup('warning'),
$this->createGroup('unknown'),
$unreachableServices,
$this->createBadge('ok'),
$this->createBadge('pending')
]));
Expand Down
1 change: 1 addition & 0 deletions library/Icingadb/Widget/ServiceSummaryDonut.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ protected function assembleBody(BaseHtmlElement $body)
->addSlice($this->summary->services_critical_unhandled, ['class' => 'slice-state-critical'])
->addSlice($this->summary->services_unknown_handled, ['class' => 'slice-state-unknown-handled'])
->addSlice($this->summary->services_unknown_unhandled, ['class' => 'slice-state-unknown'])
->addSlice($this->summary->services_unreachable, ['class' => 'slice-state-unreachable'])
->addSlice($this->summary->services_pending, ['class' => 'slice-state-pending'])
->setLabelBig($this->summary->services_critical_unhandled)
->setLabelBigUrl(Links::services()->setQueryString(QueryString::render($labelBigUrlFilter))->addParams([
Expand Down

0 comments on commit 74b5a5d

Please sign in to comment.