GelfWriter: Add 'source' configuration attribute

refs #7619
This commit is contained in:
Michael Friedrich 2014-11-11 14:05:28 +01:00
parent f838fc4e6c
commit 5ac03849d2
3 changed files with 11 additions and 4 deletions

View File

@ -79,6 +79,9 @@ void GelfWriter::CheckResultHandler(const Checkable::Ptr& checkable, const Check
{ {
CONTEXT("GELF Processing check result for '" + checkable->GetName() + "'"); CONTEXT("GELF Processing check result for '" + checkable->GetName() + "'");
Log(LogDebug, "GelfWriter")
<< "GELF Processing check result for '" << checkable->GetName() << "'";
Dictionary::Ptr fields = new Dictionary(); Dictionary::Ptr fields = new Dictionary();
Service::Ptr service = dynamic_pointer_cast<Service>(checkable); Service::Ptr service = dynamic_pointer_cast<Service>(checkable);
Host::Ptr host; Host::Ptr host;
@ -94,7 +97,7 @@ void GelfWriter::CheckResultHandler(const Checkable::Ptr& checkable, const Check
fields->Set("short_message", cr->GetOutput()); fields->Set("short_message", cr->GetOutput());
fields->Set("_type", "CHECK RESULT"); fields->Set("_type", "CHECK RESULT");
SendLogMessage(ComposeGelfMessage(fields, "icinga")); SendLogMessage(ComposeGelfMessage(fields, GetSource()));
} }
void GelfWriter::NotificationToUserHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable, void GelfWriter::NotificationToUserHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable,
@ -134,7 +137,7 @@ void GelfWriter::NotificationToUserHandler(const Notification::Ptr& notification
fields->Set("_state", notification_type_str); fields->Set("_state", notification_type_str);
fields->Set("_comment", author_comment); fields->Set("_comment", author_comment);
SendLogMessage(ComposeGelfMessage(fields, "icinga")); SendLogMessage(ComposeGelfMessage(fields, GetSource()));
} }
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)
@ -165,7 +168,7 @@ void GelfWriter::StateChangeHandler(const Checkable::Ptr& checkable, const Check
fields->Set("_check_source", cr->GetCheckSource()); fields->Set("_check_source", cr->GetCheckSource());
} }
SendLogMessage(ComposeGelfMessage(fields, "icinga")); SendLogMessage(ComposeGelfMessage(fields, GetSource()));
} }
String GelfWriter::ComposeGelfMessage(const Dictionary::Ptr& fields, const String& source) String GelfWriter::ComposeGelfMessage(const Dictionary::Ptr& fields, const String& source)

View File

@ -30,6 +30,9 @@ class GelfWriter : DynamicObject
[config] String port { [config] String port {
default {{{ return "12201"; }}} default {{{ return "12201"; }}}
}; };
[config] String source {
default {{{ return "icinga2"; }}}
};
}; };
} }

View File

@ -36,6 +36,7 @@
%type GelfWriter { %type GelfWriter {
%attribute %string "host", %attribute %string "host",
%attribute %string "port" %attribute %string "port",
%attribute %string "source"
} }