mirror of https://github.com/Icinga/icinga2.git
Add host.last_state_{up,down} and last_check attribute, hide *_raw attributes
fixes #10508 fixes #10509
This commit is contained in:
parent
a2c09a122b
commit
43976d3989
|
@ -591,6 +591,7 @@ Runtime Attributes:
|
||||||
Name | Type | Description
|
Name | Type | Description
|
||||||
--------------------------|---------------|-----------------
|
--------------------------|---------------|-----------------
|
||||||
next\_check | Number | When the next check occurs (as a UNIX timestamp).
|
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.
|
check\_attempt | Number | The current check attempt number.
|
||||||
state\_type | Number | The current state type (0 = SOFT, 1 = HARD).
|
state\_type | Number | The current state type (0 = SOFT, 1 = HARD).
|
||||||
last\_state\_type | Number | The previous 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).
|
state | Number | The current state (0 = UP, 1 = DOWN).
|
||||||
last\_state | Number | The previous 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\_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
|
Name | Type | Description
|
||||||
--------------------------|---------------|-----------------
|
--------------------------|---------------|-----------------
|
||||||
next\_check | Number | When the next check occurs (as a UNIX timestamp).
|
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.
|
check\_attempt | Number | The current check attempt number.
|
||||||
state\_type | Number | The current state type (0 = SOFT, 1 = HARD).
|
state\_type | Number | The current state type (0 = SOFT, 1 = HARD).
|
||||||
last\_state\_type | Number | The previous 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).
|
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\_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\_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
|
## <a id="objecttype-servicegroup"></a> ServiceGroup
|
||||||
|
|
|
@ -344,11 +344,17 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl
|
||||||
tie(host, service) = GetHostService(checkable);
|
tie(host, service) = GetHostService(checkable);
|
||||||
|
|
||||||
if (service) {
|
if (service) {
|
||||||
fp << "\t" << "current_state=" << service->GetState() << "\n"
|
fp << "\t" "current_state=" << service->GetState() << "\n"
|
||||||
<< "\t" << "last_hard_state=" << service->GetLastHardState() << "\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 {
|
} else {
|
||||||
fp << "\t" << "current_state=" << CompatUtility::GetHostCurrentState(host) << "\n"
|
fp << "\t" "current_state=" << CompatUtility::GetHostCurrentState(host) << "\n"
|
||||||
<< "\t" << "last_hard_state=" << host->GetLastHardState() << "\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"
|
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" "max_attempts=" << checkable->GetMaxCheckAttempts() << "\n"
|
||||||
"\t" "last_state_change=" << static_cast<long>(checkable->GetLastStateChange()) << "\n"
|
"\t" "last_state_change=" << static_cast<long>(checkable->GetLastStateChange()) << "\n"
|
||||||
"\t" "last_hard_state_change=" << static_cast<long>(checkable->GetLastHardStateChange()) << "\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" "last_update=" << static_cast<long>(time(NULL)) << "\n"
|
||||||
"\t" "notifications_enabled=" << CompatUtility::GetCheckableNotificationsEnabled(checkable) << "\n"
|
"\t" "notifications_enabled=" << CompatUtility::GetCheckableNotificationsEnabled(checkable) << "\n"
|
||||||
"\t" "active_checks_enabled=" << CompatUtility::GetCheckableActiveChecksEnabled(checkable) << "\n"
|
"\t" "active_checks_enabled=" << CompatUtility::GetCheckableActiveChecksEnabled(checkable) << "\n"
|
||||||
|
|
|
@ -185,7 +185,7 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
|
||||||
recovery = true; // NOT OK -> SOFT/HARD OK
|
recovery = true; // NOT OK -> SOFT/HARD OK
|
||||||
|
|
||||||
ResetNotificationNumbers();
|
ResetNotificationNumbers();
|
||||||
SetLastStateOK(Utility::GetTime());
|
SaveLastState(ServiceOK, Utility::GetTime());
|
||||||
|
|
||||||
/* update reachability for child objects in OK state */
|
/* update reachability for child objects in OK state */
|
||||||
if (!children.empty())
|
if (!children.empty())
|
||||||
|
@ -203,19 +203,8 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
|
||||||
attempt = old_attempt;
|
attempt = old_attempt;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (cr->GetState()) {
|
if (cr->GetState() != ServiceOK) {
|
||||||
case ServiceOK:
|
SaveLastState(cr->GetState(), Utility::GetTime());
|
||||||
/* Nothing to do here. */
|
|
||||||
break;
|
|
||||||
case ServiceWarning:
|
|
||||||
SetLastStateWarning(Utility::GetTime());
|
|
||||||
break;
|
|
||||||
case ServiceCritical:
|
|
||||||
SetLastStateCritical(Utility::GetTime());
|
|
||||||
break;
|
|
||||||
case ServiceUnknown:
|
|
||||||
SetLastStateUnknown(Utility::GetTime());
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* update reachability for child objects in NOT-OK state */
|
/* update reachability for child objects in NOT-OK state */
|
||||||
|
|
|
@ -92,8 +92,9 @@ public:
|
||||||
void UpdateNextCheck(void);
|
void UpdateNextCheck(void);
|
||||||
|
|
||||||
bool HasBeenChecked(void) const;
|
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);
|
static void UpdateStatistics(const CheckResult::Ptr& cr, CheckableType type);
|
||||||
|
|
||||||
|
|
|
@ -101,16 +101,16 @@ abstract class Checkable : CustomVarObject
|
||||||
[state] int check_attempt {
|
[state] int check_attempt {
|
||||||
default {{{ return 1; }}}
|
default {{{ return 1; }}}
|
||||||
};
|
};
|
||||||
[state, enum] ServiceState state_raw {
|
[state, enum, no_user_view, no_user_modify] ServiceState state_raw {
|
||||||
default {{{ return ServiceUnknown; }}}
|
default {{{ return ServiceUnknown; }}}
|
||||||
};
|
};
|
||||||
[state, enum] StateType state_type {
|
[state, enum] StateType state_type {
|
||||||
default {{{ return StateTypeSoft; }}}
|
default {{{ return StateTypeSoft; }}}
|
||||||
};
|
};
|
||||||
[state, enum] ServiceState last_state_raw {
|
[state, enum, no_user_view, no_user_modify] ServiceState last_state_raw {
|
||||||
default {{{ return ServiceUnknown; }}}
|
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; }}}
|
default {{{ return ServiceUnknown; }}}
|
||||||
};
|
};
|
||||||
[state, enum] StateType last_state_type {
|
[state, enum] StateType last_state_type {
|
||||||
|
@ -126,10 +126,6 @@ abstract class Checkable : CustomVarObject
|
||||||
[state] double last_hard_state_change {
|
[state] double last_hard_state_change {
|
||||||
default {{{ return Application::GetStartTime(); }}}
|
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] double last_state_unreachable;
|
||||||
[state] bool last_in_downtime;
|
[state] bool last_in_downtime;
|
||||||
[state] bool force_next_check;
|
[state] bool force_next_check;
|
||||||
|
@ -144,6 +140,9 @@ abstract class Checkable : CustomVarObject
|
||||||
[no_storage, protected] bool flapping {
|
[no_storage, protected] bool flapping {
|
||||||
get {{{ return false; }}}
|
get {{{ return false; }}}
|
||||||
};
|
};
|
||||||
|
[no_storage] double last_check {
|
||||||
|
get;
|
||||||
|
};
|
||||||
|
|
||||||
[config, navigation] name(Endpoint) command_endpoint (CommandEndpointRaw) {
|
[config, navigation] name(Endpoint) command_endpoint (CommandEndpointRaw) {
|
||||||
navigate {{{
|
navigate {{{
|
||||||
|
|
|
@ -173,17 +173,12 @@ HostState Host::GetLastHardState(void) const
|
||||||
return CalculateState(GetLastHardStateRaw());
|
return CalculateState(GetLastHardStateRaw());
|
||||||
}
|
}
|
||||||
|
|
||||||
double Host::GetLastStateUp(void) const
|
void Host::SaveLastState(ServiceState state, double timestamp)
|
||||||
{
|
{
|
||||||
if (GetLastStateOK() > GetLastStateWarning())
|
if (state == ServiceOK || state == ServiceWarning)
|
||||||
return GetLastStateOK();
|
SetLastStateUp(timestamp);
|
||||||
else
|
else if (state == ServiceCritical)
|
||||||
return GetLastStateWarning();
|
SetLastStateDown(timestamp);
|
||||||
}
|
|
||||||
|
|
||||||
double Host::GetLastStateDown(void) const
|
|
||||||
{
|
|
||||||
return GetLastStateCritical();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HostState Host::StateFromString(const String& state)
|
HostState Host::StateFromString(const String& state)
|
||||||
|
|
|
@ -54,8 +54,8 @@ public:
|
||||||
virtual HostState GetState(void) const override;
|
virtual HostState GetState(void) const override;
|
||||||
virtual HostState GetLastState(void) const override;
|
virtual HostState GetLastState(void) const override;
|
||||||
virtual HostState GetLastHardState(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 HostState StateFromString(const String& state);
|
||||||
static String StateToString(HostState state);
|
static String StateToString(HostState state);
|
||||||
|
|
|
@ -52,7 +52,8 @@ class Host : Checkable
|
||||||
[enum, no_storage] HostState last_hard_state {
|
[enum, no_storage] HostState last_hard_state {
|
||||||
get;
|
get;
|
||||||
};
|
};
|
||||||
|
[state] double last_state_up;
|
||||||
|
[state] double last_state_down;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,6 +117,18 @@ Host::Ptr Service::GetHost(void) const
|
||||||
return m_Host;
|
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)
|
ServiceState Service::StateFromString(const String& state)
|
||||||
{
|
{
|
||||||
if (state == "OK")
|
if (state == "OK")
|
||||||
|
|
|
@ -45,6 +45,8 @@ public:
|
||||||
|
|
||||||
virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, Value *result) const override;
|
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 ServiceState StateFromString(const String& state);
|
||||||
static String StateToString(ServiceState state);
|
static String StateToString(ServiceState state);
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,10 @@ class Service : Checkable < ServiceNameComposer
|
||||||
return GetLastHardStateRaw();
|
return GetLastHardStateRaw();
|
||||||
}}}
|
}}}
|
||||||
};
|
};
|
||||||
|
[state] double last_state_ok (LastStateOK);
|
||||||
|
[state] double last_state_warning;
|
||||||
|
[state] double last_state_critical;
|
||||||
|
[state] double last_state_unknown;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue