[icinga-checkins] icinga.org: icinga2/master: Make sure timestamps are formatted as integers in macro strings

git at icinga.org git at icinga.org
Tue Jun 21 11:29:53 CEST 2016


Module: icinga2
Branch: master
Commit: e3f1c1ec6f6d04c32ba29b0c44afd98ca580bf71
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=e3f1c1ec6f6d04c32ba29b0c44afd98ca580bf71

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Tue Jun 21 11:29:12 2016 +0200

Make sure timestamps are formatted as integers in macro strings

refs #11483

---

 lib/base/datetime.ti          |    2 +-
 lib/base/value.hpp            |    2 ++
 lib/icinga/checkable.ti       |   14 +++++++-------
 lib/icinga/checkresult.ti     |    8 ++++----
 lib/icinga/comment.ti         |    4 ++--
 lib/icinga/downtime.ti        |   10 +++++-----
 lib/icinga/host.cpp           |    2 +-
 lib/icinga/host.ti            |    4 ++--
 lib/icinga/macroprocessor.cpp |    5 +++++
 lib/icinga/notification.ti    |    6 +++---
 lib/icinga/service.cpp        |    2 +-
 lib/icinga/service.ti         |    8 ++++----
 lib/icinga/user.ti            |    2 +-
 lib/remote/apilistener.ti     |    2 +-
 lib/remote/endpoint.ti        |    4 ++--
 15 files changed, 41 insertions(+), 34 deletions(-)

diff --git a/lib/base/datetime.ti b/lib/base/datetime.ti
index 2b6d178..af79ed5 100644
--- a/lib/base/datetime.ti
+++ b/lib/base/datetime.ti
@@ -24,7 +24,7 @@ namespace icinga
 
 vararg_constructor class DateTime
 {
-	[state, no_storage] double value {
+	[state, no_storage] Timestamp value {
 		get;
 	};
 };
diff --git a/lib/base/value.hpp b/lib/base/value.hpp
index 34fe7cb..96be16d 100644
--- a/lib/base/value.hpp
+++ b/lib/base/value.hpp
@@ -28,6 +28,8 @@
 namespace icinga
 {
 
+typedef double Timestamp;
+
 /**
  * The type of a Value.
  *
diff --git a/lib/icinga/checkable.ti b/lib/icinga/checkable.ti
index f3621e8..e909af6 100644
--- a/lib/icinga/checkable.ti
+++ b/lib/icinga/checkable.ti
@@ -98,7 +98,7 @@ abstract class Checkable : CustomVarObject
 	[config] String icon_image;
 	[config] String icon_image_alt;
 
-	[state] double next_check;
+	[state] Timestamp next_check;
 	[state] int check_attempt {
 		default {{{ return 1; }}}
 	};
@@ -121,27 +121,27 @@ abstract class Checkable : CustomVarObject
 		default {{{ return true; }}}
 	};
 	[state] CheckResult::Ptr last_check_result;
-	[state] double last_state_change {
+	[state] Timestamp last_state_change {
 		default {{{ return Application::GetStartTime(); }}}
 	};
-	[state] double last_hard_state_change {
+	[state] Timestamp last_hard_state_change {
 		default {{{ return Application::GetStartTime(); }}}
 	};
-	[state] double last_state_unreachable;
+	[state] Timestamp last_state_unreachable;
 	[state] bool last_in_downtime;
 	[state] bool force_next_check;
 	[state] int acknowledgement (AcknowledgementRaw) {
 		default {{{ return AcknowledgementNone; }}}
 	};
-	[state] double acknowledgement_expiry;
+	[state] Timestamp acknowledgement_expiry;
 	[state] bool force_next_notification;
 	[state] int flapping_positive;
 	[state] int flapping_negative;
-	[state] double flapping_last_change;
+	[state] Timestamp flapping_last_change;
 	[no_storage, protected] bool flapping {
 		get {{{ return false; }}}
 	};
-	[no_storage] double last_check {
+	[no_storage] Timestamp last_check {
 		get;
 	};
 
diff --git a/lib/icinga/checkresult.ti b/lib/icinga/checkresult.ti
index 43c985a..4f67d75 100644
--- a/lib/icinga/checkresult.ti
+++ b/lib/icinga/checkresult.ti
@@ -61,10 +61,10 @@ enum StateType
 
 class CheckResult
 {
-	[state] double schedule_start;
-	[state] double schedule_end;
-	[state] double execution_start;
-	[state] double execution_end;
+	[state] Timestamp schedule_start;
+	[state] Timestamp schedule_end;
+	[state] Timestamp execution_start;
+	[state] Timestamp execution_end;
 
 	[state] Value command;
 	[state] int exit_status;
diff --git a/lib/icinga/comment.ti b/lib/icinga/comment.ti
index 94ad48e..412837f 100644
--- a/lib/icinga/comment.ti
+++ b/lib/icinga/comment.ti
@@ -79,7 +79,7 @@ class Comment : ConfigObject < CommentNameComposer
 		}}}
 	};
 
-	[config] double entry_time {
+	[config] Timestamp entry_time {
 		default {{{ return Utility::GetTime(); }}}
 	};
 	[config, enum] CommentType entry_type {
@@ -87,7 +87,7 @@ class Comment : ConfigObject < CommentNameComposer
 	};
 	[config, required] String author;
 	[config, required] String text;
-	[config] double expire_time;
+	[config] Timestamp expire_time;
 	[state] int legacy_id;
 };
 
diff --git a/lib/icinga/downtime.ti b/lib/icinga/downtime.ti
index 29248cc..bb2bd09 100644
--- a/lib/icinga/downtime.ti
+++ b/lib/icinga/downtime.ti
@@ -66,16 +66,16 @@ class Downtime : ConfigObject < DowntimeNameComposer
 		}}}
 	};
 
-	[config] double entry_time {
+	[config] Timestamp entry_time {
 		default {{{ return Utility::GetTime(); }}}
 	};
 	[config, required] String author;
 	[config, required] String comment;
-	[config] double start_time;
-	[config] double end_time;
-	[state] double trigger_time;
+	[config] Timestamp start_time;
+	[config] Timestamp end_time;
+	[state] Timestamp trigger_time;
 	[config] bool fixed;
-	[config] double duration;
+	[config] Timestamp duration;
 	[config] name(Downtime) triggered_by;
 	[config] String scheduled_by;
 	[state] Array::Ptr triggers {
diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp
index af6cab8..f3c907f 100644
--- a/lib/icinga/host.cpp
+++ b/lib/icinga/host.cpp
@@ -252,7 +252,7 @@ bool Host::ResolveMacro(const String& macro, const CheckResult::Ptr&, Value *res
 		*result = StateTypeToString(GetLastStateType());
 		return true;
 	} else if (macro == "last_state_change") {
-		*result = GetLastStateChange();
+		*result = static_cast<long>(GetLastStateChange());
 		return true;
 	} else if (macro == "downtime_depth") {
 		*result = GetDowntimeDepth();
diff --git a/lib/icinga/host.ti b/lib/icinga/host.ti
index a88b956..10a583e 100644
--- a/lib/icinga/host.ti
+++ b/lib/icinga/host.ti
@@ -52,8 +52,8 @@ class Host : Checkable
 	[enum, no_storage] HostState last_hard_state {
 		get;
 	};
-	[state] double last_state_up;
-	[state] double last_state_down;
+	[state] Timestamp last_state_up;
+	[state] Timestamp last_state_down;
 };
 
 }
diff --git a/lib/icinga/macroprocessor.cpp b/lib/icinga/macroprocessor.cpp
index 88c8220..11ab833 100644
--- a/lib/icinga/macroprocessor.cpp
+++ b/lib/icinga/macroprocessor.cpp
@@ -159,6 +159,11 @@ bool MacroProcessor::ResolveMacro(const String& macro, const ResolverList& resol
 				}
 
 				ref = object->GetField(field);
+
+				Field fieldInfo = type->GetFieldInfo(field);
+
+				if (strcmp(fieldInfo.TypeName, "Timestamp") == 0)
+					ref = static_cast<long>(ref);
 			}
 		}
 
diff --git a/lib/icinga/notification.ti b/lib/icinga/notification.ti
index 0d234c9..f7ef863 100644
--- a/lib/icinga/notification.ti
+++ b/lib/icinga/notification.ti
@@ -90,10 +90,10 @@ class Notification : CustomVarObject < NotificationNameComposer
 		default {{{ return new Array(); }}}
 	};
 
-	[state] double last_notification;
-	[state] double next_notification;
+	[state] Timestamp last_notification;
+	[state] Timestamp next_notification;
 	[state] int notification_number;
-	[state] double last_problem_notification;
+	[state] Timestamp last_problem_notification;
 
 	[config, navigation] name(Endpoint) command_endpoint (CommandEndpointRaw) {
 		navigate {{{
diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp
index 80f166f..1cb904f 100644
--- a/lib/icinga/service.cpp
+++ b/lib/icinga/service.cpp
@@ -207,7 +207,7 @@ bool Service::ResolveMacro(const String& macro, const CheckResult::Ptr& cr, Valu
 		*result = StateTypeToString(GetLastStateType());
 		return true;
 	} else if (macro == "last_state_change") {
-		*result = GetLastStateChange();
+		*result = static_cast<long>(GetLastStateChange());
 		return true;
 	} else if (macro == "downtime_depth") {
 		*result = GetDowntimeDepth();
diff --git a/lib/icinga/service.ti b/lib/icinga/service.ti
index 67f2773..16b9f1a 100644
--- a/lib/icinga/service.ti
+++ b/lib/icinga/service.ti
@@ -74,10 +74,10 @@ class Service : Checkable < ServiceNameComposer
 			return GetLastHardStateRaw();
 		}}}
 	};
-	[state] double last_state_ok (LastStateOK);
-	[state] double last_state_warning;
-	[state] double last_state_critical;
-	[state] double last_state_unknown;
+	[state] Timestamp last_state_ok (LastStateOK);
+	[state] Timestamp last_state_warning;
+	[state] Timestamp last_state_critical;
+	[state] Timestamp last_state_unknown;
 };
 
 }
diff --git a/lib/icinga/user.ti b/lib/icinga/user.ti
index 9df9611..e7028ea 100644
--- a/lib/icinga/user.ti
+++ b/lib/icinga/user.ti
@@ -56,7 +56,7 @@ class User : CustomVarObject
 		default {{{ return true; }}}
 	};
 
-	[state] double last_notification;
+	[state] Timestamp last_notification;
 };
 
 }
diff --git a/lib/remote/apilistener.ti b/lib/remote/apilistener.ti
index 82ed71c..34e235c 100644
--- a/lib/remote/apilistener.ti
+++ b/lib/remote/apilistener.ti
@@ -43,7 +43,7 @@ class ApiListener : ConfigObject
 
 	[config] String ticket_salt;
 
-	[state, no_user_modify] double log_message_timestamp;
+	[state, no_user_modify] Timestamp log_message_timestamp;
 
 	[no_user_modify] String identity;
 };
diff --git a/lib/remote/endpoint.ti b/lib/remote/endpoint.ti
index 9eaccb9..5253e13 100644
--- a/lib/remote/endpoint.ti
+++ b/lib/remote/endpoint.ti
@@ -34,8 +34,8 @@ class Endpoint : ConfigObject
 		default {{{ return 86400; }}}
 	};
 
-	[state] double local_log_position;
-	[state] double remote_log_position;
+	[state] Timestamp local_log_position;
+	[state] Timestamp remote_log_position;
 
 	[no_user_modify] bool connecting;
 	[no_user_modify] bool syncing;



More information about the icinga-checkins mailing list