diff --git a/library/Icingadb/Model/Hostgroupsummary.php b/library/Icingadb/Model/Hostgroupsummary.php index 25186b9d4..4046412fd 100644 --- a/library/Icingadb/Model/Hostgroupsummary.php +++ b/library/Icingadb/Model/Hostgroupsummary.php @@ -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)' ), @@ -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') ] ], [ @@ -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' ] ], [ @@ -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') ] ] ]; diff --git a/library/Icingadb/Model/ServiceState.php b/library/Icingadb/Model/ServiceState.php index 9de2a21e1..8d8475624 100644 --- a/library/Icingadb/Model/ServiceState.php +++ b/library/Icingadb/Model/ServiceState.php @@ -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); } @@ -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); } } diff --git a/library/Icingadb/Model/ServicegroupSummary.php b/library/Icingadb/Model/ServicegroupSummary.php index b43de0918..cf69c791f 100644 --- a/library/Icingadb/Model/ServicegroupSummary.php +++ b/library/Icingadb/Model/ServicegroupSummary.php @@ -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)' ), @@ -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' ] ], @@ -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') ] ] diff --git a/library/Icingadb/Model/ServicestateSummary.php b/library/Icingadb/Model/ServicestateSummary.php index 03a012c83..125e2640e 100644 --- a/library/Icingadb/Model/ServicestateSummary.php +++ b/library/Icingadb/Model/ServicestateSummary.php @@ -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)' diff --git a/library/Icingadb/Widget/ItemList/ServiceDetailHeader.php b/library/Icingadb/Widget/ItemList/ServiceDetailHeader.php index a9ad7bbee..ed2b78357 100644 --- a/library/Icingadb/Widget/ItemList/ServiceDetailHeader.php +++ b/library/Icingadb/Widget/ItemList/ServiceDetailHeader.php @@ -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') { @@ -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); } diff --git a/library/Icingadb/Widget/ServiceStateBadges.php b/library/Icingadb/Widget/ServiceStateBadges.php index 945ea0d81..51eb90f13 100644 --- a/library/Icingadb/Widget/ServiceStateBadges.php +++ b/library/Icingadb/Widget/ServiceStateBadges.php @@ -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 { @@ -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') ])); diff --git a/library/Icingadb/Widget/ServiceSummaryDonut.php b/library/Icingadb/Widget/ServiceSummaryDonut.php index 71eb78107..fd4cd5685 100644 --- a/library/Icingadb/Widget/ServiceSummaryDonut.php +++ b/library/Icingadb/Widget/ServiceSummaryDonut.php @@ -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([