Make sure timestamps are formatted as integers in macro strings

refs #11483
This commit is contained in:
Gunnar Beutner 2016-06-21 11:29:12 +02:00
parent b5a38f6707
commit e3f1c1ec6f
15 changed files with 41 additions and 34 deletions

View File

@ -24,7 +24,7 @@ namespace icinga
vararg_constructor class DateTime vararg_constructor class DateTime
{ {
[state, no_storage] double value { [state, no_storage] Timestamp value {
get; get;
}; };
}; };

View File

@ -28,6 +28,8 @@
namespace icinga namespace icinga
{ {
typedef double Timestamp;
/** /**
* The type of a Value. * The type of a Value.
* *

View File

@ -98,7 +98,7 @@ abstract class Checkable : CustomVarObject
[config] String icon_image; [config] String icon_image;
[config] String icon_image_alt; [config] String icon_image_alt;
[state] double next_check; [state] Timestamp next_check;
[state] int check_attempt { [state] int check_attempt {
default {{{ return 1; }}} default {{{ return 1; }}}
}; };
@ -121,27 +121,27 @@ abstract class Checkable : CustomVarObject
default {{{ return true; }}} default {{{ return true; }}}
}; };
[state] CheckResult::Ptr last_check_result; [state] CheckResult::Ptr last_check_result;
[state] double last_state_change { [state] Timestamp last_state_change {
default {{{ return Application::GetStartTime(); }}} default {{{ return Application::GetStartTime(); }}}
}; };
[state] double last_hard_state_change { [state] Timestamp last_hard_state_change {
default {{{ return Application::GetStartTime(); }}} default {{{ return Application::GetStartTime(); }}}
}; };
[state] double last_state_unreachable; [state] Timestamp last_state_unreachable;
[state] bool last_in_downtime; [state] bool last_in_downtime;
[state] bool force_next_check; [state] bool force_next_check;
[state] int acknowledgement (AcknowledgementRaw) { [state] int acknowledgement (AcknowledgementRaw) {
default {{{ return AcknowledgementNone; }}} default {{{ return AcknowledgementNone; }}}
}; };
[state] double acknowledgement_expiry; [state] Timestamp acknowledgement_expiry;
[state] bool force_next_notification; [state] bool force_next_notification;
[state] int flapping_positive; [state] int flapping_positive;
[state] int flapping_negative; [state] int flapping_negative;
[state] double flapping_last_change; [state] Timestamp flapping_last_change;
[no_storage, protected] bool flapping { [no_storage, protected] bool flapping {
get {{{ return false; }}} get {{{ return false; }}}
}; };
[no_storage] double last_check { [no_storage] Timestamp last_check {
get; get;
}; };

View File

@ -61,10 +61,10 @@ enum StateType
class CheckResult class CheckResult
{ {
[state] double schedule_start; [state] Timestamp schedule_start;
[state] double schedule_end; [state] Timestamp schedule_end;
[state] double execution_start; [state] Timestamp execution_start;
[state] double execution_end; [state] Timestamp execution_end;
[state] Value command; [state] Value command;
[state] int exit_status; [state] int exit_status;

View File

@ -79,7 +79,7 @@ class Comment : ConfigObject < CommentNameComposer
}}} }}}
}; };
[config] double entry_time { [config] Timestamp entry_time {
default {{{ return Utility::GetTime(); }}} default {{{ return Utility::GetTime(); }}}
}; };
[config, enum] CommentType entry_type { [config, enum] CommentType entry_type {
@ -87,7 +87,7 @@ class Comment : ConfigObject < CommentNameComposer
}; };
[config, required] String author; [config, required] String author;
[config, required] String text; [config, required] String text;
[config] double expire_time; [config] Timestamp expire_time;
[state] int legacy_id; [state] int legacy_id;
}; };

View File

@ -66,16 +66,16 @@ class Downtime : ConfigObject < DowntimeNameComposer
}}} }}}
}; };
[config] double entry_time { [config] Timestamp entry_time {
default {{{ return Utility::GetTime(); }}} default {{{ return Utility::GetTime(); }}}
}; };
[config, required] String author; [config, required] String author;
[config, required] String comment; [config, required] String comment;
[config] double start_time; [config] Timestamp start_time;
[config] double end_time; [config] Timestamp end_time;
[state] double trigger_time; [state] Timestamp trigger_time;
[config] bool fixed; [config] bool fixed;
[config] double duration; [config] Timestamp duration;
[config] name(Downtime) triggered_by; [config] name(Downtime) triggered_by;
[config] String scheduled_by; [config] String scheduled_by;
[state] Array::Ptr triggers { [state] Array::Ptr triggers {

View File

@ -252,7 +252,7 @@ bool Host::ResolveMacro(const String& macro, const CheckResult::Ptr&, Value *res
*result = StateTypeToString(GetLastStateType()); *result = StateTypeToString(GetLastStateType());
return true; return true;
} else if (macro == "last_state_change") { } else if (macro == "last_state_change") {
*result = GetLastStateChange(); *result = static_cast<long>(GetLastStateChange());
return true; return true;
} else if (macro == "downtime_depth") { } else if (macro == "downtime_depth") {
*result = GetDowntimeDepth(); *result = GetDowntimeDepth();

View File

@ -52,8 +52,8 @@ class Host : Checkable
[enum, no_storage] HostState last_hard_state { [enum, no_storage] HostState last_hard_state {
get; get;
}; };
[state] double last_state_up; [state] Timestamp last_state_up;
[state] double last_state_down; [state] Timestamp last_state_down;
}; };
} }

View File

@ -159,6 +159,11 @@ bool MacroProcessor::ResolveMacro(const String& macro, const ResolverList& resol
} }
ref = object->GetField(field); ref = object->GetField(field);
Field fieldInfo = type->GetFieldInfo(field);
if (strcmp(fieldInfo.TypeName, "Timestamp") == 0)
ref = static_cast<long>(ref);
} }
} }

View File

@ -90,10 +90,10 @@ class Notification : CustomVarObject < NotificationNameComposer
default {{{ return new Array(); }}} default {{{ return new Array(); }}}
}; };
[state] double last_notification; [state] Timestamp last_notification;
[state] double next_notification; [state] Timestamp next_notification;
[state] int notification_number; [state] int notification_number;
[state] double last_problem_notification; [state] Timestamp last_problem_notification;
[config, navigation] name(Endpoint) command_endpoint (CommandEndpointRaw) { [config, navigation] name(Endpoint) command_endpoint (CommandEndpointRaw) {
navigate {{{ navigate {{{

View File

@ -207,7 +207,7 @@ bool Service::ResolveMacro(const String& macro, const CheckResult::Ptr& cr, Valu
*result = StateTypeToString(GetLastStateType()); *result = StateTypeToString(GetLastStateType());
return true; return true;
} else if (macro == "last_state_change") { } else if (macro == "last_state_change") {
*result = GetLastStateChange(); *result = static_cast<long>(GetLastStateChange());
return true; return true;
} else if (macro == "downtime_depth") { } else if (macro == "downtime_depth") {
*result = GetDowntimeDepth(); *result = GetDowntimeDepth();

View File

@ -74,10 +74,10 @@ class Service : Checkable < ServiceNameComposer
return GetLastHardStateRaw(); return GetLastHardStateRaw();
}}} }}}
}; };
[state] double last_state_ok (LastStateOK); [state] Timestamp last_state_ok (LastStateOK);
[state] double last_state_warning; [state] Timestamp last_state_warning;
[state] double last_state_critical; [state] Timestamp last_state_critical;
[state] double last_state_unknown; [state] Timestamp last_state_unknown;
}; };
} }

View File

@ -56,7 +56,7 @@ class User : CustomVarObject
default {{{ return true; }}} default {{{ return true; }}}
}; };
[state] double last_notification; [state] Timestamp last_notification;
}; };
} }

View File

@ -43,7 +43,7 @@ class ApiListener : ConfigObject
[config] String ticket_salt; [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; [no_user_modify] String identity;
}; };

View File

@ -34,8 +34,8 @@ class Endpoint : ConfigObject
default {{{ return 86400; }}} default {{{ return 86400; }}}
}; };
[state] double local_log_position; [state] Timestamp local_log_position;
[state] double remote_log_position; [state] Timestamp remote_log_position;
[no_user_modify] bool connecting; [no_user_modify] bool connecting;
[no_user_modify] bool syncing; [no_user_modify] bool syncing;