[icinga-checkins] icinga.org: icingaweb2-module-director/feature-ddo-playground: Ddo\StateList: first state list prototype

git at icinga.org git at icinga.org
Tue Jul 19 10:31:51 CEST 2016


Module: icingaweb2-module-director
Branch: feature-ddo-playground
Commit: 984d14f82310a8e2cb4fa673c46c31efca42e08c
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=984d14f82310a8e2cb4fa673c46c31efca42e08c

Author: Thomas Gelf <thomas at gelf.net>
Date:   Tue Jun 21 13:00:18 2016 +0200

Ddo\StateList: first state list prototype

---

 library/Director/Ddo/StateList.php |   64 ++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/library/Director/Ddo/StateList.php b/library/Director/Ddo/StateList.php
new file mode 100644
index 0000000..7104dbc
--- /dev/null
+++ b/library/Director/Ddo/StateList.php
@@ -0,0 +1,64 @@
+<?php
+
+namespace Icinga\Module\Director\StateList;
+
+class StateList
+{
+    protected $connection;
+
+    protected $db;
+
+    protected $objects;
+
+    public function __construct(DdoDb $connection)
+    {
+        $this->connection = $connection;
+        $this->db = $connection->getDbAdapter();
+    }
+
+    public function processCheckResult($result)
+    {
+        list($host, $service) = $this->getHostServiceFromResult($result);
+
+        $key = self::createKey($host, $service);
+
+        if ($this->hasKey($key)) {
+            $object = $this->getObject($key);
+        } else {
+            $object = $this->createObject($host, $service, $key);
+        }
+
+        $object->processCheckResult($result);
+        if ($object->hasBeenModified()) {
+            $object->store();
+        }
+    }
+
+    protected function hasKey($key)
+    {
+        return array_key_exists($key, $this->objects);
+    }
+
+    protected function getHostServiceFromResult($result)
+    {
+        $list = array($result->host);
+
+        if (property_exists($result, 'service')) {
+            $list[] = $result->service;
+        } else {
+            $list[] = null;
+        }
+
+        return $list;
+    }
+
+    protected function createKey($host, $service = null)
+    {
+        $key = $host;
+        if (property_exists($result, 'service')) {
+            $key .= '!' . $result->service;
+        }
+
+        return sha1($key, true);
+    }
+}



More information about the icinga-checkins mailing list