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).
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).
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).
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
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"
"\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"
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())
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 */
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);
[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 {
[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;
[no_storage, protected] bool flapping {
get {{{ return false; }}}
};
+ [no_storage] double last_check {
+ get;
+ };
[config, navigation] name(Endpoint) command_endpoint (CommandEndpointRaw) {
navigate {{{
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)
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);
[enum, no_storage] HostState last_hard_state {
get;
};
-
+ [state] double last_state_up;
+ [state] double last_state_down;
};
}
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")
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);
return GetLastHardStateRaw();
}}}
};
+ [state] double last_state_ok (LastStateOK);
+ [state] double last_state_warning;
+ [state] double last_state_critical;
+ [state] double last_state_unknown;
};
}