[icinga-checkins] icinga.org: icingaweb2-module-director/feature-ddo-playground: StateObject : handle missing properties

git at icinga.org git at icinga.org
Tue Jun 21 15:07:36 CEST 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Tue Jun 21 15:07:22 2016 +0200

StateObject: handle missing properties

---

 library/Director/Ddo/StateObject.php |   20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/library/Director/Ddo/StateObject.php b/library/Director/Ddo/StateObject.php
index 7a19ff2..4017a90 100644
--- a/library/Director/Ddo/StateObject.php
+++ b/library/Director/Ddo/StateObject.php
@@ -44,11 +44,27 @@ abstract class StateObject extends DdoObject
         $checkResult = $result->check_result;
         $vars = $checkResult->vars_after;
 
-        $this->state      = $checkResult->state;
+        $currentState = (int) $checkResult->state;
+
+        if ($this->state === null || $currentState !== (int) $this->state) {
+            $this->last_state_change = $result->timestamp;
+        }
+
+        $this->state      = $currentState;
         $this->state_type = $vars->state_type;
+        $this->problem    = $currentState > 0;
         $this->reachable  = $vars->reachable;
         $this->attempt    = $vars->attempt;
+
+        // TODO: Handle those
+        $this->acknowledged = false;
+        $this->in_downtime  = false;
+
         $this->severity   = $this->calculateSeverity();
+
+        if ($this->hasBeenModified()) {
+            $this->last_update = time();
+        }
     }
 
     public function setState_type($type)
@@ -58,7 +74,7 @@ abstract class StateObject extends DdoObject
         }
 
         return $this->reallySet('state_type', $type);
-     }
+    }
 
     /*
     // Draft for history updates



More information about the icinga-checkins mailing list