Merge pull request #7657 from Icinga/feature/icingadb-host_id

IcingaDB: always set *#host_id
This commit is contained in:
Noah Hilverling 2019-11-27 14:38:22 +01:00 committed by GitHub
commit ce4409d1d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 20 deletions

View File

@ -1169,6 +1169,7 @@ void IcingaDB::SendStatusUpdate(const ConfigObject::Ptr& object, const CheckResu
"XADD", "icinga:history:stream:state", "*",
"id", Utility::NewUniqueID(),
"environment_id", SHA1(GetEnvironment()),
"host_id", GetObjectIdentifier(host),
"state_type", Convert::ToString(type),
"soft_state", Convert::ToString(cr ? service ? cr->GetState() : Host::CalculateState(cr->GetState()) : 99),
"hard_state", Convert::ToString(hard_state),
@ -1207,8 +1208,6 @@ void IcingaDB::SendStatusUpdate(const ConfigObject::Ptr& object, const CheckResu
} else {
xAdd.emplace_back("object_type");
xAdd.emplace_back("host");
xAdd.emplace_back("host_id");
xAdd.emplace_back(GetObjectIdentifier(checkable));
}
auto endpoint (Endpoint::GetLocalEndpoint());
@ -1229,7 +1228,9 @@ void IcingaDB::SendSentNotification(
if (!m_Rcon || !m_Rcon->IsConnected())
return;
auto service (dynamic_pointer_cast<Service>(checkable));
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
auto finalText = text;
if (finalText == "" && cr) {
@ -1244,6 +1245,7 @@ void IcingaDB::SendSentNotification(
"id", notificationHistoryId,
"environment_id", SHA1(GetEnvironment()),
"notification_id", GetObjectIdentifier(notification),
"host_id", GetObjectIdentifier(host),
"type", Convert::ToString(type),
"state", Convert::ToString(service ? cr->GetState() : Host::CalculateState(cr->GetState())),
"previous_hard_state", Convert::ToString(GetPreviousState(checkable, service, StateTypeHard)),
@ -1263,8 +1265,6 @@ void IcingaDB::SendSentNotification(
} else {
xAdd.emplace_back("object_type");
xAdd.emplace_back("host");
xAdd.emplace_back("host_id");
xAdd.emplace_back(GetObjectIdentifier(checkable));
}
auto endpoint (Endpoint::GetLocalEndpoint());
@ -1298,13 +1298,17 @@ void IcingaDB::SendStartedDowntime(const Downtime::Ptr& downtime)
SendConfigUpdate(downtime, true);
auto checkable (downtime->GetCheckable());
auto service (dynamic_pointer_cast<Service>(checkable));
auto triggeredBy (Downtime::GetByName(downtime->GetTriggeredBy()));
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
std::vector<String> xAdd ({
"XADD", "icinga:history:stream:downtime", "*",
"downtime_id", GetObjectIdentifier(downtime),
"environment_id", SHA1(GetEnvironment()),
"host_id", GetObjectIdentifier(host),
"entry_time", Convert::ToString(TimestampToMilliseconds(downtime->GetEntryTime())),
"author", Utility::ValidateUTF8(downtime->GetAuthor()),
"comment", Utility::ValidateUTF8(downtime->GetComment()),
@ -1326,8 +1330,6 @@ void IcingaDB::SendStartedDowntime(const Downtime::Ptr& downtime)
} else {
xAdd.emplace_back("object_type");
xAdd.emplace_back("host");
xAdd.emplace_back("host_id");
xAdd.emplace_back(GetObjectIdentifier(checkable));
}
if (triggeredBy) {
@ -1363,9 +1365,12 @@ void IcingaDB::SendRemovedDowntime(const Downtime::Ptr& downtime)
return;
auto checkable (downtime->GetCheckable());
auto service (dynamic_pointer_cast<Service>(checkable));
auto triggeredBy (Downtime::GetByName(downtime->GetTriggeredBy()));
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
// Downtime never got triggered (didn't send "downtime_start") so we don't want to send "downtime_end"
if (downtime->GetTriggerTime() == 0)
return;
@ -1374,6 +1379,7 @@ void IcingaDB::SendRemovedDowntime(const Downtime::Ptr& downtime)
"XADD", "icinga:history:stream:downtime", "*",
"downtime_id", GetObjectIdentifier(downtime),
"environment_id", SHA1(GetEnvironment()),
"host_id", GetObjectIdentifier(host),
"entry_time", Convert::ToString(TimestampToMilliseconds(downtime->GetEntryTime())),
"author", Utility::ValidateUTF8(downtime->GetRemovedBy()),
"comment", Utility::ValidateUTF8(downtime->GetComment()),
@ -1396,8 +1402,6 @@ void IcingaDB::SendRemovedDowntime(const Downtime::Ptr& downtime)
} else {
xAdd.emplace_back("object_type");
xAdd.emplace_back("host");
xAdd.emplace_back("host_id");
xAdd.emplace_back(GetObjectIdentifier(checkable));
}
if (triggeredBy) {
@ -1433,12 +1437,16 @@ void IcingaDB::SendAddedComment(const Comment::Ptr& comment)
return;
auto checkable (comment->GetCheckable());
auto service (dynamic_pointer_cast<Service>(checkable));
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
std::vector<String> xAdd ({
"XADD", "icinga:history:stream:comment", "*",
"comment_id", GetObjectIdentifier(comment),
"environment_id", SHA1(GetEnvironment()),
"host_id", GetObjectIdentifier(host),
"entry_time", Convert::ToString(TimestampToMilliseconds(comment->GetEntryTime())),
"author", Utility::ValidateUTF8(comment->GetAuthor()),
"comment", Utility::ValidateUTF8(comment->GetText()),
@ -1458,8 +1466,6 @@ void IcingaDB::SendAddedComment(const Comment::Ptr& comment)
} else {
xAdd.emplace_back("object_type");
xAdd.emplace_back("host");
xAdd.emplace_back("host_id");
xAdd.emplace_back(GetObjectIdentifier(checkable));
}
auto endpoint (Endpoint::GetLocalEndpoint());
@ -1478,12 +1484,16 @@ void IcingaDB::SendRemovedComment(const Comment::Ptr& comment)
return;
auto checkable (comment->GetCheckable());
auto service (dynamic_pointer_cast<Service>(checkable));
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
std::vector<String> xAdd ({
"XADD", "icinga:history:stream:comment", "*",
"comment_id", GetObjectIdentifier(comment),
"environment_id", SHA1(GetEnvironment()),
"host_id", GetObjectIdentifier(host),
"entry_time", Convert::ToString(TimestampToMilliseconds(comment->GetEntryTime())),
"author", Utility::ValidateUTF8(comment->GetRemovedBy()),
"comment", Utility::ValidateUTF8(comment->GetText()),
@ -1503,8 +1513,6 @@ void IcingaDB::SendRemovedComment(const Comment::Ptr& comment)
} else {
xAdd.emplace_back("object_type");
xAdd.emplace_back("host");
xAdd.emplace_back("host_id");
xAdd.emplace_back(GetObjectIdentifier(checkable));
}
auto endpoint (Endpoint::GetLocalEndpoint());
@ -1532,12 +1540,15 @@ void IcingaDB::SendFlappingChanged(const Checkable::Ptr& checkable, const Value&
if (!m_Rcon || !m_Rcon->IsConnected())
return;
auto service (dynamic_pointer_cast<Service>(checkable));
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
std::vector<String> xAdd ({
"XADD", "icinga:history:stream:flapping", "*",
"id", Utility::NewUniqueID(),
"environment_id", SHA1(GetEnvironment()),
"host_id", GetObjectIdentifier(host),
"percent_state_change", Convert::ToString(checkable->GetFlappingCurrent()),
"flapping_threshold_low", Convert::ToString(checkable->GetFlappingThresholdLow()),
"flapping_threshold_high", Convert::ToString(checkable->GetFlappingThresholdHigh()),
@ -1554,8 +1565,6 @@ void IcingaDB::SendFlappingChanged(const Checkable::Ptr& checkable, const Value&
} else {
xAdd.emplace_back("object_type");
xAdd.emplace_back("host");
xAdd.emplace_back("host_id");
xAdd.emplace_back(GetObjectIdentifier(checkable));
}
auto endpoint (Endpoint::GetLocalEndpoint());