icingadb-web/library/Icingadb/Widget/ServiceSummaryDonut.php

82 lines
3.1 KiB
PHP
Raw Permalink Normal View History

2020-03-04 04:35:48 -05:00
<?php
2020-03-13 03:38:01 -04:00
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
2020-03-04 04:35:48 -05:00
namespace Icinga\Module\Icingadb\Widget;
use Icinga\Chart\Donut;
use Icinga\Module\Icingadb\Common\Links;
use Icinga\Module\Icingadb\Model\ServicestateSummary;
use ipl\Html\Attributes;
2020-03-04 04:35:48 -05:00
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;
2021-08-20 11:13:22 -04:00
use ipl\Web\Common\Card;
2020-03-04 04:35:48 -05:00
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)
{
$labelBigUrlFilter = Filter::all(
Filter::equal('service.state.soft_state', 2),
Filter::equal('service.state.is_handled', 'n')
);
if ($this->hasBaseFilter()) {
$labelBigUrlFilter->add($this->getBaseFilter());
}
2020-03-04 04:35:48 -05:00
$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'])
2024-01-23 03:36:05 -05:00
->setLabelBig((string) $this->summary->services_critical_unhandled)
->setLabelBigUrl(Links::services()->setFilter($labelBigUrlFilter)->addParams([
2020-03-04 04:35:48 -05:00
'sort' => 'service.state.last_state_change'
]))
->setLabelBigEyeCatching($this->summary->services_critical_unhandled > 0)
->setLabelSmall(t('Critical'));
2020-03-04 04:35:48 -05:00
$body->addHtml(
new HtmlElement('div', Attributes::create(['class' => 'donut']), new HtmlString($donut->render()))
);
2020-03-04 04:35:48 -05:00
}
protected function assembleFooter(BaseHtmlElement $footer)
{
$footer->addHtml((new ServiceStateBadges($this->summary))->setBaseFilter($this->getBaseFilter()));
2020-03-04 04:35:48 -05:00
}
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
))
);
2020-03-04 04:35:48 -05:00
}
}