Use check_result timestamp for GELF log messages

fixes #9184

Signed-off-by: Michael Friedrich <michael.friedrich@netways.de>
This commit is contained in:
Marius Sturm 2016-04-10 22:33:31 +02:00 committed by Michael Friedrich
parent dd28dbdb57
commit 15cb9c1c1a
2 changed files with 11 additions and 8 deletions

View File

@ -89,6 +89,7 @@ void GelfWriter::CheckResultHandler(const Checkable::Ptr& checkable, const Check
Host::Ptr host; Host::Ptr host;
Service::Ptr service; Service::Ptr service;
tie(host, service) = GetHostService(checkable); tie(host, service) = GetHostService(checkable);
double ts = cr->GetExecutionEnd();
Dictionary::Ptr fields = new Dictionary(); Dictionary::Ptr fields = new Dictionary();
@ -159,7 +160,7 @@ void GelfWriter::CheckResultHandler(const Checkable::Ptr& checkable, const Check
} }
} }
SendLogMessage(ComposeGelfMessage(fields, GetSource())); SendLogMessage(ComposeGelfMessage(fields, GetSource(), ts));
} }
void GelfWriter::NotificationToUserHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable, void GelfWriter::NotificationToUserHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable,
@ -174,6 +175,7 @@ void GelfWriter::NotificationToUserHandler(const Notification::Ptr& notification
Host::Ptr host; Host::Ptr host;
Service::Ptr service; Service::Ptr service;
tie(host, service) = GetHostService(checkable); tie(host, service) = GetHostService(checkable);
double ts = cr->GetExecutionEnd();
String notification_type_str = Notification::NotificationTypeToString(notification_type); String notification_type_str = Notification::NotificationTypeToString(notification_type);
@ -206,7 +208,7 @@ void GelfWriter::NotificationToUserHandler(const Notification::Ptr& notification
fields->Set("_notification_type", notification_type_str); fields->Set("_notification_type", notification_type_str);
fields->Set("_comment", author_comment); fields->Set("_comment", author_comment);
SendLogMessage(ComposeGelfMessage(fields, GetSource())); SendLogMessage(ComposeGelfMessage(fields, GetSource(), ts));
} }
void GelfWriter::StateChangeHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type) void GelfWriter::StateChangeHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type)
@ -219,6 +221,7 @@ void GelfWriter::StateChangeHandler(const Checkable::Ptr& checkable, const Check
Host::Ptr host; Host::Ptr host;
Service::Ptr service; Service::Ptr service;
tie(host, service) = GetHostService(checkable); tie(host, service) = GetHostService(checkable);
double ts = cr->GetExecutionEnd();
Dictionary::Ptr fields = new Dictionary(); Dictionary::Ptr fields = new Dictionary();
@ -244,14 +247,14 @@ void GelfWriter::StateChangeHandler(const Checkable::Ptr& checkable, const Check
fields->Set("_check_source", cr->GetCheckSource()); fields->Set("_check_source", cr->GetCheckSource());
} }
SendLogMessage(ComposeGelfMessage(fields, GetSource())); SendLogMessage(ComposeGelfMessage(fields, GetSource(), ts));
} }
String GelfWriter::ComposeGelfMessage(const Dictionary::Ptr& fields, const String& source) String GelfWriter::ComposeGelfMessage(const Dictionary::Ptr& fields, const String& source, double ts)
{ {
fields->Set("version", "1.1"); fields->Set("version", "1.1");
fields->Set("host", source); fields->Set("host", source);
fields->Set("timestamp", Utility::GetTime()); fields->Set("timestamp", ts);
return JsonEncode(fields); return JsonEncode(fields);
} }

View File

@ -53,7 +53,7 @@ private:
void NotificationToUserHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable, void NotificationToUserHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable,
const User::Ptr& user, NotificationType notification_type, CheckResult::Ptr const& cr, const User::Ptr& user, NotificationType notification_type, CheckResult::Ptr const& cr,
const String& author, const String& comment_text, const String& command_name); const String& author, const String& comment_text, const String& command_name);
String ComposeGelfMessage(const Dictionary::Ptr& fields, const String& source); String ComposeGelfMessage(const Dictionary::Ptr& fields, const String& source, double ts);
void StateChangeHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type); void StateChangeHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type);
void SendLogMessage(const String& gelf); void SendLogMessage(const String& gelf);