summaryrefslogtreecommitdiffstats
path: root/library/Icingadb/Widget/ServiceSummaryDonut.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:36:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:36:40 +0000
commita0901c4b7f2db488cb4fb3be2dd921a0308f4659 (patch)
treefafb393cf330a60df129ff10d0059eb7b14052a7 /library/Icingadb/Widget/ServiceSummaryDonut.php
parentInitial commit. (diff)
downloadicingadb-web-a0901c4b7f2db488cb4fb3be2dd921a0308f4659.tar.xz
icingadb-web-a0901c4b7f2db488cb4fb3be2dd921a0308f4659.zip
Adding upstream version 1.0.2.upstream/1.0.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Icingadb/Widget/ServiceSummaryDonut.php')
-rw-r--r--library/Icingadb/Widget/ServiceSummaryDonut.php78
1 files changed, 78 insertions, 0 deletions
diff --git a/library/Icingadb/Widget/ServiceSummaryDonut.php b/library/Icingadb/Widget/ServiceSummaryDonut.php
new file mode 100644
index 0000000..8141f86
--- /dev/null
+++ b/library/Icingadb/Widget/ServiceSummaryDonut.php
@@ -0,0 +1,78 @@
+<?php
+
+/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
+
+namespace Icinga\Module\Icingadb\Widget;
+
+use Icinga\Chart\Donut;
+use Icinga\Data\Filter\Filter;
+use Icinga\Module\Icingadb\Common\BaseFilter;
+use Icinga\Module\Icingadb\Common\Links;
+use Icinga\Module\Icingadb\Model\ServicestateSummary;
+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\Web\Common\Card;
+use ipl\Web\Filter\QueryString;
+
+class ServiceSummaryDonut extends Card
+{
+ use BaseFilter;
+
+ protected $defaultAttributes = ['class' => 'donut-container', 'data-base-target' => '_next'];
+
+ /** @var ServicestateSummary */
+ protected $summary;
+
+ public function __construct(ServicestateSummary $summary)
+ {
+ $this->summary = $summary;
+ }
+
+ protected function assembleBody(BaseHtmlElement $body)
+ {
+ $donut = (new Donut())
+ ->addSlice($this->summary->services_ok, ['class' => 'slice-state-ok'])
+ ->addSlice($this->summary->services_warning_handled, ['class' => 'slice-state-warning-handled'])
+ ->addSlice($this->summary->services_warning_unhandled, ['class' => 'slice-state-warning'])
+ ->addSlice($this->summary->services_critical_handled, ['class' => 'slice-state-critical-handled'])
+ ->addSlice($this->summary->services_critical_unhandled, ['class' => 'slice-state-critical'])
+ ->addSlice($this->summary->services_unknown_handled, ['class' => 'slice-state-unknown-handled'])
+ ->addSlice($this->summary->services_unknown_unhandled, ['class' => 'slice-state-unknown'])
+ ->addSlice($this->summary->services_pending, ['class' => 'slice-state-pending'])
+ ->setLabelBig($this->summary->services_critical_unhandled)
+ ->setLabelBigUrl(Links::services()->addFilter(
+ Filter::fromQueryString(QueryString::render($this->getBaseFilter()))
+ )->addParams([
+ 'service.state.soft_state' => 2,
+ 'service.state.is_handled' => 'n',
+ 'sort' => 'service.state.last_state_change'
+ ]))
+ ->setLabelBigEyeCatching($this->summary->services_critical_unhandled > 0)
+ ->setLabelSmall(t('Critical'));
+
+ $body->addHtml(
+ new HtmlElement('div', Attributes::create(['class' => 'donut']), new HtmlString($donut->render()))
+ );
+ }
+
+ protected function assembleFooter(BaseHtmlElement $footer)
+ {
+ $footer->addHtml((new ServiceStateBadges($this->summary))->setBaseFilter($this->getBaseFilter()));
+ }
+
+ protected function assembleHeader(BaseHtmlElement $header)
+ {
+ $header->addHtml(
+ new HtmlElement('h2', null, Text::create(t('Services'))),
+ new HtmlElement('span', Attributes::create(['class' => 'meta']), TemplateString::create(
+ t('{{#total}}Total{{/total}} %d'),
+ ['total' => new HtmlElement('span')],
+ (int) $this->summary->services_total
+ ))
+ );
+ }
+}