mirror of https://github.com/Icinga/icinga2.git
RedisWriter: add icinga:history:stream:{state,notification}#previous_hard_state
This commit is contained in:
parent
4a7a8cb6f8
commit
746a48e2ca
|
@ -300,6 +300,7 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
|
||||||
if (hardChange || is_volatile) {
|
if (hardChange || is_volatile) {
|
||||||
SetLastHardStateRaw(new_state);
|
SetLastHardStateRaw(new_state);
|
||||||
SetLastHardStateChange(now);
|
SetLastHardStateChange(now);
|
||||||
|
SetLastHardStatesRaw(GetLastHardStatesRaw() / 100u + new_state * 100u);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsStateOK(new_state))
|
if (!IsStateOK(new_state))
|
||||||
|
|
|
@ -105,6 +105,9 @@ abstract class Checkable : CustomVarObject
|
||||||
[state, enum, no_user_view, no_user_modify] ServiceState last_hard_state_raw {
|
[state, enum, no_user_view, no_user_modify] ServiceState last_hard_state_raw {
|
||||||
default {{{ return ServiceUnknown; }}}
|
default {{{ return ServiceUnknown; }}}
|
||||||
};
|
};
|
||||||
|
[state, no_user_view, no_user_modify] "unsigned short" last_hard_states_raw {
|
||||||
|
default {{{ return /* current */ 99 * 100 + /* previous */ 99; }}}
|
||||||
|
};
|
||||||
[state, enum] StateType last_state_type {
|
[state, enum] StateType last_state_type {
|
||||||
default {{{ return StateTypeSoft; }}}
|
default {{{ return StateTypeSoft; }}}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1140,6 +1140,18 @@ void RedisWriter::SendConfigDelete(const ConfigObject::Ptr& object)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
unsigned short GetPreviousHardState(const Checkable::Ptr& checkable, const Service::Ptr& service)
|
||||||
|
{
|
||||||
|
auto phs (checkable->GetLastHardStatesRaw() % 100u);
|
||||||
|
|
||||||
|
if (service) {
|
||||||
|
return phs;
|
||||||
|
} else {
|
||||||
|
return phs == 99 ? phs : Host::CalculateState(ServiceState(phs));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RedisWriter::SendStatusUpdate(const ConfigObject::Ptr& object, const CheckResult::Ptr& cr, StateType type)
|
void RedisWriter::SendStatusUpdate(const ConfigObject::Ptr& object, const CheckResult::Ptr& cr, StateType type)
|
||||||
{
|
{
|
||||||
if (!m_Rcon || !m_Rcon->IsConnected())
|
if (!m_Rcon || !m_Rcon->IsConnected())
|
||||||
|
@ -1185,6 +1197,7 @@ void RedisWriter::SendStatusUpdate(const ConfigObject::Ptr& object, const CheckR
|
||||||
// TODO: last_hard/soft_state should be "previous".
|
// TODO: last_hard/soft_state should be "previous".
|
||||||
"last_soft_state", Convert::ToString(cr ? cr->GetState() : 99),
|
"last_soft_state", Convert::ToString(cr ? cr->GetState() : 99),
|
||||||
"last_hard_state", Convert::ToString(service ? service->GetLastHardState() : host->GetLastHardState()),
|
"last_hard_state", Convert::ToString(service ? service->GetLastHardState() : host->GetLastHardState()),
|
||||||
|
"previous_hard_state", Convert::ToString(GetPreviousHardState(checkable, service)),
|
||||||
"output", Utility::ValidateUTF8(std::move(output.first)),
|
"output", Utility::ValidateUTF8(std::move(output.first)),
|
||||||
"long_output", Utility::ValidateUTF8(std::move(output.second)),
|
"long_output", Utility::ValidateUTF8(std::move(output.second)),
|
||||||
"check_source", cr->GetCheckSource(),
|
"check_source", cr->GetCheckSource(),
|
||||||
|
@ -1234,6 +1247,7 @@ void RedisWriter::SendSentNotification(
|
||||||
"type", Convert::ToString(type),
|
"type", Convert::ToString(type),
|
||||||
"send_time", Convert::ToString(TimestampToMilliseconds(Utility::GetTime())),
|
"send_time", Convert::ToString(TimestampToMilliseconds(Utility::GetTime())),
|
||||||
"state", Convert::ToString(cr->GetState()),
|
"state", Convert::ToString(cr->GetState()),
|
||||||
|
"previous_hard_state", Convert::ToString(GetPreviousHardState(checkable, service)),
|
||||||
"output", Utility::ValidateUTF8(std::move(output.first)),
|
"output", Utility::ValidateUTF8(std::move(output.first)),
|
||||||
"long_output", Utility::ValidateUTF8(std::move(output.second)),
|
"long_output", Utility::ValidateUTF8(std::move(output.second)),
|
||||||
"users_notified", Convert::ToString(users),
|
"users_notified", Convert::ToString(users),
|
||||||
|
|
Loading…
Reference in New Issue