Skip to content

Icinga DB: Add downtime.duration & service_state.host_id to Redis #9084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/icingadb/icingadb-objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,7 @@ bool IcingaDB::PrepareObject(const ConfigObject::Ptr& object, Dictionary::Ptr& a
attributes->Set("entry_time", TimestampToMilliseconds(downtime->GetEntryTime()));
attributes->Set("scheduled_start_time", TimestampToMilliseconds(downtime->GetStartTime()));
attributes->Set("scheduled_end_time", TimestampToMilliseconds(downtime->GetEndTime()));
attributes->Set("scheduled_duration", TimestampToMilliseconds(downtime->GetEndTime() - downtime->GetStartTime()));
attributes->Set("flexible_duration", TimestampToMilliseconds(downtime->GetDuration()));
attributes->Set("is_flexible", !downtime->GetFixed());
attributes->Set("is_in_effect", downtime->IsInEffect());
Expand All @@ -1338,6 +1339,12 @@ bool IcingaDB::PrepareObject(const ConfigObject::Ptr& object, Dictionary::Ptr& a
attributes->Set("end_time", TimestampToMilliseconds(downtime->GetFixed() ? downtime->GetEndTime() : (downtime->GetTriggerTime() + downtime->GetDuration())));
}

auto duration = downtime->GetDuration();
if (downtime->GetFixed()) {
duration = downtime->GetEndTime() - downtime->GetStartTime();
}
attributes->Set("duration", TimestampToMilliseconds(duration));

Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(downtime->GetCheckable());
Expand Down Expand Up @@ -1682,7 +1689,7 @@ void IcingaDB::SendStartedDowntime(const Downtime::Ptr& downtime)
"author", Utility::ValidateUTF8(downtime->GetAuthor()),
"comment", Utility::ValidateUTF8(downtime->GetComment()),
"is_flexible", Convert::ToString((unsigned short)!downtime->GetFixed()),
"flexible_duration", Convert::ToString(downtime->GetDuration()),
"flexible_duration", Convert::ToString(TimestampToMilliseconds(downtime->GetDuration())),
"scheduled_start_time", Convert::ToString(TimestampToMilliseconds(downtime->GetStartTime())),
"scheduled_end_time", Convert::ToString(TimestampToMilliseconds(downtime->GetEndTime())),
"has_been_cancelled", Convert::ToString((unsigned short)downtime->GetWasCancelled()),
Expand Down Expand Up @@ -1761,7 +1768,7 @@ void IcingaDB::SendRemovedDowntime(const Downtime::Ptr& downtime)
"cancelled_by", Utility::ValidateUTF8(downtime->GetRemovedBy()),
"comment", Utility::ValidateUTF8(downtime->GetComment()),
"is_flexible", Convert::ToString((unsigned short)!downtime->GetFixed()),
"flexible_duration", Convert::ToString(downtime->GetDuration()),
"flexible_duration", Convert::ToString(TimestampToMilliseconds(downtime->GetDuration())),
"scheduled_start_time", Convert::ToString(TimestampToMilliseconds(downtime->GetStartTime())),
"scheduled_end_time", Convert::ToString(TimestampToMilliseconds(downtime->GetEndTime())),
"has_been_cancelled", Convert::ToString((unsigned short)downtime->GetWasCancelled()),
Expand Down Expand Up @@ -2163,6 +2170,7 @@ Dictionary::Ptr IcingaDB::SerializeState(const Checkable::Ptr& checkable)
attrs->Set("state", state);
attrs->Set("hard_state", service->HasBeenChecked() ? service->GetLastHardState() : 99);
attrs->Set("severity", service->GetSeverity());
attrs->Set("host_id", GetObjectIdentifier(host));
} else {
attrs->Set("host_id", id);
auto state = host->HasBeenChecked() ? host->GetState() : 99;
Expand Down