mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 14:44:32 +02:00
Icinga DB: make icinga:history:stream:state#id deterministic
... i.e. UUID -> SHA1(x..., check time) given that SHA1(x...) = checkable id. Rationale: allow both masters to write the same state history concurrently (while not in split-brain), so that REPLACE INTO deduplicates the same events written twice.
This commit is contained in:
parent
afb2635e76
commit
4f6c87402e
@ -1522,6 +1522,9 @@ void IcingaDB::SendStateChange(const ConfigObject::Ptr& object, const CheckResul
|
|||||||
if (!checkable)
|
if (!checkable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!cr)
|
||||||
|
return;
|
||||||
|
|
||||||
Host::Ptr host;
|
Host::Ptr host;
|
||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
|
|
||||||
@ -1536,9 +1539,14 @@ void IcingaDB::SendStateChange(const ConfigObject::Ptr& object, const CheckResul
|
|||||||
hard_state = service ? Convert::ToLong(service->GetLastHardState()) : Convert::ToLong(host->GetLastHardState());
|
hard_state = service ? Convert::ToLong(service->GetLastHardState()) : Convert::ToLong(host->GetLastHardState());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto eventTime (TimestampToMilliseconds(cr->GetExecutionEnd()));
|
||||||
|
|
||||||
|
Array::Ptr rawId = new Array(Prepend(GetEnvironment(), GetObjectIdentifiersWithoutEnv(object)));
|
||||||
|
rawId->Add(eventTime);
|
||||||
|
|
||||||
std::vector<String> xAdd ({
|
std::vector<String> xAdd ({
|
||||||
"XADD", "icinga:history:stream:state", "*",
|
"XADD", "icinga:history:stream:state", "*",
|
||||||
"id", Utility::NewUniqueID(),
|
"id", HashValue(rawId),
|
||||||
"environment_id", m_EnvironmentId,
|
"environment_id", m_EnvironmentId,
|
||||||
"host_id", GetObjectIdentifier(host),
|
"host_id", GetObjectIdentifier(host),
|
||||||
"state_type", Convert::ToString(type),
|
"state_type", Convert::ToString(type),
|
||||||
@ -1548,7 +1556,7 @@ void IcingaDB::SendStateChange(const ConfigObject::Ptr& object, const CheckResul
|
|||||||
"previous_soft_state", Convert::ToString(GetPreviousState(checkable, service, StateTypeSoft)),
|
"previous_soft_state", Convert::ToString(GetPreviousState(checkable, service, StateTypeSoft)),
|
||||||
"previous_hard_state", Convert::ToString(GetPreviousState(checkable, service, StateTypeHard)),
|
"previous_hard_state", Convert::ToString(GetPreviousState(checkable, service, StateTypeHard)),
|
||||||
"max_check_attempts", Convert::ToString(checkable->GetMaxCheckAttempts()),
|
"max_check_attempts", Convert::ToString(checkable->GetMaxCheckAttempts()),
|
||||||
"event_time", Convert::ToString(TimestampToMilliseconds(cr ? cr->GetExecutionEnd() : Utility::GetTime())),
|
"event_time", Convert::ToString(eventTime),
|
||||||
"event_id", Utility::NewUniqueID(),
|
"event_id", Utility::NewUniqueID(),
|
||||||
"event_type", "state_change"
|
"event_type", "state_change"
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user