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
|
<?php
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
namespace Icinga\Module\Icingadb\Widget;
use Icinga\Chart\Donut;
use Icinga\Module\Icingadb\Common\Links;
use Icinga\Module\Icingadb\Model\HoststateSummary;
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
use ipl\Html\HtmlElement;
use ipl\Html\HtmlString;
use ipl\Html\TemplateString;
use ipl\Html\Text;
use ipl\Stdlib\BaseFilter;
use ipl\Stdlib\Filter;
use ipl\Web\Common\Card;
use ipl\Web\Filter\QueryString;
class HostSummaryDonut extends Card
{
use BaseFilter;
protected $defaultAttributes = ['class' => 'donut-container', 'data-base-target' => '_next'];
/** @var HoststateSummary */
protected $summary;
public function __construct(HoststateSummary $summary)
{
$this->summary = $summary;
}
protected function assembleBody(BaseHtmlElement $body)
{
$labelBigUrlFilter = Filter::all(
Filter::equal('host.state.soft_state', 1),
Filter::equal('host.state.is_handled', 'n')
);
if ($this->hasBaseFilter()) {
$labelBigUrlFilter->add($this->getBaseFilter());
}
$donut = (new Donut())
->addSlice($this->summary->hosts_up, ['class' => 'slice-state-ok'])
->addSlice($this->summary->hosts_down_handled, ['class' => 'slice-state-critical-handled'])
->addSlice($this->summary->hosts_down_unhandled, ['class' => 'slice-state-critical'])
->addSlice($this->summary->hosts_pending, ['class' => 'slice-state-pending'])
->setLabelBig((string) $this->summary->hosts_down_unhandled)
->setLabelBigUrl(Links::hosts()->setFilter($labelBigUrlFilter)->addParams([
'sort' => 'host.state.last_state_change'
]))
->setLabelBigEyeCatching($this->summary->hosts_down_unhandled > 0)
->setLabelSmall(t('Down'));
$body->addHtml(
new HtmlElement('div', Attributes::create(['class' => 'donut']), new HtmlString($donut->render()))
);
}
protected function assembleFooter(BaseHtmlElement $footer)
{
$footer->addHtml((new HostStateBadges($this->summary))->setBaseFilter($this->getBaseFilter()));
}
protected function assembleHeader(BaseHtmlElement $header)
{
$header->addHtml(
new HtmlElement('h2', null, Text::create(t('Hosts'))),
new HtmlElement('span', Attributes::create(['class' => 'meta']), TemplateString::create(
t('{{#total}}Total{{/total}} %d'),
['total' => new HtmlElement('span')],
(int) $this->summary->hosts_total
))
);
}
}
|