Skip to content

Commit ce7f0d2

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 428345d commit ce7f0d2

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
}
@@ -273,15 +273,27 @@ public function assembleFooter($item, HtmlDocument $footer, string $layout): voi
273273
}
274274

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

281287
if (! $item->active_checks_enabled) {
282-
$statusIcons->addHtml(
283-
new Icon('eye-slash', ['title' => $this->translate('Active checks disabled')])
284-
);
288+
$title = $isService
289+
? sprintf(
290+
$this->translate('Service "%s" on "%s" has active checks disabled'),
291+
$item->display_name,
292+
$item->host->display_name
293+
)
294+
: sprintf($this->translate('Host "%s" has active checks disabled'), $item->display_name);
295+
296+
$statusIcons->addHtml(new Icon(Icons::ACTIVE_CHECKS_DISABLED, ['title' => $title]));
285297
}
286298

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

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

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)