Refactor patch for host recovery notifications

refs #10225
This commit is contained in:
Michael Friedrich 2016-03-15 09:46:20 +01:00
parent af58be7884
commit 3bd6848763
6 changed files with 23 additions and 21 deletions

View File

@ -95,16 +95,6 @@ double Checkable::GetLastCheck(void) const
return schedule_end;
}
bool Checkable::StateIsOK(CheckableType type, ServiceState state)
{
if (type == CheckableHost && Host::CalculateState(state) == HostUp)
return true;
else if (type == CheckableService && state == ServiceOK)
return true;
return false;
}
void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrigin::Ptr& origin)
{
{
@ -184,13 +174,13 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
if (!old_cr) {
SetStateType(StateTypeHard);
} else if (StateIsOK(checkableType, cr->GetState())) {
if (StateIsOK(checkableType, old_state) && old_stateType == StateTypeSoft) {
} else if (IsStateOK(cr->GetState())) {
if (IsStateOK(old_state) && old_stateType == StateTypeSoft) {
SetStateType(StateTypeHard); // SOFT OK -> HARD OK
recovery = true;
}
if (!StateIsOK(checkableType, old_state))
if (!IsStateOK(old_state))
recovery = true; // NOT OK -> SOFT/HARD OK
ResetNotificationNumbers();
@ -202,10 +192,10 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
} else {
if (old_attempt >= GetMaxCheckAttempts()) {
SetStateType(StateTypeHard);
} else if (old_stateType == StateTypeSoft && !StateIsOK(checkableType, old_state)) {
} else if (old_stateType == StateTypeSoft && !IsStateOK(old_state)) {
SetStateType(StateTypeSoft);
attempt = old_attempt + 1; // NOT-OK -> NOT-OK counter
} else if (StateIsOK(checkableType, old_state)) {
} else if (IsStateOK(old_state)) {
SetStateType(StateTypeSoft);
attempt = 1; // OK -> NOT-OK transition, reset the counter
@ -219,7 +209,7 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
attempt = old_attempt;
}
if (!StateIsOK(checkableType, cr->GetState())) {
if (!IsStateOK(cr->GetState())) {
SaveLastState(cr->GetState(), Utility::GetTime());
}
@ -249,7 +239,7 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
/* remove acknowledgements */
if (GetAcknowledgement() == AcknowledgementNormal ||
(GetAcknowledgement() == AcknowledgementSticky && StateIsOK(checkableType, new_state))) {
(GetAcknowledgement() == AcknowledgementSticky && IsStateOK(new_state))) {
ClearAcknowledgement();
}
@ -280,7 +270,7 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
SetLastHardStateChange(now);
}
if (!StateIsOK(checkableType, new_state))
if (!IsStateOK(new_state))
TriggerDowntimes();
/* statistics for external tools */
@ -302,10 +292,10 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
if (!old_cr)
send_notification = false; /* Don't send notifications for the initial state change */
if (StateIsOK(checkableType, old_state) && old_stateType == StateTypeSoft)
if (IsStateOK(old_state) && old_stateType == StateTypeSoft)
send_notification = false; /* Don't send notifications for SOFT-OK -> HARD-OK. */
if (is_volatile && StateIsOK(checkableType, old_state) && StateIsOK(checkableType, new_state))
if (is_volatile && IsStateOK(old_state) && IsStateOK(new_state))
send_notification = false; /* Don't send notifications for volatile OK -> OK changes. */
bool send_downtime_notification = (GetLastInDowntime() != in_downtime);

View File

@ -92,7 +92,7 @@ public:
void UpdateNextCheck(void);
bool HasBeenChecked(void) const;
bool StateIsOK(CheckableType type, ServiceState state);
virtual bool IsStateOK(ServiceState state) = 0;
virtual double GetLastCheck(void) const override;

View File

@ -182,6 +182,11 @@ HostState Host::GetLastHardState(void) const
return CalculateState(GetLastHardStateRaw());
}
bool Host::IsStateOK(ServiceState state)
{
return Host::CalculateState(state) == HostUp;
}
void Host::SaveLastState(ServiceState state, double timestamp)
{
if (state == ServiceOK || state == ServiceWarning)

View File

@ -55,6 +55,7 @@ public:
virtual HostState GetLastState(void) const override;
virtual HostState GetLastHardState(void) const override;
virtual bool IsStateOK(ServiceState state) override;
virtual void SaveLastState(ServiceState state, double timestamp) override;
static HostState StateFromString(const String& state);

View File

@ -126,6 +126,11 @@ Host::Ptr Service::GetHost(void) const
return m_Host;
}
bool Service::IsStateOK(ServiceState state)
{
return state == ServiceOK;
}
void Service::SaveLastState(ServiceState state, double timestamp)
{
if (state == ServiceOK)

View File

@ -45,6 +45,7 @@ public:
virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, Value *result) const override;
virtual bool IsStateOK(ServiceState state) override;
virtual void SaveLastState(ServiceState state, double timestamp) override;
static ServiceState StateFromString(const String& state);