mirror of https://github.com/Icinga/icinga2.git
Improve event payload
Adds host/service_id Acknowledgement events. AcknowledgementSet events also send the comment_id. fixes #29
This commit is contained in:
parent
e889de966e
commit
47905a25e8
|
@ -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
|
||||||
|
@ -280,7 +282,7 @@ void RedisWriter::HandleEvent(const Dictionary::Ptr& event)
|
||||||
|
|
||||||
long maxEvents = MAX_EVENTS_DEFAULT;
|
long maxEvents = MAX_EVENTS_DEFAULT;
|
||||||
if (maxExists->integer) {
|
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);
|
VERIFY(redisReply->type == REDIS_REPLY_STRING);
|
||||||
|
|
||||||
Log(LogInformation, "RedisWriter")
|
Log(LogInformation, "RedisWriter")
|
||||||
|
@ -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")
|
||||||
|
|
Loading…
Reference in New Issue