summaryrefslogtreecommitdiffstats
path: root/application/controllers/ServiceController.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:15:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:15:40 +0000
commitb7fd908d538ed19fe41f03c0a3f93351d8da64e9 (patch)
tree46e14f318948cd4f5d7e874f83e7dfcc5d42fc64 /application/controllers/ServiceController.php
parentInitial commit. (diff)
downloadicingaweb2-module-businessprocess-upstream.tar.xz
icingaweb2-module-businessprocess-upstream.zip
Adding upstream version 2.5.0.upstream/2.5.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'application/controllers/ServiceController.php')
-rw-r--r--application/controllers/ServiceController.php74
1 files changed, 74 insertions, 0 deletions
diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php
new file mode 100644
index 0000000..671d00c
--- /dev/null
+++ b/application/controllers/ServiceController.php
@@ -0,0 +1,74 @@
+<?php
+
+namespace Icinga\Module\Businessprocess\Controllers;
+
+use Icinga\Application\Modules\Module;
+use Icinga\Module\Businessprocess\IcingaDbObject;
+use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport;
+use Icinga\Module\Icingadb\Model\Service;
+use Icinga\Module\Monitoring\Controller;
+use Icinga\Module\Monitoring\DataView\DataView;
+use Icinga\Web\Url;
+use ipl\Stdlib\Filter;
+
+class ServiceController extends Controller
+{
+ /**
+ * True if business process prefers to use icingadb as backend for it's nodes
+ *
+ * @var bool
+ */
+ protected $isIcingadbPreferred;
+
+ protected function moduleInit()
+ {
+ $this->isIcingadbPreferred = Module::exists('icingadb')
+ && ! $this->params->has('backend')
+ && IcingadbSupport::useIcingaDbAsBackend();
+
+ if (! $this->isIcingadbPreferred) {
+ parent::moduleInit();
+ }
+ }
+
+ public function showAction()
+ {
+ if ($this->isIcingadbPreferred) {
+ $hostName = $this->params->shift('host');
+ $serviceName = $this->params->shift('service');
+
+ $query = Service::on(IcingaDbObject::fetchDb());
+ IcingaDbObject::applyIcingaDbRestrictions($query);
+
+ $query->filter(Filter::all(
+ Filter::equal('service.name', $serviceName),
+ Filter::equal('host.name', $hostName)
+ ));
+
+ $service = $query->first();
+
+ $this->params->add('name', $serviceName);
+ $this->params->add('host.name', $hostName);
+
+ if ($service !== null) {
+ $this->redirectNow(Url::fromPath('icingadb/service')->setParams($this->params));
+ }
+ } else {
+ $hostName = $this->params->get('host');
+ $serviceName = $this->params->get('service');
+
+ $query = $this->backend->select()
+ ->from('servicestatus', array('service_description'))
+ ->where('host_name', $hostName)
+ ->where('service_description', $serviceName);
+
+ $this->applyRestriction('monitoring/filter/objects', $query);
+ if ($query->fetchRow() !== false) {
+ $this->redirectNow(Url::fromPath('monitoring/service/show')->setParams($this->params));
+ }
+ }
+
+ $this->view->host = $hostName;
+ $this->view->service = $serviceName;
+ }
+}