Skip to content

Commit

Permalink
Fix that unreachable hosts and services are not shown as such (#803)
Browse files Browse the repository at this point in the history
fixes #802
  • Loading branch information
nilmerg authored Jul 21, 2023
2 parents 4c5e601 + 966bb50 commit cd5f74b
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 160 deletions.
11 changes: 0 additions & 11 deletions library/Icingadb/Common/HostStates.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class HostStates

const DOWN = 1;

const UNREACHABLE = 2;

const PENDING = 99;

/**
Expand All @@ -35,9 +33,6 @@ public static function int(string $state): int
case 'down':
$int = self::DOWN;
break;
case 'unreachable':
$int = self::UNREACHABLE;
break;
case 'pending':
$int = self::PENDING;
break;
Expand Down Expand Up @@ -66,9 +61,6 @@ public static function text(int $state = null): string
case $state === self::DOWN:
$text = 'down';
break;
case $state === self::UNREACHABLE:
$text = 'unreachable';
break;
case $state === self::PENDING:
$text = 'pending';
break;
Expand Down Expand Up @@ -100,9 +92,6 @@ public static function translated(int $state = null): string
case $state === self::DOWN:
$text = t('down');
break;
case $state === self::UNREACHABLE:
$text = t('unreachable');
break;
case $state === self::PENDING:
$text = t('pending');
break;
Expand Down
32 changes: 17 additions & 15 deletions library/Icingadb/Common/StateBadges.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,17 @@ public function setUrl(Url $url): self
* Create a badge link
*
* @param mixed $content
* @param ?array $filter
* @param ?Filter\Rule $filter
*
* @return Link
*/
public function createLink($content, array $filter = null): Link
public function createLink($content, Filter\Rule $filter = null): Link
{
$url = clone $this->getUrl();

$urlFilter = Filter::all();
if (! empty($filter)) {
foreach ($filter as $column => $value) {
$urlFilter->add(Filter::equal($column, $value));
}
if ($filter !== null) {
$urlFilter->add($filter);
}

if ($this->hasBaseFilter()) {
Expand Down Expand Up @@ -146,7 +144,7 @@ protected function createBadge(string $state)
if (isset($this->item->$key) && $this->item->$key) {
return Html::tag('li', $this->createLink(
new StateBadge($this->item->$key, $state),
[$this->type . '.state.soft_state' => $this->getStateInt($state)]
Filter::equal($this->type . '.state.soft_state', $this->getStateInt($state))
));
}

Expand All @@ -169,20 +167,24 @@ protected function createGroup(string $state)
if (isset($this->item->$unhandledKey) && $this->item->$unhandledKey) {
$content[] = Html::tag('li', $this->createLink(
new StateBadge($this->item->$unhandledKey, $state),
[
$this->type . '.state.soft_state' => $this->getStateInt($state),
$this->type . '.state.is_handled' => 'n'
]
Filter::all(
Filter::equal($this->type . '.state.soft_state', $this->getStateInt($state)),
Filter::equal($this->type . '.state.is_handled', 'n'),
Filter::equal($this->type . '.state.is_reachable', 'y')
)
));
}

if (isset($this->item->$handledKey) && $this->item->$handledKey) {
$content[] = Html::tag('li', $this->createLink(
new StateBadge($this->item->$handledKey, $state, true),
[
$this->type . '.state.soft_state' => $this->getStateInt($state),
$this->type . '.state.is_handled' => 'y'
]
Filter::all(
Filter::equal($this->type . '.state.soft_state', $this->getStateInt($state)),
Filter::any(
Filter::equal($this->type . '.state.is_handled', 'y'),
Filter::equal($this->type . '.state.is_reachable', 'n')
)
)
));
}

Expand Down
45 changes: 25 additions & 20 deletions library/Icingadb/Model/Hostgroupsummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,36 +57,31 @@ public function getColumns()
return [
'display_name' => 'hostgroup_display_name',
'hosts_down_handled' => new Expression(
'SUM(CASE WHEN host_state = 1 AND host_handled = \'y\' THEN 1 ELSE 0 END)'
'SUM(CASE WHEN host_state = 1'
. ' AND (host_handled = \'y\' OR host_reachable = \'n\') THEN 1 ELSE 0 END)'
),
'hosts_down_unhandled' => new Expression(
'SUM(CASE WHEN host_state = 1 AND host_handled = \'n\' THEN 1 ELSE 0 END)'
'SUM(CASE WHEN host_state = 1'
. ' AND host_handled = \'n\' AND host_reachable = \'y\' THEN 1 ELSE 0 END)'
),
'hosts_pending' => new Expression(
'SUM(CASE WHEN host_state = 99 THEN 1 ELSE 0 END)'
),
'hosts_total' => new Expression(
'SUM(CASE WHEN host_id IS NOT NULL THEN 1 ELSE 0 END)'
),
'hosts_unreachable' => new Expression(
'SUM(CASE WHEN host_state = 2 THEN 1 ELSE 0 END)'
),
'hosts_unreachable_handled' => new Expression(
'SUM(CASE WHEN host_state = 2 AND host_handled = \'y\' THEN 1 ELSE 0 END)'
),
'hosts_unreachable_unhandled' => new Expression(
'SUM(CASE WHEN host_state = 2 AND host_handled = \'n\' THEN 1 ELSE 0 END)'
),
'hosts_up' => new Expression(
'SUM(CASE WHEN host_state = 0 THEN 1 ELSE 0 END)'
),
'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 @@ -98,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 @@ -138,10 +137,12 @@ public function getUnions()
'host_id' => 'host.id',
'host_state' => 'state.soft_state',
'host_handled' => 'state.is_handled',
'host_reachable' => 'state.is_reachable',
'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 @@ -157,10 +158,12 @@ public function getUnions()
'host_id' => new Expression('NULL'),
'host_state' => new Expression('NULL'),
'host_handled' => new Expression('NULL'),
'host_reachable' => new Expression('NULL'),
'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,10 +176,12 @@ public function getUnions()
'host_id' => new Expression('NULL'),
'host_state' => new Expression('NULL'),
'host_handled' => new Expression('NULL'),
'host_reachable' => new Expression('NULL'),
'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
15 changes: 2 additions & 13 deletions library/Icingadb/Model/HoststateSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public function getSummaryColumns()
),
'hosts_down_handled' => new Expression(
'SUM(CASE WHEN host_state.soft_state = 1'
. ' AND host_state.is_handled = \'y\' THEN 1 ELSE 0 END)'
. ' AND (host_state.is_handled = \'y\' OR host_state.is_reachable = \'n\') THEN 1 ELSE 0 END)'
),
'hosts_down_unhandled' => new Expression(
'SUM(CASE WHEN host_state.soft_state = 1'
. ' AND host_state.is_handled = \'n\' THEN 1 ELSE 0 END)'
. ' AND host_state.is_handled = \'n\' AND host_state.is_reachable = \'y\' THEN 1 ELSE 0 END)'
),
'hosts_event_handler_enabled' => new Expression(
'SUM(CASE WHEN host.event_handler_enabled = \'y\' THEN 1 ELSE 0 END)'
Expand All @@ -48,17 +48,6 @@ public function getSummaryColumns()
'hosts_total' => new Expression(
'SUM(CASE WHEN host.id IS NOT NULL THEN 1 ELSE 0 END)'
),
'hosts_unreachable' => new Expression(
'SUM(CASE WHEN host_state.soft_state = 2 THEN 1 ELSE 0 END)'
),
'hosts_unreachable_handled' => new Expression(
'SUM(CASE WHEN host_state.soft_state = 2'
. ' AND host_state.is_handled = \'y\' THEN 1 ELSE 0 END)'
),
'hosts_unreachable_unhandled' => new Expression(
'SUM(CASE WHEN host_state.soft_state = 2'
. ' AND host_state.is_handled = \'n\' THEN 1 ELSE 0 END)'
),
'hosts_up' => new Expression(
'SUM(CASE WHEN host_state.soft_state = 0 THEN 1 ELSE 0 END)'
)
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
13 changes: 13 additions & 0 deletions library/Icingadb/Model/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function getIcon(): ?Icon
switch (true) {
case $this->is_acknowledged:
$icon = new Icon(Icons::IS_ACKNOWLEDGED);

break;
case $this->in_downtime:
$icon = new Icon(
Expand All @@ -106,9 +107,21 @@ public function getIcon(): ?Icon
break;
case $this->is_flapping:
$icon = new Icon(Icons::IS_FLAPPING);

break;
case ! $this->is_reachable:
$icon = new Icon(Icons::HOST_DOWN, [
'title' => sprintf(
'%s (%s)',
strtoupper($this->getStateTextTranslated()),
t('is unreachable')
)
]);

break;
case $this->is_handled:
$icon = new Icon(Icons::HOST_DOWN);

break;
}

Expand Down
11 changes: 6 additions & 5 deletions library/Icingadb/Widget/Detail/CheckStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ protected function assembleBody(BaseHtmlElement $body)
$leftNow = 100;
} elseif ($nextCheckTime === null) {
$leftNow = 0;
} elseif (! $this->object->state->is_reachable && time() - $executionEndTime > $checkInterval * 2) {
// We have no way of knowing whether the dependency pauses check scheduling.
// The only way to detect this, is to measure how old the last update is.
$nextCheckTime = null;
$leftNow = 0;
} else {
$leftNow = 100 * (1 - ($nextCheckTime - time()) / ($nextCheckTime - $lastUpdateTime));
if ($leftNow > 100) {
Expand Down Expand Up @@ -294,11 +299,7 @@ protected function assembleHeader(BaseHtmlElement $header)
{
$checkSource = (new EmptyState(t('n. a.')))->setTag('span');
if ($this->object->state->check_source) {
$checkSource = [
new StateBall($this->object->state->is_reachable ? 'up' : 'down', StateBall::SIZE_MEDIUM),
' ',
$this->object->state->check_source
];
$checkSource = Text::create($this->object->state->check_source);
}

$header->addHtml(
Expand Down
Loading

0 comments on commit cd5f74b

Please sign in to comment.