From b18bc644404e02b57635bfcc8258e85abb141146 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:44:46 +0200 Subject: Adding upstream version 1.1.1. Signed-off-by: Daniel Baumann --- library/Icingadb/Widget/HostSummaryDonut.php | 78 ++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 library/Icingadb/Widget/HostSummaryDonut.php (limited to 'library/Icingadb/Widget/HostSummaryDonut.php') diff --git a/library/Icingadb/Widget/HostSummaryDonut.php b/library/Icingadb/Widget/HostSummaryDonut.php new file mode 100644 index 0000000..db5fef8 --- /dev/null +++ b/library/Icingadb/Widget/HostSummaryDonut.php @@ -0,0 +1,78 @@ + '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($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 + )) + ); + } +} -- cgit v1.2.3