Improve event payload

Adds host/service_id Acknowledgement events. AcknowledgementSet events also send the comment_id.

fixes #29
This commit is contained in:
Jean Flach 2018-10-30 16:00:41 +01:00 committed by Michael Friedrich
parent e889de966e
commit 47905a25e8
1 changed files with 31 additions and 2 deletions

View File

@ -22,10 +22,12 @@
#include "redis/redisconnection.hpp" #include "redis/redisconnection.hpp"
#include "remote/eventqueue.hpp" #include "remote/eventqueue.hpp"
#include "base/json.hpp" #include "base/json.hpp"
#include "rediswriter.hpp" #include "icinga/checkable.hpp"
#include "icinga/host.hpp"
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
using namespace icinga; using namespace icinga;
//TODO Make configurable and figure out a sane default //TODO Make configurable and figure out a sane default
@ -304,6 +306,33 @@ void RedisWriter::SendEvent(const Dictionary::Ptr& event)
if (!m_Rcon->IsConnected()) if (!m_Rcon->IsConnected())
return; return;
String type = event->Get("type");
if (type.Contains("Acknowledgement")) {
Checkable::Ptr checkable;
if (event->Contains("service")) {
checkable = Service::GetByNamePair(event->Get("host"), event->Get("service"));
event->Set("service_id", GetObjectIdentifier(checkable));
} else {
checkable = Host::GetByName(event->Get("host"));
event->Set("host_id", GetObjectIdentifier(checkable));
}
if (type == "AcknowledgementSet") {
Timestamp entry = 0;
Comment::Ptr AckComment;
for (const Comment::Ptr& c : checkable->GetComments()) {
if (c->GetEntryType() == CommentAcknowledgement) {
if (c->GetEntryTime() > entry) {
entry = c->GetEntryTime();
AckComment = c;
}
}
}
event->Set("comment_id", GetObjectIdentifier(AckComment));
}
}
String body = JsonEncode(event); String body = JsonEncode(event);
// Log(LogInformation, "RedisWriter") // Log(LogInformation, "RedisWriter")