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 "remote/eventqueue.hpp"
#include "base/json.hpp"
#include "rediswriter.hpp"
#include "icinga/checkable.hpp"
#include "icinga/host.hpp"
#include <boost/algorithm/string.hpp>
using namespace icinga;
//TODO Make configurable and figure out a sane default
@ -280,7 +282,7 @@ void RedisWriter::HandleEvent(const Dictionary::Ptr& event)
long maxEvents = MAX_EVENTS_DEFAULT;
if (maxExists->integer) {
redisReply *redisReply =RedisGet({ "GET", "icinga:subscription:" + name + ":limit"});
redisReply *redisReply = RedisGet({ "GET", "icinga:subscription:" + name + ":limit"});
VERIFY(redisReply->type == REDIS_REPLY_STRING);
Log(LogInformation, "RedisWriter")
@ -304,6 +306,33 @@ void RedisWriter::SendEvent(const Dictionary::Ptr& event)
if (!m_Rcon->IsConnected())
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);
// Log(LogInformation, "RedisWriter")