Move CompatUtility::GetHostCurrentState() logic into DB IDO and StatusData features

This commit is contained in:
Michael Friedrich 2017-12-21 09:12:12 +01:00
parent 48516560bc
commit 915d0417c9
6 changed files with 28 additions and 17 deletions

View File

@ -365,7 +365,12 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl
"\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"
int currentState = host->GetState();
if (currentState != HostUp && !host->IsReachable())
currentState = 2; /* hardcoded compat state */
fp << "\t" "current_state=" << currentState << "\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";

View File

@ -761,7 +761,7 @@ void DbEvents::AddAcknowledgementHistory(const Checkable::Ptr& checkable, const
if (service) {
fields1->Set("state", service->GetState());
} else {
fields1->Set("state", CompatUtility::GetHostCurrentState(host));
fields1->Set("state", GetHostState(host));
}
String node = IcingaApplication::GetInstance()->GetNodeName();
@ -855,7 +855,7 @@ void DbEvents::AddNotificationHistory(const Notification::Ptr& notification, con
if (service) {
fields1->Set("state", service->GetState());
} else {
fields1->Set("state", CompatUtility::GetHostCurrentState(host));
fields1->Set("state", GetHostState(host));
}
if (cr) {
@ -936,7 +936,7 @@ void DbEvents::AddStateChangeHistory(const Checkable::Ptr& checkable, const Chec
fields1->Set("last_state", service->GetLastState());
fields1->Set("last_hard_state", service->GetLastHardState());
} else {
fields1->Set("state", CompatUtility::GetHostCurrentState(host));
fields1->Set("state", GetHostState(host));
fields1->Set("last_state", host->GetLastState());
fields1->Set("last_hard_state", host->GetLastHardState());
}
@ -1421,7 +1421,7 @@ void DbEvents::AddCheckableCheckHistory(const Checkable::Ptr& checkable, const C
fields1->Set("state", service->GetState());
} else {
fields1->Set("host_object_id", host);
fields1->Set("state", CompatUtility::GetHostCurrentState(host));
fields1->Set("state", GetHostState(host));
}
String node = IcingaApplication::GetInstance()->GetNodeName();
@ -1459,7 +1459,7 @@ void DbEvents::AddEventHandlerHistory(const Checkable::Ptr& checkable)
fields1->Set("state", service->GetState());
fields1->Set("eventhandler_type", 1);
} else {
fields1->Set("state", CompatUtility::GetHostCurrentState(host));
fields1->Set("state", GetHostState(host));
fields1->Set("eventhandler_type", 0);
}
@ -1512,6 +1512,16 @@ void DbEvents::AddExternalCommandHistory(double time, const String& command, con
DbObject::OnQuery(query1);
}
int DbEvents::GetHostState(const Host::Ptr& host)
{
int currentState = host->GetState();
if (currentState != HostUp && !host->IsReachable())
currentState = 2; /* hardcoded compat state */
return currentState;
}
std::pair<unsigned long, unsigned long> DbEvents::ConvertTimestamp(double time)
{
unsigned long time_sec = static_cast<long>(time);

View File

@ -133,6 +133,7 @@ private:
static void RemoveDowntimeInternal(std::vector<DbQuery>& queries, const Downtime::Ptr& downtime);
static void EnableChangedHandlerInternal(const Checkable::Ptr& checkable, const String& fieldName, bool enabled);
static int GetHostState(const Host::Ptr& host);
static std::pair<unsigned long, unsigned long> ConvertTimestamp(double time);
static int MapNotificationReasonType(NotificationType type);
static int MapExternalCommandType(const String& name);

View File

@ -137,7 +137,12 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const
fields->Set("check_source", cr->GetCheckSource());
}
fields->Set("current_state", CompatUtility::GetHostCurrentState(host));
int currentState = host->GetState();
if (currentState != HostUp && !host->IsReachable())
currentState = 2; /* hardcoded compat state */
fields->Set("current_state", currentState);
fields->Set("has_been_checked", host->HasBeenChecked());
fields->Set("should_be_scheduled", host->GetEnableActiveChecks());
fields->Set("current_check_attempt", host->GetCheckAttempt());

View File

@ -81,15 +81,6 @@ String CompatUtility::GetCommandName(const Command::Ptr& command)
return GetCommandNamePrefix(command) + command->GetName();
}
/* Used in StatusDataWriter and DB IDO. */
int CompatUtility::GetHostCurrentState(const Host::Ptr& host)
{
if (host->GetState() != HostUp && !host->IsReachable())
return 2; /* hardcoded compat state */
return host->GetState();
}
/* Used in StatusDataWriter and DB IDO. */
String CompatUtility::GetHostStateString(const Host::Ptr& host)
{

View File

@ -40,7 +40,6 @@ public:
static String GetCommandName(const Command::Ptr& command);
/* host */
static int GetHostCurrentState(const Host::Ptr& host);
static String GetHostStateString(const Host::Ptr& host);
/* service */