[icinga-checkins] icinga.org: icingaweb2/feature/livestatus-playground-4787: Livestatus\StatusQuery: a couple of munge methods

git at icinga.org git at icinga.org
Sun Nov 16 17:17:21 CET 2014


Module: icingaweb2
Branch: feature/livestatus-playground-4787
Commit: 7eb960ea0b38f7dbab35c2e874b04deeb9eb6d79
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=7eb960ea0b38f7dbab35c2e874b04deeb9eb6d79

Author: Thomas Gelf <thomas at gelf.net>
Date:   Sun Nov 16 16:40:15 2014 +0100

Livestatus\StatusQuery: a couple of munge methods

---

 .../Backend/Livestatus/Query/StatusQuery.php       |   56 ++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/modules/monitoring/library/Monitoring/Backend/Livestatus/Query/StatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Livestatus/Query/StatusQuery.php
index 1fd02f6..5a638c9 100644
--- a/modules/monitoring/library/Monitoring/Backend/Livestatus/Query/StatusQuery.php
+++ b/modules/monitoring/library/Monitoring/Backend/Livestatus/Query/StatusQuery.php
@@ -201,4 +201,60 @@ class StatusQuery extends Query
 'service_flap_detection_enabled' => 'flap_detection_enabled',
 'service_process_performance_data' => 'process_performance_data',
     );
+
+    public function mungeResult_custom_variables($val, & $row)
+    {
+        $notseen = $this->customvars;
+        foreach ($val as $cv) {
+            $name = '_service_' . $cv[0];
+            $row->$name = $cv[1];
+            unset($notseen[$name]);
+        }
+        foreach ($notseen as $k => $v) {
+            $row->$k = $v;
+        }
+    }
+
+    public function mungeResult_service_last_comment($val, & $row)
+    {
+        $this->mungeResult_comments_with_info($val, $row);
+    }
+
+    public function mungeResult_service_last_ack($val, & $row)
+    {
+        $this->mungeResult_comments_with_info($val, $row);
+    }
+
+    public function mungeResult_service_last_downtime($val, & $row)
+    {
+        $this->mungeResult_comments_with_info($val, $row);
+    }
+
+    public function mungeResult_comments_with_info($val, & $row)
+    {
+        if (empty($val)) {
+            $row->service_last_comment = $row->service_last_ack
+                = $row->service_last_downtime = null;
+        } else {
+            $row->service_last_comment = $row->service_last_ack
+                = $row->service_last_downtime = preg_replace('/\n/', ' ', print_r($val, 1));
+        }
+    }
+
+    public function mungeResult_host_unhandled_services($val, & $row)
+    {
+        $cnt = 0;
+        foreach ($this->parseArray($val) as $service) {
+            if (! isset($service[1])) {
+                continue;
+                // TODO: More research is required here, on Icinga2 I got
+                //       array(1) { [0]=> array(1) { [0]=> string(1) "2" } }
+                var_dump($this->parseArray($val));
+            }
+            if ($service[1] > 0) {
+                $cnt++;
+            }
+        }
+        $row->host_unhandled_services = $cnt;
+    }
 }



More information about the icinga-checkins mailing list