1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
<?php
/* Icinga DB Web | (c) 2023 Icinga GmbH | GPLv2 */
namespace Icinga\Module\Icingadb\Widget\ItemTable;
use ipl\Stdlib\Filter;
use ipl\Web\Url;
use ipl\Web\Widget\Link;
use ipl\Web\Widget\StateBadge;
class HostgroupGridCell extends BaseHostGroupItem
{
use GridCellLayout;
protected $defaultAttributes = ['class' => ['group-grid-cell', 'hostgroup-grid-cell']];
protected function createGroupBadge(): Link
{
$url = Url::fromPath('icingadb/hosts');
$urlFilter = Filter::all(Filter::equal('hostgroup.name', $this->item->name));
if ($this->item->hosts_down_unhandled > 0) {
$urlFilter->add(Filter::equal('host.state.soft_state', 1))
->add(Filter::equal('host.state.is_handled', 'n'))
->add(Filter::equal('host.state.is_reachable', 'y'));
return new Link(
new StateBadge($this->item->hosts_down_unhandled, 'down'),
$url->setFilter($urlFilter),
[
'title' => sprintf(
$this->translatePlural(
'List %d host that is currently in DOWN state in host group "%s"',
'List %d hosts which are currently in DOWN state in host group "%s"',
$this->item->hosts_down_unhandled
),
$this->item->hosts_down_unhandled,
$this->item->display_name
)
]
);
} elseif ($this->item->hosts_down_handled > 0) {
$urlFilter->add(Filter::equal('host.state.soft_state', 1))
->add(Filter::any(
Filter::equal('host.state.is_handled', 'y'),
Filter::equal('host.state.is_reachable', 'n')
));
return new Link(
new StateBadge($this->item->hosts_down_handled, 'down', true),
$url->setFilter($urlFilter),
[
'title' => sprintf(
$this->translatePlural(
'List %d host that is currently in DOWN (Acknowledged) state in host group "%s"',
'List %d hosts which are currently in DOWN (Acknowledged) state in host group "%s"',
$this->item->hosts_down_handled
),
$this->item->hosts_down_handled,
$this->item->display_name
)
]
);
} elseif ($this->item->hosts_pending > 0) {
$urlFilter->add(Filter::equal('host.state.soft_state', 99));
return new Link(
new StateBadge($this->item->hosts_pending, 'pending'),
$url->setFilter($urlFilter),
[
'title' => sprintf(
$this->translatePlural(
'List %d host that is currently in PENDING state in host group "%s"',
'List %d hosts which are currently in PENDING state in host group "%s"',
$this->item->hosts_pending
),
$this->item->hosts_pending,
$this->item->display_name
)
]
);
} elseif ($this->item->hosts_up > 0) {
$urlFilter->add(Filter::equal('host.state.soft_state', 0));
return new Link(
new StateBadge($this->item->hosts_up, 'up'),
$url->setFilter($urlFilter),
[
'title' => sprintf(
$this->translatePlural(
'List %d host that is currently in UP state in host group "%s"',
'List %d hosts which are currently in UP state in host group "%s"',
$this->item->hosts_up
),
$this->item->hosts_up,
$this->item->display_name
)
]
);
}
return new Link(
new StateBadge(0, 'none'),
$url,
[
'title' => sprintf(
$this->translate('There are no hosts in host group "%s"'),
$this->item->display_name
)
]
);
}
}
|