From fb6d31fcde30530abdd7cb6563317624645f652c Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 2 Oct 2019 16:20:12 +0200 Subject: [PATCH] RedisWriter: populate icinga:history:stream:*:flapping --- lib/redis/rediswriter-objects.cpp | 28 ++++++++++++++++++++++++++++ lib/redis/rediswriter.hpp | 2 ++ 2 files changed, 30 insertions(+) diff --git a/lib/redis/rediswriter-objects.cpp b/lib/redis/rediswriter-objects.cpp index 9617c98ee..a4ab277ff 100644 --- a/lib/redis/rediswriter-objects.cpp +++ b/lib/redis/rediswriter-objects.cpp @@ -104,6 +104,8 @@ void RedisWriter::ConfigStaticInitialize() Comment::OnCommentAdded.connect(&RedisWriter::CommentAddedHandler); Comment::OnCommentRemoved.connect(&RedisWriter::CommentRemovedHandler); + + Checkable::OnFlappingChanged.connect(&RedisWriter::FlappingChangedHandler); } static std::pair SplitOutput(String output) @@ -1337,6 +1339,25 @@ void RedisWriter::SendRemovedComment(const Comment::Ptr& comment) }); } +void RedisWriter::SendFlappingChanged(const Checkable::Ptr& checkable, const Value& value) +{ + if (!m_Rcon || !m_Rcon->IsConnected()) + return; + + auto service (dynamic_pointer_cast(checkable)); + + m_Rcon->FireAndForgetQuery({ + "XADD", service ? "icinga:history:stream:service:flapping" : "icinga:history:stream:host:flapping", "*", + "id", Utility::NewUniqueID(), + "environment_id", SHA1(GetEnvironment()), + service ? "service_id" : "host_id", GetObjectIdentifier(checkable), + value.ToBool() ? "start_time" : "end_time", Convert::ToString(Utility::GetTime()), + "percent_state_change", Convert::ToString(checkable->GetFlappingCurrent()), + "flapping_threshold_low", Convert::ToString(checkable->GetFlappingThresholdLow()), + "flapping_threshold_high", Convert::ToString(checkable->GetFlappingThresholdHigh()) + }); +} + Dictionary::Ptr RedisWriter::SerializeState(const Checkable::Ptr& checkable) { Dictionary::Ptr attrs = new Dictionary(); @@ -1561,3 +1582,10 @@ void RedisWriter::CommentRemovedHandler(const Comment::Ptr& comment) rw->m_WorkQueue.Enqueue([rw, comment]() { rw->SendRemovedComment(comment); }); } } + +void RedisWriter::FlappingChangedHandler(const Checkable::Ptr& checkable, const Value& value) +{ + for (auto& rw : ConfigType::GetObjectsByType()) { + rw->m_WorkQueue.Enqueue([rw, checkable, value]() { rw->SendFlappingChanged(checkable, value); }); + } +} diff --git a/lib/redis/rediswriter.hpp b/lib/redis/rediswriter.hpp index 4300c165a..e44965b67 100644 --- a/lib/redis/rediswriter.hpp +++ b/lib/redis/rediswriter.hpp @@ -91,6 +91,7 @@ private: void SendRemovedDowntime(const Downtime::Ptr& downtime); void SendAddedComment(const Comment::Ptr& comment); void SendRemovedComment(const Comment::Ptr& comment); + void SendFlappingChanged(const Checkable::Ptr& checkable, const Value& value); std::vector UpdateObjectAttrs(const ConfigObject::Ptr& object, int fieldType, const String& typeNameOverride); Dictionary::Ptr SerializeState(const Checkable::Ptr& checkable); @@ -130,6 +131,7 @@ private: static void CommentAddedHandler(const Comment::Ptr& comment); static void CommentRemovedHandler(const Comment::Ptr& comment); + static void FlappingChangedHandler(const Checkable::Ptr& checkable, const Value& value); void AssertOnWorkQueue();