mirror of https://github.com/Icinga/icinga2.git
Move CompatUtility::GetHostStateString() logic into DB IDO and CompatLogger features
This commit is contained in:
parent
5222f7d058
commit
7a012c062a
|
@ -142,7 +142,7 @@ void CompatLogger::CheckResultHandler(const Checkable::Ptr& checkable, const Che
|
||||||
|
|
||||||
msgbuf << "HOST ALERT: "
|
msgbuf << "HOST ALERT: "
|
||||||
<< host->GetName() << ";"
|
<< host->GetName() << ";"
|
||||||
<< CompatUtility::GetHostStateString(host) << ";"
|
<< GetHostStateString(host) << ";"
|
||||||
<< Host::StateTypeToString(host->GetStateType()) << ";"
|
<< Host::StateTypeToString(host->GetStateType()) << ";"
|
||||||
<< attempt_after << ";"
|
<< attempt_after << ";"
|
||||||
<< output << ""
|
<< output << ""
|
||||||
|
@ -258,7 +258,7 @@ void CompatLogger::NotificationSentHandler(const Notification::Ptr& notification
|
||||||
if (service)
|
if (service)
|
||||||
notification_type_str = Service::StateToString(service->GetState());
|
notification_type_str = Service::StateToString(service->GetState());
|
||||||
else
|
else
|
||||||
notification_type_str = CompatUtility::GetHostStateString(host);
|
notification_type_str = GetHostStateString(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
String author_comment = "";
|
String author_comment = "";
|
||||||
|
@ -290,7 +290,7 @@ void CompatLogger::NotificationSentHandler(const Notification::Ptr& notification
|
||||||
<< user->GetName() << ";"
|
<< user->GetName() << ";"
|
||||||
<< host->GetName() << ";"
|
<< host->GetName() << ";"
|
||||||
<< notification_type_str << " "
|
<< notification_type_str << " "
|
||||||
<< "(" << CompatUtility::GetHostStateString(host) << ");"
|
<< "(" << GetHostStateString(host) << ");"
|
||||||
<< command_name << ";"
|
<< command_name << ";"
|
||||||
<< output << ";"
|
<< output << ";"
|
||||||
<< author_comment
|
<< author_comment
|
||||||
|
@ -422,7 +422,7 @@ void CompatLogger::EventCommandHandler(const Checkable::Ptr& checkable)
|
||||||
} else {
|
} else {
|
||||||
msgbuf << "HOST EVENT HANDLER: "
|
msgbuf << "HOST EVENT HANDLER: "
|
||||||
<< host->GetName() << ";"
|
<< host->GetName() << ";"
|
||||||
<< CompatUtility::GetHostStateString(host) << ";"
|
<< GetHostStateString(host) << ";"
|
||||||
<< Host::StateTypeToString(host->GetStateType()) << ";"
|
<< Host::StateTypeToString(host->GetStateType()) << ";"
|
||||||
<< current_attempt << ";"
|
<< current_attempt << ";"
|
||||||
<< event_command_name;
|
<< event_command_name;
|
||||||
|
@ -435,6 +435,14 @@ void CompatLogger::EventCommandHandler(const Checkable::Ptr& checkable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String CompatLogger::GetHostStateString(const Host::Ptr& host)
|
||||||
|
{
|
||||||
|
if (host->GetState() != HostUp && !host->IsReachable())
|
||||||
|
return "UNREACHABLE"; /* hardcoded compat state */
|
||||||
|
|
||||||
|
return Host::StateToString(host->GetState());
|
||||||
|
}
|
||||||
|
|
||||||
void CompatLogger::WriteLine(const String& line)
|
void CompatLogger::WriteLine(const String& line)
|
||||||
{
|
{
|
||||||
ASSERT(OwnsLock());
|
ASSERT(OwnsLock());
|
||||||
|
@ -499,7 +507,7 @@ void CompatLogger::ReopenFile(bool rotate)
|
||||||
std::ostringstream msgbuf;
|
std::ostringstream msgbuf;
|
||||||
msgbuf << "CURRENT HOST STATE: "
|
msgbuf << "CURRENT HOST STATE: "
|
||||||
<< host->GetName() << ";"
|
<< host->GetName() << ";"
|
||||||
<< CompatUtility::GetHostStateString(host) << ";"
|
<< GetHostStateString(host) << ";"
|
||||||
<< Host::StateTypeToString(host->GetStateType()) << ";"
|
<< Host::StateTypeToString(host->GetStateType()) << ";"
|
||||||
<< host->GetCheckAttempt() << ";"
|
<< host->GetCheckAttempt() << ";"
|
||||||
<< output << "";
|
<< output << "";
|
||||||
|
|
|
@ -62,6 +62,8 @@ private:
|
||||||
void ExternalCommandHandler(const String& command, const std::vector<String>& arguments);
|
void ExternalCommandHandler(const String& command, const std::vector<String>& arguments);
|
||||||
void EventCommandHandler(const Checkable::Ptr& service);
|
void EventCommandHandler(const Checkable::Ptr& service);
|
||||||
|
|
||||||
|
static String GetHostStateString(const Host::Ptr& host);
|
||||||
|
|
||||||
Timer::Ptr m_RotationTimer;
|
Timer::Ptr m_RotationTimer;
|
||||||
void RotationTimerHandler();
|
void RotationTimerHandler();
|
||||||
void ScheduleNextRotation();
|
void ScheduleNextRotation();
|
||||||
|
|
|
@ -1025,7 +1025,7 @@ void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const C
|
||||||
} else {
|
} else {
|
||||||
msgbuf << "HOST ALERT: "
|
msgbuf << "HOST ALERT: "
|
||||||
<< host->GetName() << ";"
|
<< host->GetName() << ";"
|
||||||
<< CompatUtility::GetHostStateString(host) << ";"
|
<< GetHostStateString(host) << ";"
|
||||||
<< Host::StateTypeToString(host->GetStateType()) << ";"
|
<< Host::StateTypeToString(host->GetStateType()) << ";"
|
||||||
<< attempt_after << ";"
|
<< attempt_after << ";"
|
||||||
<< output << ""
|
<< output << ""
|
||||||
|
@ -1522,6 +1522,14 @@ int DbEvents::GetHostState(const Host::Ptr& host)
|
||||||
return currentState;
|
return currentState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String DbEvents::GetHostStateString(const Host::Ptr& host)
|
||||||
|
{
|
||||||
|
if (host->GetState() != HostUp && !host->IsReachable())
|
||||||
|
return "UNREACHABLE"; /* hardcoded compat state */
|
||||||
|
|
||||||
|
return Host::StateToString(host->GetState());
|
||||||
|
}
|
||||||
|
|
||||||
std::pair<unsigned long, unsigned long> DbEvents::ConvertTimestamp(double time)
|
std::pair<unsigned long, unsigned long> DbEvents::ConvertTimestamp(double time)
|
||||||
{
|
{
|
||||||
unsigned long time_sec = static_cast<long>(time);
|
unsigned long time_sec = static_cast<long>(time);
|
||||||
|
|
|
@ -134,6 +134,7 @@ private:
|
||||||
static void EnableChangedHandlerInternal(const Checkable::Ptr& checkable, const String& fieldName, bool enabled);
|
static void EnableChangedHandlerInternal(const Checkable::Ptr& checkable, const String& fieldName, bool enabled);
|
||||||
|
|
||||||
static int GetHostState(const Host::Ptr& host);
|
static int GetHostState(const Host::Ptr& host);
|
||||||
|
static String GetHostStateString(const Host::Ptr& host);
|
||||||
static std::pair<unsigned long, unsigned long> ConvertTimestamp(double time);
|
static std::pair<unsigned long, unsigned long> ConvertTimestamp(double time);
|
||||||
static int MapNotificationReasonType(NotificationType type);
|
static int MapNotificationReasonType(NotificationType type);
|
||||||
static int MapExternalCommandType(const String& name);
|
static int MapExternalCommandType(const String& name);
|
||||||
|
|
|
@ -81,15 +81,6 @@ String CompatUtility::GetCommandName(const Command::Ptr& command)
|
||||||
return GetCommandNamePrefix(command) + command->GetName();
|
return GetCommandNamePrefix(command) + command->GetName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Used in StatusDataWriter and DB IDO. */
|
|
||||||
String CompatUtility::GetHostStateString(const Host::Ptr& host)
|
|
||||||
{
|
|
||||||
if (host->GetState() != HostUp && !host->IsReachable())
|
|
||||||
return "UNREACHABLE"; /* hardcoded compat state */
|
|
||||||
|
|
||||||
return Host::StateToString(host->GetState());
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Used in DB IDO, StatusDataWriter and Livestatus. */
|
/* Used in DB IDO, StatusDataWriter and Livestatus. */
|
||||||
String CompatUtility::GetCheckableCommandArgs(const Checkable::Ptr& checkable)
|
String CompatUtility::GetCheckableCommandArgs(const Checkable::Ptr& checkable)
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,9 +39,6 @@ public:
|
||||||
static String GetCommandLine(const Command::Ptr& command);
|
static String GetCommandLine(const Command::Ptr& command);
|
||||||
static String GetCommandName(const Command::Ptr& command);
|
static String GetCommandName(const Command::Ptr& command);
|
||||||
|
|
||||||
/* host */
|
|
||||||
static String GetHostStateString(const Host::Ptr& host);
|
|
||||||
|
|
||||||
/* service */
|
/* service */
|
||||||
static String GetCheckableCommandArgs(const Checkable::Ptr& checkable);
|
static String GetCheckableCommandArgs(const Checkable::Ptr& checkable);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue