Add host.last_state_{up,down} and last_check attribute, hide *_raw attributes

fixes #10508
fixes #10509
This commit is contained in:
Michael Friedrich 2015-11-02 14:10:44 +01:00
parent a2c09a122b
commit 43976d3989
11 changed files with 56 additions and 43 deletions

View File

@ -591,6 +591,7 @@ Runtime Attributes:
Name | Type | Description
--------------------------|---------------|-----------------
next\_check | Number | When the next check occurs (as a UNIX timestamp).
last\_check | Number | When the last check occured (as a UNIX timestamp).
check\_attempt | Number | The current check attempt number.
state\_type | Number | The current state type (0 = SOFT, 1 = HARD).
last\_state\_type | Number | The previous state type (0 = SOFT, 1 = HARD).
@ -606,6 +607,8 @@ Runtime Attributes:
state | Number | The current state (0 = UP, 1 = DOWN).
last\_state | Number | The previous state (0 = UP, 1 = DOWN).
last\_hard\_state | Number | The last hard state (0 = UP, 1 = DOWN).
last_state_up | Number | When the last UP state occurred (as a UNIX timestamp).
last_state_down | Number | When the last DOWN state occurred (as a UNIX timestamp).
@ -1206,6 +1209,7 @@ Runtime Attributes:
Name | Type | Description
--------------------------|---------------|-----------------
next\_check | Number | When the next check occurs (as a UNIX timestamp).
last\_check | Number | When the last check occured (as a UNIX timestamp).
check\_attempt | Number | The current check attempt number.
state\_type | Number | The current state type (0 = SOFT, 1 = HARD).
last\_state\_type | Number | The previous state type (0 = SOFT, 1 = HARD).
@ -1221,6 +1225,10 @@ Runtime Attributes:
state | Number | The current state (0 = OK, 1 = WARNING, 2 = CRITICAL, 3 = UNKNOWN).
last\_state | Number | The previous state (0 = OK, 1 = WARNING, 2 = CRITICAL, 3 = UNKNOWN).
last\_hard\_state | Number | The last hard state (0 = OK, 1 = WARNING, 2 = CRITICAL, 3 = UNKNOWN).
last_state_ok | Number | When the last OK state occurred (as a UNIX timestamp).
last_state_warning | Number | When the last WARNING state occurred (as a UNIX timestamp).
last_state_critical | Number | When the last CRITICAL state occurred (as a UNIX timestamp).
last_state_unknown | Number | When the last UNKNOWN state occurred (as a UNIX timestamp).
## <a id="objecttype-servicegroup"></a> ServiceGroup

View File

@ -344,11 +344,17 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl
tie(host, service) = GetHostService(checkable);
if (service) {
fp << "\t" << "current_state=" << service->GetState() << "\n"
<< "\t" << "last_hard_state=" << service->GetLastHardState() << "\n";
fp << "\t" "current_state=" << service->GetState() << "\n"
"\t" "last_hard_state=" << service->GetLastHardState() << "\n"
"\t" "last_time_ok=" << static_cast<int>(service->GetLastStateOK()) << "\n"
"\t" "last_time_warn=" << static_cast<int>(service->GetLastStateWarning()) << "\n"
"\t" "last_time_critical=" << static_cast<int>(service->GetLastStateCritical()) << "\n"
"\t" "last_time_unknown=" << static_cast<int>(service->GetLastStateUnknown()) << "\n";
} else {
fp << "\t" << "current_state=" << CompatUtility::GetHostCurrentState(host) << "\n"
<< "\t" << "last_hard_state=" << host->GetLastHardState() << "\n";
fp << "\t" "current_state=" << CompatUtility::GetHostCurrentState(host) << "\n"
"\t" "last_hard_state=" << host->GetLastHardState() << "\n"
"\t" "last_time_up=" << static_cast<int>(host->GetLastStateUp()) << "\n"
"\t" "last_time_down=" << static_cast<int>(host->GetLastStateDown()) << "\n";
}
fp << "\t" "state_type=" << checkable->GetStateType() << "\n"
@ -366,10 +372,6 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl
"\t" "max_attempts=" << checkable->GetMaxCheckAttempts() << "\n"
"\t" "last_state_change=" << static_cast<long>(checkable->GetLastStateChange()) << "\n"
"\t" "last_hard_state_change=" << static_cast<long>(checkable->GetLastHardStateChange()) << "\n"
"\t" "last_time_ok=" << static_cast<int>(checkable->GetLastStateOK()) << "\n"
"\t" "last_time_warn=" << static_cast<int>(checkable->GetLastStateWarning()) << "\n"
"\t" "last_time_critical=" << static_cast<int>(checkable->GetLastStateCritical()) << "\n"
"\t" "last_time_unknown=" << static_cast<int>(checkable->GetLastStateUnknown()) << "\n"
"\t" "last_update=" << static_cast<long>(time(NULL)) << "\n"
"\t" "notifications_enabled=" << CompatUtility::GetCheckableNotificationsEnabled(checkable) << "\n"
"\t" "active_checks_enabled=" << CompatUtility::GetCheckableActiveChecksEnabled(checkable) << "\n"

View File

@ -185,7 +185,7 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
recovery = true; // NOT OK -> SOFT/HARD OK
ResetNotificationNumbers();
SetLastStateOK(Utility::GetTime());
SaveLastState(ServiceOK, Utility::GetTime());
/* update reachability for child objects in OK state */
if (!children.empty())
@ -203,19 +203,8 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
attempt = old_attempt;
}
switch (cr->GetState()) {
case ServiceOK:
/* Nothing to do here. */
break;
case ServiceWarning:
SetLastStateWarning(Utility::GetTime());
break;
case ServiceCritical:
SetLastStateCritical(Utility::GetTime());
break;
case ServiceUnknown:
SetLastStateUnknown(Utility::GetTime());
break;
if (cr->GetState() != ServiceOK) {
SaveLastState(cr->GetState(), Utility::GetTime());
}
/* update reachability for child objects in NOT-OK state */

View File

@ -92,8 +92,9 @@ public:
void UpdateNextCheck(void);
bool HasBeenChecked(void) const;
virtual double GetLastCheck(void) const override;
double GetLastCheck(void) const;
virtual void SaveLastState(ServiceState state, double timestamp) = 0;
static void UpdateStatistics(const CheckResult::Ptr& cr, CheckableType type);

View File

@ -101,16 +101,16 @@ abstract class Checkable : CustomVarObject
[state] int check_attempt {
default {{{ return 1; }}}
};
[state, enum] ServiceState state_raw {
[state, enum, no_user_view, no_user_modify] ServiceState state_raw {
default {{{ return ServiceUnknown; }}}
};
[state, enum] StateType state_type {
default {{{ return StateTypeSoft; }}}
};
[state, enum] ServiceState last_state_raw {
[state, enum, no_user_view, no_user_modify] ServiceState last_state_raw {
default {{{ return ServiceUnknown; }}}
};
[state, enum] ServiceState last_hard_state_raw {
[state, enum, no_user_view, no_user_modify] ServiceState last_hard_state_raw {
default {{{ return ServiceUnknown; }}}
};
[state, enum] StateType last_state_type {
@ -126,10 +126,6 @@ abstract class Checkable : CustomVarObject
[state] double last_hard_state_change {
default {{{ return Application::GetStartTime(); }}}
};
[state] double last_state_ok (LastStateOK);
[state] double last_state_warning;
[state] double last_state_critical;
[state] double last_state_unknown;
[state] double last_state_unreachable;
[state] bool last_in_downtime;
[state] bool force_next_check;
@ -144,6 +140,9 @@ abstract class Checkable : CustomVarObject
[no_storage, protected] bool flapping {
get {{{ return false; }}}
};
[no_storage] double last_check {
get;
};
[config, navigation] name(Endpoint) command_endpoint (CommandEndpointRaw) {
navigate {{{

View File

@ -173,17 +173,12 @@ HostState Host::GetLastHardState(void) const
return CalculateState(GetLastHardStateRaw());
}
double Host::GetLastStateUp(void) const
void Host::SaveLastState(ServiceState state, double timestamp)
{
if (GetLastStateOK() > GetLastStateWarning())
return GetLastStateOK();
else
return GetLastStateWarning();
}
double Host::GetLastStateDown(void) const
{
return GetLastStateCritical();
if (state == ServiceOK || state == ServiceWarning)
SetLastStateUp(timestamp);
else if (state == ServiceCritical)
SetLastStateDown(timestamp);
}
HostState Host::StateFromString(const String& state)

View File

@ -54,8 +54,8 @@ public:
virtual HostState GetState(void) const override;
virtual HostState GetLastState(void) const override;
virtual HostState GetLastHardState(void) const override;
double GetLastStateUp(void) const;
double GetLastStateDown(void) const;
virtual void SaveLastState(ServiceState state, double timestamp);
static HostState StateFromString(const String& state);
static String StateToString(HostState state);

View File

@ -52,7 +52,8 @@ class Host : Checkable
[enum, no_storage] HostState last_hard_state {
get;
};
[state] double last_state_up;
[state] double last_state_down;
};
}

View File

@ -117,6 +117,18 @@ Host::Ptr Service::GetHost(void) const
return m_Host;
}
void Service::SaveLastState(ServiceState state, double timestamp)
{
if (state == ServiceOK)
SetLastStateOK(timestamp);
else if (state == ServiceWarning)
SetLastStateWarning(timestamp);
else if (state == ServiceCritical)
SetLastStateCritical(timestamp);
else if (state == ServiceUnknown)
SetLastStateUnknown(timestamp);
}
ServiceState Service::StateFromString(const String& state)
{
if (state == "OK")

View File

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

View File

@ -74,6 +74,10 @@ class Service : Checkable < ServiceNameComposer
return GetLastHardStateRaw();
}}}
};
[state] double last_state_ok (LastStateOK);
[state] double last_state_warning;
[state] double last_state_critical;
[state] double last_state_unknown;
};
}