Skip to content

Commit 543c756

Browse files
committed
Add more state pictograms to state balls
Now also add pictograms to state ball in the following cases: - Disabled active checks - Disabled notifications
1 parent 541ce9b commit 543c756

File tree

3 files changed

+74
-9
lines changed

3 files changed

+74
-9
lines changed

library/Icingadb/Common/Icons.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ class Icons
2222

2323
const NOTIFICATION = 'bell';
2424

25+
const NOTIFICATIONS_DISABLED = 'bell-slash';
26+
27+
const ACTIVE_CHECKS_DISABLED = 'eye-slash';
28+
2529
const REMOVE = 'trash';
2630

2731
const USER = 'user';

library/Icingadb/View/BaseHostAndServiceRenderer.php

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function assembleVisual($item, HtmlDocument $visual, string $layout): voi
9696
}
9797
}
9898

99-
$stateChange->setIcon($item->state->getIcon());
99+
$stateChange->setIcon($this->getStateBallIcon($item));
100100
$stateChange->setHandled(
101101
$item->state->is_problem && ($item->state->is_handled || ! $item->state->is_reachable)
102102
);
@@ -109,7 +109,7 @@ public function assembleVisual($item, HtmlDocument $visual, string $layout): voi
109109
$ballSize = $layout === 'minimal' ? StateBall::SIZE_BIG : StateBall::SIZE_LARGE;
110110

111111
$stateBall = new StateBall($item->state->getStateText(), $ballSize);
112-
$stateBall->add($item->state->getIcon());
112+
$stateBall->add($this->getStateBallIcon($item));
113113
if ($item->state->is_problem && ($item->state->is_handled || ! $item->state->is_reachable)) {
114114
$stateBall->getAttributes()->add('class', 'handled');
115115
}
@@ -275,15 +275,27 @@ public function assembleFooter($item, HtmlDocument $footer, string $layout): voi
275275
}
276276

277277
if (! $item->notifications_enabled) {
278-
$statusIcons->addHtml(
279-
new Icon('bell-slash', ['title' => $this->translate('Notifications disabled')])
280-
);
278+
$title = $isService
279+
? sprintf(
280+
$this->translate('Service "%s" on "%s" has notifications disabled'),
281+
$item->display_name,
282+
$item->host->display_name
283+
)
284+
: sprintf($this->translate('Host "%s" has notifications disabled'), $item->display_name);
285+
286+
$statusIcons->addHtml(new Icon(Icons::NOTIFICATIONS_DISABLED, ['title' => $title]));
281287
}
282288

283289
if (! $item->active_checks_enabled) {
284-
$statusIcons->addHtml(
285-
new Icon('eye-slash', ['title' => $this->translate('Active checks disabled')])
286-
);
290+
$title = $isService
291+
? sprintf(
292+
$this->translate('Service "%s" on "%s" has active checks disabled'),
293+
$item->display_name,
294+
$item->host->display_name
295+
)
296+
: sprintf($this->translate('Host "%s" has active checks disabled'), $item->display_name);
297+
298+
$statusIcons->addHtml(new Icon(Icons::ACTIVE_CHECKS_DISABLED, ['title' => $title]));
287299
}
288300

289301
$performanceData = new HtmlElement('div', Attributes::create(['class' => 'performance-data']));
@@ -338,4 +350,31 @@ public function assemble($item, string $name, HtmlDocument $element, string $lay
338350

339351
return false;
340352
}
353+
354+
protected function getStateBallIcon($item): ?Icon
355+
{
356+
$icon = $item->state->getIcon();
357+
358+
if ($icon === null) {
359+
if (! $item->notifications_enabled) {
360+
$icon = new Icon(Icons::NOTIFICATIONS_DISABLED, [
361+
'title' => sprintf(
362+
'%s (%s)',
363+
strtoupper($item->state->getStateTextTranslated()),
364+
$this->translate('has notifications disabled')
365+
)
366+
]);
367+
} elseif (! $item->active_checks_enabled) {
368+
$icon = new Icon(Icons::ACTIVE_CHECKS_DISABLED, [
369+
'title' => sprintf(
370+
'%s (%s)',
371+
strtoupper($item->state->getStateTextTranslated()),
372+
$this->translate('has active checks disabled')
373+
)
374+
]);
375+
}
376+
}
377+
378+
return $icon;
379+
}
341380
}

library/Icingadb/Widget/ItemTable/StateRowItem.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Icinga\Module\Icingadb\Widget\ItemTable;
66

77
use Icinga\Module\Icingadb\Common\HostStates;
8+
use Icinga\Module\Icingadb\Common\Icons;
89
use Icinga\Module\Icingadb\Common\ServiceStates;
910
use Icinga\Module\Icingadb\Model\Host;
1011
use Icinga\Module\Icingadb\Util\PerfDataSet;
@@ -31,8 +32,29 @@ abstract class StateRowItem extends BaseStateRowItem
3132
protected function assembleVisual(BaseHtmlElement $visual)
3233
{
3334
$stateBall = new StateBall($this->item->state->getStateText(), StateBall::SIZE_LARGE);
34-
$stateBall->add($this->item->state->getIcon());
35+
$icon = $this->item->state->getIcon();
3536

37+
if ($icon === null) {
38+
if (! $this->item->notifications_enabled) {
39+
$icon = new Icon(Icons::NOTIFICATIONS_DISABLED, [
40+
'title' => sprintf(
41+
'%s (%s)',
42+
strtoupper($this->item->state->getStateTextTranslated()),
43+
t('has notifications disabled')
44+
)
45+
]);
46+
} elseif (! $this->item->active_checks_enabled) {
47+
$icon = new Icon(Icons::ACTIVE_CHECKS_DISABLED, [
48+
'title' => sprintf(
49+
'%s (%s)',
50+
strtoupper($this->item->state->getStateTextTranslated()),
51+
t('has active checks disabled')
52+
)
53+
]);
54+
}
55+
}
56+
57+
$stateBall->add($icon);
3658
$stateBall->setHandled($this->item->state->is_problem && (
3759
$this->item->state->is_handled || ! $this->item->state->is_reachable
3860
));

0 commit comments

Comments
 (0)