summaryrefslogtreecommitdiffstats
path: root/library/Graphite/Web/Widget/IcingadbGraphs.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:21:16 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:21:16 +0000
commit2e582fe0b8b6a8e67982ddb84935db1bd3b401fe (patch)
treedd511b321f308264952cffb005a4288ea4e478e6 /library/Graphite/Web/Widget/IcingadbGraphs.php
parentInitial commit. (diff)
downloadicingaweb2-module-graphite-2e582fe0b8b6a8e67982ddb84935db1bd3b401fe.tar.xz
icingaweb2-module-graphite-2e582fe0b8b6a8e67982ddb84935db1bd3b401fe.zip
Adding upstream version 1.2.2.upstream/1.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Graphite/Web/Widget/IcingadbGraphs.php')
-rw-r--r--library/Graphite/Web/Widget/IcingadbGraphs.php106
1 files changed, 106 insertions, 0 deletions
diff --git a/library/Graphite/Web/Widget/IcingadbGraphs.php b/library/Graphite/Web/Widget/IcingadbGraphs.php
new file mode 100644
index 0000000..e038e92
--- /dev/null
+++ b/library/Graphite/Web/Widget/IcingadbGraphs.php
@@ -0,0 +1,106 @@
+<?php
+
+/* Icinga Graphite Web | (c) 2022 Icinga GmbH | GPLv2 */
+
+namespace Icinga\Module\Graphite\Web\Widget;
+
+use Icinga\Data\Filter\Filter;
+use Icinga\Module\Graphite\Web\Widget\Graphs\Icingadb\IcingadbHost;
+use Icinga\Module\Graphite\Web\Widget\Graphs\Icingadb\IcingadbService;
+use Icinga\Module\Icingadb\Common\Links;
+use Icinga\Module\Icingadb\Widget\EmptyState;
+use Icinga\Module\Icingadb\Model\Host;
+use ipl\Html\BaseHtmlElement;
+use ipl\Html\Html;
+use ipl\Html\HtmlDocument;
+use ipl\Html\HtmlString;
+use ipl\Orm\ResultSet;
+use ipl\Stdlib\BaseFilter;
+use ipl\Web\Filter\QueryString;
+use ipl\Web\Widget\Link;
+
+/**
+* Class for creating graphs of icingadb objects
+*/
+class IcingadbGraphs extends BaseHtmlElement
+{
+ use BaseFilter;
+
+ protected $defaultAttributes = ['class' => 'grid'];
+
+ /** @var Iterable */
+ protected $objects;
+
+ protected $tag = 'div';
+
+ /**
+ * Create a new Graph item
+ *
+ * @param ResultSet $objects
+ */
+ public function __construct(ResultSet $objects)
+ {
+ $this->objects = $objects;
+ }
+
+ protected function assemble()
+ {
+ if (! $this->objects->hasResult()) {
+ $this->add(new EmptyState(t('No items found.')));
+ }
+
+ foreach ($this->objects as $object) {
+ $this->add($this->createGridItem($object));
+ }
+
+ $document = new HtmlDocument();
+ $document->addHtml(Html::tag('div', ['class' => 'graphite-graph-color-registry']), $this);
+ $this->prependWrapper($document);
+ }
+
+ protected function createGridItem($object)
+ {
+ if ($object instanceof Host) {
+ $graph = new IcingadbHost($object);
+ $hostObj = $object;
+ } else {
+ $graph = new IcingadbService($object);
+ $hostObj = $object->host;
+ }
+
+ $hostUrl = Links::host($hostObj);
+
+ if ($this->hasBaseFilter()) {
+ $hostUrl->addFilter(Filter::fromQueryString(QueryString::render($this->getBaseFilter())));
+ }
+
+ $hostLink = new Link(
+ $graph->createHostTitle(),
+ $hostUrl,
+ ['data-base-target' => '_next']
+ );
+
+ $serviceLink = null;
+ if ($graph->getObjectType() === 'service') {
+ $serviceUrl = Links::service($object, $hostObj);
+
+ if ($this->hasBaseFilter()) {
+ $serviceUrl->addFilter(Filter::fromQueryString(QueryString::render($this->getBaseFilter())));
+ }
+
+ $serviceLink = new Link(
+ $graph->createServiceTitle(),
+ $serviceUrl,
+ ['data-base-target' => '_next']
+ );
+ }
+
+ $gridItem = Html::tag('div', ['class' => 'grid-item']);
+ $header = Html::tag('h2');
+
+ $header->add([$hostLink, $serviceLink]);
+ $gridItem->add($header);
+
+ return $gridItem->add(HtmlString::create($graph->setPreloadDummy()->handleRequest()));
+ }
+}