RedisWriter: populate icinga:history:stream:*:flapping

This commit is contained in:
Alexander A. Klimov 2019-10-02 16:20:12 +02:00 committed by Michael Friedrich
parent 81873248e1
commit fb6d31fcde
2 changed files with 30 additions and 0 deletions

View File

@ -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<String, String> 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<Service>(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<RedisWriter>()) {
rw->m_WorkQueue.Enqueue([rw, checkable, value]() { rw->SendFlappingChanged(checkable, value); });
}
}

View File

@ -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<String> 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();