add LastState{OK,Warning,Critical,Unknown|Up,Down,Unreachable} time attributes

This commit is contained in:
Michael Friedrich 2013-07-18 18:16:39 +02:00
parent 369fe28acc
commit 2ebf0822ac
5 changed files with 144 additions and 0 deletions

View File

@ -566,6 +566,45 @@ HostState Host::GetLastHardState(void) const
}
}
double Host::GetLastStateUp(void) const
{
ASSERT(!OwnsLock());
Service::Ptr hc = GetHostCheckService();
if (!hc)
return 0;
if (hc->GetLastStateOK() > hc->GetLastStateWarning())
return hc->GetLastStateOK();
else
return hc->GetLastStateWarning();
}
double Host::GetLastStateDown(void) const
{
ASSERT(!OwnsLock());
Service::Ptr hc = GetHostCheckService();
if (!hc)
return 0;
return hc->GetLastStateCritical();
}
double Host::GetLastStateUnreachable(void) const
{
ASSERT(!OwnsLock());
Service::Ptr hc = GetHostCheckService();
if (!hc)
return 0;
return hc->GetLastStateUnreachable();
}
double Host::GetLastStateChange(void) const
{
Service::Ptr hc = GetHostCheckService();

View File

@ -115,6 +115,9 @@ public:
StateType GetLastStateType(void) const;
double GetLastStateChange(void) const;
double GetLastHardStateChange(void) const;
double GetLastStateUp(void) const;
double GetLastStateDown(void) const;
double GetLastStateUnreachable(void) const;
static String StateToString(HostState state);

View File

@ -224,6 +224,76 @@ StateType Service::GetLastStateType(void) const
return static_cast<StateType>(ivalue);
}
void Service::SetLastStateOK(double ts)
{
m_LastStateOK = ts;
Touch("last_state_ok");
}
double Service::GetLastStateOK(void) const
{
if (m_LastStateOK.IsEmpty())
return 0;
return m_LastStateOK;
}
void Service::SetLastStateWarning(double ts)
{
m_LastStateWarning = ts;
Touch("last_state_warning");
}
double Service::GetLastStateWarning(void) const
{
if (m_LastStateWarning.IsEmpty())
return 0;
return m_LastStateWarning;
}
void Service::SetLastStateCritical(double ts)
{
m_LastStateCritical = ts;
Touch("last_state_critical");
}
double Service::GetLastStateCritical(void) const
{
if (m_LastStateCritical.IsEmpty())
return 0;
return m_LastStateCritical;
}
void Service::SetLastStateUnknown(double ts)
{
m_LastStateUnknown = ts;
Touch("last_state_unknown");
}
double Service::GetLastStateUnknown(void) const
{
if (m_LastStateUnknown.IsEmpty())
return 0;
return m_LastStateUnknown;
}
void Service::SetLastStateUnreachable(double ts)
{
m_LastStateUnreachable = ts;
Touch("last_state_unreachable");
}
double Service::GetLastStateUnreachable(void) const
{
if (m_LastStateUnreachable.IsEmpty())
return 0;
return m_LastStateUnreachable;
}
void Service::SetLastReachable(bool reachable)
{
m_LastReachable = reachable;
@ -400,6 +470,9 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
bool reachable = IsReachable();
if (!reachable)
SetLastStateUnreachable(Utility::GetTime());
Host::Ptr host = GetHost();
bool host_reachable = true;
@ -430,6 +503,7 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
attempt = 1;
recovery = true;
ResetNotificationNumbers();
SetLastStateOK(Utility::GetTime());
} else {
if (old_attempt >= GetMaxCheckAttempts()) {
SetStateType(StateTypeHard);
@ -442,6 +516,13 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
}
recovery = false;
if (cr->Get("state") == StateWarning)
SetLastStateWarning(Utility::GetTime());
if (cr->Get("state") == StateCritical)
SetLastStateCritical(Utility::GetTime());
if (cr->Get("state") == StateUnknown)
SetLastStateUnknown(Utility::GetTime());
}
SetCurrentCheckAttempt(attempt);

View File

@ -70,6 +70,11 @@ Service::Service(const Dictionary::Ptr& serializedObject)
RegisterAttribute("last_result", Attribute_Replicated, &m_LastResult);
RegisterAttribute("last_state_change", Attribute_Replicated, &m_LastStateChange);
RegisterAttribute("last_hard_state_change", Attribute_Replicated, &m_LastHardStateChange);
RegisterAttribute("last_state_ok", Attribute_Replicated, &m_LastStateOK);
RegisterAttribute("last_state_warning", Attribute_Replicated, &m_LastStateWarning);
RegisterAttribute("last_state_critical", Attribute_Replicated, &m_LastStateCritical);
RegisterAttribute("last_state_unknown", Attribute_Replicated, &m_LastStateUnknown);
RegisterAttribute("last_state_unreachable", Attribute_Replicated, &m_LastStateUnreachable);
RegisterAttribute("last_in_downtime", Attribute_Replicated, &m_LastInDowntime);
RegisterAttribute("enable_active_checks", Attribute_Replicated, &m_EnableActiveChecks);
RegisterAttribute("enable_passive_checks", Attribute_Replicated, &m_EnablePassiveChecks);

View File

@ -184,6 +184,17 @@ public:
void SetLastHardStateChange(double ts);
double GetLastHardStateChange(void) const;
void SetLastStateOK(double ts);
double GetLastStateOK(void) const;
void SetLastStateWarning(double ts);
double GetLastStateWarning(void) const;
void SetLastStateCritical(double ts);
double GetLastStateCritical(void) const;
void SetLastStateUnknown(double ts);
double GetLastStateUnknown(void) const;
void SetLastStateUnreachable(double ts);
double GetLastStateUnreachable(void) const;
void SetLastReachable(bool reachable);
bool GetLastReachable(void) const;
@ -340,6 +351,11 @@ private:
Attribute<Dictionary::Ptr> m_LastResult;
Attribute<double> m_LastStateChange;
Attribute<double> m_LastHardStateChange;
Attribute<double> m_LastStateOK;
Attribute<double> m_LastStateWarning;
Attribute<double> m_LastStateCritical;
Attribute<double> m_LastStateUnknown;
Attribute<double> m_LastStateUnreachable;
Attribute<bool> m_LastInDowntime;
Attribute<bool> m_EnableActiveChecks;
Attribute<bool> m_EnablePassiveChecks;