mirror of https://github.com/Icinga/icinga2.git
RedisWriter: Add downtime schedule history event
This commit is contained in:
parent
6f0822cbe8
commit
042ed8b9e9
|
@ -87,11 +87,13 @@ void RedisWriter::ConfigStaticInitialize()
|
|||
RedisWriter::VersionChangedHandler(object);
|
||||
});
|
||||
|
||||
/* fixed/flexible downtime add */
|
||||
Downtime::OnDowntimeAdded.connect(&RedisWriter::DowntimeAddedHandler);
|
||||
/* fixed downtime start */
|
||||
Downtime::OnDowntimeStarted.connect(&RedisWriter::DowntimeStartedHandler);
|
||||
/* flexible downtime start */
|
||||
Downtime::OnDowntimeTriggered.connect(&RedisWriter::DowntimeStartedHandler);
|
||||
/* fixed/flexible downtime end */
|
||||
/* fixed/flexible downtime end or remove */
|
||||
Downtime::OnDowntimeRemoved.connect(&RedisWriter::DowntimeRemovedHandler);
|
||||
|
||||
Checkable::OnNotificationSentToAllUsers.connect([](
|
||||
|
@ -1219,6 +1221,51 @@ void RedisWriter::SendSentNotification(
|
|||
});
|
||||
}
|
||||
|
||||
void RedisWriter::SendAddedDowntime(const Downtime::Ptr& downtime)
|
||||
{
|
||||
auto service (dynamic_pointer_cast<Service>(downtime->GetCheckable()));
|
||||
auto triggeredBy (Downtime::GetByName(downtime->GetTriggeredBy()));
|
||||
|
||||
std::vector<String> xAdd ({
|
||||
"XADD", service ? "icinga:history:stream:service:downtime" : "icinga:history:stream:host:downtime", "*",
|
||||
"downtime_id", GetObjectIdentifier(downtime),
|
||||
"environment_id", SHA1(GetEnvironment()),
|
||||
service ? "service_id" : "host_id", GetObjectIdentifier(downtime->GetCheckable()),
|
||||
"entry_time", Convert::ToString(TimestampToMilliseconds(downtime->GetEntryTime())),
|
||||
"author", Utility::ValidateUTF8(downtime->GetAuthor()),
|
||||
"comment", Utility::ValidateUTF8(downtime->GetComment()),
|
||||
"is_fixed", Convert::ToString((unsigned short)downtime->GetFixed()),
|
||||
"duration", Convert::ToString(downtime->GetDuration()),
|
||||
"scheduled_start_time", Convert::ToString(TimestampToMilliseconds(downtime->GetStartTime())),
|
||||
"scheduled_end_time", Convert::ToString(TimestampToMilliseconds(downtime->GetEndTime())),
|
||||
"was_started", "0",
|
||||
"was_cancelled", Convert::ToString((unsigned short)downtime->GetWasCancelled()),
|
||||
"is_in_effect", Convert::ToString((unsigned short)downtime->IsInEffect()),
|
||||
"trigger_time", Convert::ToString(TimestampToMilliseconds(downtime->GetTriggerTime())),
|
||||
"event_id", Utility::NewUniqueID(),
|
||||
"event_type", "downtime_schedule"
|
||||
});
|
||||
|
||||
if (triggeredBy) {
|
||||
xAdd.emplace_back("triggered_by_id");
|
||||
xAdd.emplace_back(GetObjectIdentifier(triggeredBy));
|
||||
}
|
||||
|
||||
if (downtime->GetFixed()) {
|
||||
xAdd.emplace_back("actual_start_time");
|
||||
xAdd.emplace_back(Convert::ToString(TimestampToMilliseconds(downtime->GetStartTime())));
|
||||
xAdd.emplace_back("actual_end_time");
|
||||
xAdd.emplace_back(Convert::ToString(TimestampToMilliseconds(downtime->GetEndTime())));
|
||||
} else {
|
||||
xAdd.emplace_back("actual_start_time");
|
||||
xAdd.emplace_back(Convert::ToString(TimestampToMilliseconds(downtime->GetTriggerTime())));
|
||||
xAdd.emplace_back("actual_end_time");
|
||||
xAdd.emplace_back(Convert::ToString(TimestampToMilliseconds(downtime->GetTriggerTime() + downtime->GetDuration())));
|
||||
}
|
||||
|
||||
m_Rcon->FireAndForgetQuery(std::move(xAdd));
|
||||
}
|
||||
|
||||
void RedisWriter::SendStartedDowntime(const Downtime::Ptr& downtime)
|
||||
{
|
||||
auto service (dynamic_pointer_cast<Service>(downtime->GetCheckable()));
|
||||
|
@ -1546,6 +1593,13 @@ void RedisWriter::VersionChangedHandler(const ConfigObject::Ptr& object)
|
|||
}
|
||||
}
|
||||
|
||||
void RedisWriter::DowntimeAddedHandler(const Downtime::Ptr& downtime)
|
||||
{
|
||||
for (auto& rw : ConfigType::GetObjectsByType<RedisWriter>()) {
|
||||
rw->m_WorkQueue.Enqueue([rw, downtime]() { rw->SendAddedDowntime(downtime); });
|
||||
}
|
||||
}
|
||||
|
||||
void RedisWriter::DowntimeStartedHandler(const Downtime::Ptr& downtime)
|
||||
{
|
||||
StateChangeHandler(downtime->GetCheckable());
|
||||
|
|
|
@ -87,6 +87,7 @@ private:
|
|||
NotificationType type, const CheckResult::Ptr& cr, const String& author, const String& text
|
||||
);
|
||||
|
||||
void SendAddedDowntime(const Downtime::Ptr& downtime);
|
||||
void SendStartedDowntime(const Downtime::Ptr& downtime);
|
||||
void SendRemovedDowntime(const Downtime::Ptr& downtime);
|
||||
void SendAddedComment(const Comment::Ptr& comment);
|
||||
|
@ -122,6 +123,7 @@ private:
|
|||
static void StateChangeHandler(const ConfigObject::Ptr& object);
|
||||
static void StateChangeHandler(const ConfigObject::Ptr& object, const CheckResult::Ptr& cr, StateType type);
|
||||
static void VersionChangedHandler(const ConfigObject::Ptr& object);
|
||||
static void DowntimeAddedHandler(const Downtime::Ptr& downtime);
|
||||
static void DowntimeStartedHandler(const Downtime::Ptr& downtime);
|
||||
static void DowntimeRemovedHandler(const Downtime::Ptr& downtime);
|
||||
|
||||
|
|
Loading…
Reference in New Issue