mirror of https://github.com/Icinga/icinga2.git
parent
2ab208e452
commit
e560e1e00c
|
@ -127,9 +127,14 @@ void CompatLogger::CheckResultHandler(const Checkable::Ptr& checkable, const Che
|
|||
<< output << ""
|
||||
<< "";
|
||||
} else {
|
||||
String state = Host::StateToString(Host::CalculateState(static_cast<ServiceState>(state_after)));
|
||||
|
||||
if (!reachable_after)
|
||||
state = "UNREACHABLE";
|
||||
|
||||
msgbuf << "HOST ALERT: "
|
||||
<< host->GetName() << ";"
|
||||
<< Host::StateToString(Host::CalculateState(static_cast<ServiceState>(state_after), host_reachable_after)) << ";"
|
||||
<< state << ";"
|
||||
<< Host::StateTypeToString(static_cast<StateType>(stateType_after)) << ";"
|
||||
<< attempt_after << ";"
|
||||
<< output << ""
|
||||
|
@ -245,7 +250,7 @@ void CompatLogger::NotificationSentHandler(const Notification::Ptr& notification
|
|||
if (service)
|
||||
notification_type_str = Service::StateToString(service->GetState());
|
||||
else
|
||||
notification_type_str = Host::StateToString(host->GetState());
|
||||
notification_type_str = host->IsReachable() ? Host::StateToString(host->GetState()) : "UNREACHABLE";
|
||||
}
|
||||
|
||||
String author_comment = "";
|
||||
|
@ -277,7 +282,7 @@ void CompatLogger::NotificationSentHandler(const Notification::Ptr& notification
|
|||
<< user->GetName() << ";"
|
||||
<< host->GetName() << ";"
|
||||
<< notification_type_str << " "
|
||||
<< "(" << Host::StateToString(host->GetState()) << ");"
|
||||
<< "(" << (host->IsReachable() ? Host::StateToString(host->GetState()) : "UNREACHABLE") << ");"
|
||||
<< command_name << ";"
|
||||
<< output << ";"
|
||||
<< author_comment
|
||||
|
@ -382,7 +387,7 @@ void CompatLogger::EventCommandHandler(const Checkable::Ptr& checkable)
|
|||
} else {
|
||||
msgbuf << "HOST EVENT HANDLER: "
|
||||
<< host->GetName() << ";"
|
||||
<< Host::StateToString(host->GetState()) << ";"
|
||||
<< (host->IsReachable() ? Host::StateToString(host->GetState()) : "UNREACHABLE") << ";"
|
||||
<< Host::StateTypeToString(host->GetStateType()) << ";"
|
||||
<< current_attempt << ";"
|
||||
<< event_command_name;
|
||||
|
@ -456,7 +461,7 @@ void CompatLogger::ReopenFile(bool rotate)
|
|||
std::ostringstream msgbuf;
|
||||
msgbuf << "CURRENT HOST STATE: "
|
||||
<< host->GetName() << ";"
|
||||
<< Host::StateToString(host->GetState()) << ";"
|
||||
<< (host->IsReachable() ? Host::StateToString(host->GetState()) : "UNREACHABLE") << ";"
|
||||
<< Host::StateTypeToString(host->GetStateType()) << ";"
|
||||
<< host->GetCheckAttempt() << ";"
|
||||
<< output << "";
|
||||
|
|
|
@ -354,7 +354,7 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl
|
|||
if (service)
|
||||
fp << "\t" << "current_state=" << service->GetState() << "\n";
|
||||
else
|
||||
fp << "\t" << "current_state=" << host->GetState() << "\n";
|
||||
fp << "\t" << "current_state=" << (host->IsReachable() ? host->GetState() : 2) << "\n";
|
||||
|
||||
fp << "\t" "state_type=" << checkable->GetStateType() << "\n"
|
||||
"\t" "plugin_output=" << CompatUtility::GetCheckResultOutput(cr) << "\n"
|
||||
|
|
|
@ -197,7 +197,7 @@ Value HostGroupsTable::NumHostsUnreachAccessor(const Value& row)
|
|||
int num_hosts = 0;
|
||||
|
||||
BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->GetMembers()) {
|
||||
if (host->GetState() == HostUnreachable)
|
||||
if (!host->IsReachable())
|
||||
num_hosts++;
|
||||
}
|
||||
|
||||
|
|
|
@ -660,7 +660,7 @@ Value HostsTable::StateAccessor(const Value& row)
|
|||
if (!host)
|
||||
return Empty;
|
||||
|
||||
return host->GetState();
|
||||
return host->IsReachable() ? host->GetState() : 2;
|
||||
}
|
||||
|
||||
Value HostsTable::StateTypeAccessor(const Value& row)
|
||||
|
|
|
@ -127,6 +127,7 @@ void GraphiteWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C
|
|||
SendMetric(prefix, "current_attempt", checkable->GetCheckAttempt());
|
||||
SendMetric(prefix, "max_check_attempts", checkable->GetMaxCheckAttempts());
|
||||
SendMetric(prefix, "state_type", checkable->GetStateType());
|
||||
SendMetric(prefix, "reachable", checkable->IsReachable());
|
||||
SendMetric(prefix, "latency", Service::CalculateLatency(cr));
|
||||
SendMetric(prefix, "execution_time", Service::CalculateExecutionTime(cr));
|
||||
SendPerfdata(prefix, cr);
|
||||
|
|
|
@ -596,7 +596,6 @@ void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const C
|
|||
long stateType_after = vars_after->Get("state_type");
|
||||
long attempt_after = vars_after->Get("attempt");
|
||||
bool reachable_after = vars_after->Get("reachable");
|
||||
bool host_reachable_after = vars_after->Get("host_reachable");
|
||||
|
||||
Dictionary::Ptr vars_before = cr->GetVarsBefore();
|
||||
|
||||
|
@ -651,9 +650,14 @@ void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const C
|
|||
return;
|
||||
}
|
||||
} else {
|
||||
String state = Host::StateToString(Host::CalculateState(static_cast<ServiceState>(state_after)));
|
||||
|
||||
if (!reachable_after)
|
||||
state = "UNREACHABLE";
|
||||
|
||||
msgbuf << "HOST ALERT: "
|
||||
<< host->GetName() << ";"
|
||||
<< Host::StateToString(Host::CalculateState(static_cast<ServiceState>(state_after), host_reachable_after)) << ";"
|
||||
<< state << ";"
|
||||
<< Service::StateTypeToString(static_cast<StateType>(stateType_after)) << ";"
|
||||
<< attempt_after << ";"
|
||||
<< output << ""
|
||||
|
@ -666,14 +670,13 @@ void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const C
|
|||
case HostDown:
|
||||
type = LogEntryTypeHostDown;
|
||||
break;
|
||||
case HostUnreachable:
|
||||
type = LogEntryTypeHostUnreachable;
|
||||
break;
|
||||
default:
|
||||
Log(LogCritical, "db_ido", "Unknown host state: " + Convert::ToString(state_after));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!reachable_after)
|
||||
type = LogEntryTypeHostUnreachable;
|
||||
}
|
||||
|
||||
AddLogHistory(checkable, msgbuf.str(), type);
|
||||
|
|
|
@ -132,7 +132,7 @@ Dictionary::Ptr HostDbObject::GetStatusFields(void) const
|
|||
fields->Set("check_source", cr->GetCheckSource());
|
||||
}
|
||||
|
||||
fields->Set("current_state", host->GetState());
|
||||
fields->Set("current_state", host->IsReachable() ? host->GetState() : 2);
|
||||
fields->Set("has_been_checked", CompatUtility::GetCheckableHasBeenChecked(host));
|
||||
fields->Set("should_be_scheduled", CompatUtility::GetCheckableShouldBeScheduled(host));
|
||||
fields->Set("current_check_attempt", host->GetCheckAttempt());
|
||||
|
|
|
@ -10,8 +10,7 @@ code {{{
|
|||
enum HostState
|
||||
{
|
||||
HostUp = 0,
|
||||
HostDown = 1,
|
||||
HostUnreachable = 2
|
||||
HostDown = 1
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -140,11 +140,12 @@ HostStatistics CIB::CalculateHostStats(void)
|
|||
BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
|
||||
ObjectLock olock(host);
|
||||
|
||||
if (host->GetState() == HostUp)
|
||||
hs.hosts_up++;
|
||||
if (host->GetState() == HostDown)
|
||||
hs.hosts_down++;
|
||||
if (host->GetState() == HostUnreachable)
|
||||
if (host->IsReachable()) {
|
||||
if (host->GetState() == HostUp)
|
||||
hs.hosts_up++;
|
||||
if (host->GetState() == HostDown)
|
||||
hs.hosts_down++;
|
||||
} else
|
||||
hs.hosts_unreachable++;
|
||||
|
||||
if (!host->GetLastCheckResult())
|
||||
|
|
|
@ -134,11 +134,8 @@ Service::Ptr Host::GetServiceByShortName(const Value& name)
|
|||
}
|
||||
}
|
||||
|
||||
HostState Host::CalculateState(ServiceState state, bool reachable)
|
||||
HostState Host::CalculateState(ServiceState state)
|
||||
{
|
||||
if (!reachable)
|
||||
return HostUnreachable;
|
||||
|
||||
switch (state) {
|
||||
case StateOK:
|
||||
case StateWarning:
|
||||
|
@ -152,49 +149,21 @@ HostState Host::GetState(void) const
|
|||
{
|
||||
ASSERT(!OwnsLock());
|
||||
|
||||
if (!IsReachable())
|
||||
return HostUnreachable;
|
||||
|
||||
switch (GetStateRaw()) {
|
||||
case StateOK:
|
||||
case StateWarning:
|
||||
return HostUp;
|
||||
default:
|
||||
return HostDown;
|
||||
}
|
||||
|
||||
return CalculateState(GetStateRaw());
|
||||
}
|
||||
|
||||
HostState Host::GetLastState(void) const
|
||||
{
|
||||
ASSERT(!OwnsLock());
|
||||
|
||||
if (!IsReachable())
|
||||
return HostUnreachable;
|
||||
|
||||
switch (GetLastStateRaw()) {
|
||||
case StateOK:
|
||||
case StateWarning:
|
||||
return HostUp;
|
||||
default:
|
||||
return HostDown;
|
||||
}
|
||||
return CalculateState(GetLastStateRaw());
|
||||
}
|
||||
|
||||
HostState Host::GetLastHardState(void) const
|
||||
{
|
||||
ASSERT(!OwnsLock());
|
||||
|
||||
if (!IsReachable())
|
||||
return HostUnreachable;
|
||||
|
||||
switch (GetLastHardStateRaw()) {
|
||||
case StateOK:
|
||||
case StateWarning:
|
||||
return HostUp;
|
||||
default:
|
||||
return HostDown;
|
||||
}
|
||||
return CalculateState(GetLastHardStateRaw());
|
||||
}
|
||||
|
||||
double Host::GetLastStateUp(void) const
|
||||
|
@ -218,12 +187,8 @@ HostState Host::StateFromString(const String& state)
|
|||
{
|
||||
if (state == "UP")
|
||||
return HostUp;
|
||||
else if (state == "DOWN")
|
||||
return HostDown;
|
||||
else if (state == "UNREACHABLE")
|
||||
return HostUnreachable;
|
||||
else
|
||||
return HostUnreachable;
|
||||
return HostDown;
|
||||
}
|
||||
|
||||
String Host::StateToString(HostState state)
|
||||
|
@ -233,8 +198,6 @@ String Host::StateToString(HostState state)
|
|||
return "UP";
|
||||
case HostDown:
|
||||
return "DOWN";
|
||||
case HostUnreachable:
|
||||
return "UNREACHABLE";
|
||||
default:
|
||||
return "INVALID";
|
||||
}
|
||||
|
@ -319,20 +282,7 @@ bool Host::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *re
|
|||
CheckResult::Ptr cr = GetLastCheckResult();
|
||||
|
||||
if (key == "state") {
|
||||
switch (GetState()) {
|
||||
case HostUnreachable:
|
||||
*result = "UNREACHABLE";
|
||||
break;
|
||||
case HostUp:
|
||||
*result = "UP";
|
||||
break;
|
||||
case HostDown:
|
||||
*result = "DOWN";
|
||||
break;
|
||||
default:
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
*result = StateToString(GetState());
|
||||
return true;
|
||||
} else if (key == "stateid") {
|
||||
*result = Convert::ToString(GetState());
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
|
||||
int GetTotalServices(void) const;
|
||||
|
||||
static HostState CalculateState(ServiceState state, bool reachable);
|
||||
static HostState CalculateState(ServiceState state);
|
||||
|
||||
HostState GetState(void) const;
|
||||
HostState GetLastState(void) const;
|
||||
|
|
|
@ -411,8 +411,7 @@ int icinga::HostStateToFilter(HostState state)
|
|||
switch (state) {
|
||||
case HostUp:
|
||||
return StateFilterUp;
|
||||
case HostDown: /* fall through */
|
||||
case HostUnreachable:
|
||||
case HostDown:
|
||||
return StateFilterDown;
|
||||
default:
|
||||
VERIFY(!"Invalid state type.");
|
||||
|
|
Loading…
Reference in New Issue