mirror of https://github.com/Icinga/icinga2.git
parent
c953104783
commit
0a43e81306
|
@ -117,21 +117,18 @@ void CompatLogger::CheckResultHandler(const Checkable::Ptr& checkable, const Che
|
||||||
msgbuf << "SERVICE ALERT: "
|
msgbuf << "SERVICE ALERT: "
|
||||||
<< host->GetName() << ";"
|
<< host->GetName() << ";"
|
||||||
<< service->GetShortName() << ";"
|
<< service->GetShortName() << ";"
|
||||||
<< Service::StateToString(static_cast<ServiceState>(state_after)) << ";"
|
<< Service::StateToString(service->GetState()) << ";"
|
||||||
<< Service::StateTypeToString(static_cast<StateType>(stateType_after)) << ";"
|
<< Service::StateTypeToString(service->GetStateType()) << ";"
|
||||||
<< attempt_after << ";"
|
<< attempt_after << ";"
|
||||||
<< output << ""
|
<< output << ""
|
||||||
<< "";
|
<< "";
|
||||||
} else {
|
} else {
|
||||||
String state = Host::StateToString(Host::CalculateState(static_cast<ServiceState>(state_after)));
|
String state = Host::StateToString(Host::CalculateState(static_cast<ServiceState>(state_after)));
|
||||||
|
|
||||||
if (!reachable_after)
|
|
||||||
state = "UNREACHABLE";
|
|
||||||
|
|
||||||
msgbuf << "HOST ALERT: "
|
msgbuf << "HOST ALERT: "
|
||||||
<< host->GetName() << ";"
|
<< host->GetName() << ";"
|
||||||
<< state << ";"
|
<< CompatUtility::GetHostStateString(host) << ";"
|
||||||
<< Host::StateTypeToString(static_cast<StateType>(stateType_after)) << ";"
|
<< Host::StateTypeToString(host->GetStateType()) << ";"
|
||||||
<< attempt_after << ";"
|
<< attempt_after << ";"
|
||||||
<< output << ""
|
<< output << ""
|
||||||
<< "";
|
<< "";
|
||||||
|
@ -246,7 +243,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 = host->IsReachable() ? Host::StateToString(host->GetState()) : "UNREACHABLE";
|
notification_type_str = CompatUtility::GetHostStateString(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
String author_comment = "";
|
String author_comment = "";
|
||||||
|
@ -278,7 +275,7 @@ void CompatLogger::NotificationSentHandler(const Notification::Ptr& notification
|
||||||
<< user->GetName() << ";"
|
<< user->GetName() << ";"
|
||||||
<< host->GetName() << ";"
|
<< host->GetName() << ";"
|
||||||
<< notification_type_str << " "
|
<< notification_type_str << " "
|
||||||
<< "(" << (host->IsReachable() ? Host::StateToString(host->GetState()) : "UNREACHABLE") << ");"
|
<< "(" << CompatUtility::GetHostStateString(host) << ");"
|
||||||
<< command_name << ";"
|
<< command_name << ";"
|
||||||
<< output << ";"
|
<< output << ";"
|
||||||
<< author_comment
|
<< author_comment
|
||||||
|
@ -385,7 +382,7 @@ void CompatLogger::EventCommandHandler(const Checkable::Ptr& checkable)
|
||||||
} else {
|
} else {
|
||||||
msgbuf << "HOST EVENT HANDLER: "
|
msgbuf << "HOST EVENT HANDLER: "
|
||||||
<< host->GetName() << ";"
|
<< host->GetName() << ";"
|
||||||
<< (host->IsReachable() ? Host::StateToString(host->GetState()) : "UNREACHABLE") << ";"
|
<< CompatUtility::GetHostStateString(host) << ";"
|
||||||
<< Host::StateTypeToString(host->GetStateType()) << ";"
|
<< Host::StateTypeToString(host->GetStateType()) << ";"
|
||||||
<< current_attempt << ";"
|
<< current_attempt << ";"
|
||||||
<< event_command_name;
|
<< event_command_name;
|
||||||
|
@ -462,7 +459,7 @@ void CompatLogger::ReopenFile(bool rotate)
|
||||||
std::ostringstream msgbuf;
|
std::ostringstream msgbuf;
|
||||||
msgbuf << "CURRENT HOST STATE: "
|
msgbuf << "CURRENT HOST STATE: "
|
||||||
<< host->GetName() << ";"
|
<< host->GetName() << ";"
|
||||||
<< (host->IsReachable() ? Host::StateToString(host->GetState()) : "UNREACHABLE") << ";"
|
<< CompatUtility::GetHostStateString(host) << ";"
|
||||||
<< Host::StateTypeToString(host->GetStateType()) << ";"
|
<< Host::StateTypeToString(host->GetStateType()) << ";"
|
||||||
<< host->GetCheckAttempt() << ";"
|
<< host->GetCheckAttempt() << ";"
|
||||||
<< output << "";
|
<< output << "";
|
||||||
|
|
|
@ -355,7 +355,7 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl
|
||||||
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";
|
||||||
} else {
|
} else {
|
||||||
fp << "\t" << "current_state=" << (host->IsReachable() ? host->GetState() : 2) << "\n"
|
fp << "\t" << "current_state=" << CompatUtility::GetHostCurrentState(host) << "\n"
|
||||||
<< "\t" << "last_hard_state=" << host->GetLastHardState() << "\n";
|
<< "\t" << "last_hard_state=" << host->GetLastHardState() << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -992,8 +992,8 @@ void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const C
|
||||||
msgbuf << "SERVICE ALERT: "
|
msgbuf << "SERVICE ALERT: "
|
||||||
<< host->GetName() << ";"
|
<< host->GetName() << ";"
|
||||||
<< service->GetShortName() << ";"
|
<< service->GetShortName() << ";"
|
||||||
<< Service::StateToString(static_cast<ServiceState>(state_after)) << ";"
|
<< Service::StateToString(service->GetState()) << ";"
|
||||||
<< Service::StateTypeToString(static_cast<StateType>(stateType_after)) << ";"
|
<< Service::StateTypeToString(service->GetStateType()) << ";"
|
||||||
<< attempt_after << ";"
|
<< attempt_after << ";"
|
||||||
<< output << ""
|
<< output << ""
|
||||||
<< "";
|
<< "";
|
||||||
|
@ -1017,15 +1017,10 @@ void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const C
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String state = Host::StateToString(Host::CalculateState(static_cast<ServiceState>(state_after)));
|
|
||||||
|
|
||||||
if (!reachable_after)
|
|
||||||
state = "UNREACHABLE";
|
|
||||||
|
|
||||||
msgbuf << "HOST ALERT: "
|
msgbuf << "HOST ALERT: "
|
||||||
<< host->GetName() << ";"
|
<< host->GetName() << ";"
|
||||||
<< state << ";"
|
<< CompatUtility::GetHostStateString(host) << ";"
|
||||||
<< Service::StateTypeToString(static_cast<StateType>(stateType_after)) << ";"
|
<< Host::StateTypeToString(host->GetStateType()) << ";"
|
||||||
<< attempt_after << ";"
|
<< attempt_after << ";"
|
||||||
<< output << ""
|
<< output << ""
|
||||||
<< "";
|
<< "";
|
||||||
|
|
|
@ -122,7 +122,7 @@ Dictionary::Ptr HostDbObject::GetStatusFields(void) const
|
||||||
fields->Set("check_source", cr->GetCheckSource());
|
fields->Set("check_source", cr->GetCheckSource());
|
||||||
}
|
}
|
||||||
|
|
||||||
fields->Set("current_state", host->IsReachable() ? host->GetState() : 2);
|
fields->Set("current_state", CompatUtility::GetHostCurrentState(host));
|
||||||
fields->Set("has_been_checked", CompatUtility::GetCheckableHasBeenChecked(host));
|
fields->Set("has_been_checked", CompatUtility::GetCheckableHasBeenChecked(host));
|
||||||
fields->Set("should_be_scheduled", host->GetEnableActiveChecks());
|
fields->Set("should_be_scheduled", host->GetEnableActiveChecks());
|
||||||
fields->Set("current_check_attempt", host->GetCheckAttempt());
|
fields->Set("current_check_attempt", host->GetCheckAttempt());
|
||||||
|
|
|
@ -69,8 +69,8 @@ bool Checkable::IsReachable(DependencyType dt, Dependency::Ptr *failedDependency
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FOREACH(const Checkable::Ptr& service, GetParents()) {
|
BOOST_FOREACH(const Checkable::Ptr& checkable, GetParents()) {
|
||||||
if (!service->IsReachable(dt, failedDependency, rstack + 1))
|
if (!checkable->IsReachable(dt, failedDependency, rstack + 1))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,22 @@ String CompatUtility::GetCommandName(const Command::Ptr command)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* host */
|
/* host */
|
||||||
|
int CompatUtility::GetHostCurrentState(const Host::Ptr& host)
|
||||||
|
{
|
||||||
|
if (host->GetState() != HostUp && !host->IsReachable())
|
||||||
|
return 2; /* hardcoded compat state */
|
||||||
|
|
||||||
|
return host->GetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
String CompatUtility::GetHostStateString(const Host::Ptr& host)
|
||||||
|
{
|
||||||
|
if (host->GetState() != HostUp && !host->IsReachable())
|
||||||
|
return "UNREACHABLE"; /* hardcoded compat state */
|
||||||
|
|
||||||
|
return Host::StateToString(host->GetState());
|
||||||
|
}
|
||||||
|
|
||||||
String CompatUtility::GetHostAlias(const Host::Ptr& host)
|
String CompatUtility::GetHostAlias(const Host::Ptr& host)
|
||||||
{
|
{
|
||||||
if (!host->GetDisplayName().IsEmpty())
|
if (!host->GetDisplayName().IsEmpty())
|
||||||
|
|
|
@ -44,6 +44,8 @@ public:
|
||||||
static String GetCommandName(const Command::Ptr command);
|
static String GetCommandName(const Command::Ptr command);
|
||||||
|
|
||||||
/* host */
|
/* host */
|
||||||
|
static int GetHostCurrentState(const Host::Ptr& host);
|
||||||
|
static String GetHostStateString(const Host::Ptr& host);
|
||||||
static String GetHostAlias(const Host::Ptr& host);
|
static String GetHostAlias(const Host::Ptr& host);
|
||||||
static int GetHostNotifyOnDown(const Host::Ptr& host);
|
static int GetHostNotifyOnDown(const Host::Ptr& host);
|
||||||
static int GetHostNotifyOnUnreachable(const Host::Ptr& host);
|
static int GetHostNotifyOnUnreachable(const Host::Ptr& host);
|
||||||
|
|
|
@ -113,21 +113,21 @@ bool Dependency::IsAvailable(DependencyType dt) const
|
||||||
{
|
{
|
||||||
Checkable::Ptr parent = GetParent();
|
Checkable::Ptr parent = GetParent();
|
||||||
|
|
||||||
Host::Ptr host;
|
Host::Ptr parentHost;
|
||||||
Service::Ptr service;
|
Service::Ptr parentService;
|
||||||
tie(host, service) = GetHostService(parent);
|
tie(parentHost, parentService) = GetHostService(parent);
|
||||||
|
|
||||||
/* ignore if it's the same checkable object */
|
/* ignore if it's the same checkable object */
|
||||||
if (parent == GetChild()) {
|
if (parent == GetChild()) {
|
||||||
Log(LogNotice, "Dependency")
|
Log(LogNotice, "Dependency")
|
||||||
<< "Dependency '" << GetName() << "' passed: Parent and child " << (service ? "service" : "host") << " are identical.";
|
<< "Dependency '" << GetName() << "' passed: Parent and child " << (parentService ? "service" : "host") << " are identical.";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ignore pending */
|
/* ignore pending */
|
||||||
if (!parent->GetLastCheckResult()) {
|
if (!parent->GetLastCheckResult()) {
|
||||||
Log(LogNotice, "Dependency")
|
Log(LogNotice, "Dependency")
|
||||||
<< "Dependency '" << GetName() << "' passed: " << (service ? "Service" : "Host") << " '" << parent->GetName() << "' hasn't been checked yet.";
|
<< "Dependency '" << GetName() << "' passed: Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' hasn't been checked yet.";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,25 +135,25 @@ bool Dependency::IsAvailable(DependencyType dt) const
|
||||||
/* ignore soft states */
|
/* ignore soft states */
|
||||||
if (parent->GetStateType() == StateTypeSoft) {
|
if (parent->GetStateType() == StateTypeSoft) {
|
||||||
Log(LogNotice, "Dependency")
|
Log(LogNotice, "Dependency")
|
||||||
<< "Dependency '" << GetName() << "' passed: " << (service ? "Service" : "Host") << " '" << parent->GetName() << "' is in a soft state.";
|
<< "Dependency '" << GetName() << "' passed: Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' is in a soft state.";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log(LogNotice, "Dependency")
|
Log(LogNotice, "Dependency")
|
||||||
<< "Dependency '" << GetName() << "' failed: " << (service ? "Service" : "Host") << " '" << parent->GetName() << "' is in a soft state.";
|
<< "Dependency '" << GetName() << "' failed: Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' is in a soft state.";
|
||||||
}
|
}
|
||||||
|
|
||||||
int state;
|
int state;
|
||||||
|
|
||||||
if (service)
|
if (parentService)
|
||||||
state = ServiceStateToFilter(service->GetState());
|
state = ServiceStateToFilter(parentService->GetState());
|
||||||
else
|
else
|
||||||
state = HostStateToFilter(host->GetState());
|
state = HostStateToFilter(parentHost->GetState());
|
||||||
|
|
||||||
/* check state */
|
/* check state */
|
||||||
if (state & GetStateFilter()) {
|
if (state & GetStateFilter()) {
|
||||||
Log(LogNotice, "Dependency")
|
Log(LogNotice, "Dependency")
|
||||||
<< "Dependency '" << GetName() << "' passed: " << (service ? "Service" : "Host") << " '" << parent->GetName() << "' matches state filter.";
|
<< "Dependency '" << GetName() << "' passed: Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' matches state filter.";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,8 +177,8 @@ bool Dependency::IsAvailable(DependencyType dt) const
|
||||||
|
|
||||||
Log(LogNotice, "Dependency")
|
Log(LogNotice, "Dependency")
|
||||||
<< "Dependency '" << GetName() << "' failed. Parent "
|
<< "Dependency '" << GetName() << "' failed. Parent "
|
||||||
<< (service ? "service" : "host") << " '" << parent->GetName() << "' is "
|
<< (parentService ? "service" : "host") << " '" << parent->GetName() << "' is "
|
||||||
<< (service ? Service::StateToString(service->GetState()) : Host::StateToString(host->GetState()));
|
<< (parentService ? Service::StateToString(parentService->GetState()) : Host::StateToString(parentHost->GetState()));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,7 +149,7 @@ void GelfWriter::NotificationToUserHandler(const Notification::Ptr& notification
|
||||||
fields->Set("short_message", output);
|
fields->Set("short_message", output);
|
||||||
} else {
|
} else {
|
||||||
fields->Set("_type", "HOST NOTIFICATION");
|
fields->Set("_type", "HOST NOTIFICATION");
|
||||||
fields->Set("short_message", "(" + (host->IsReachable() ? Host::StateToString(host->GetState()) : String("UNREACHABLE")) + ")");
|
fields->Set("short_message", "(" + CompatUtility::GetHostStateString(host) + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
fields->Set("_state", service ? Service::StateToString(service->GetState()) : Host::StateToString(host->GetState()));
|
fields->Set("_state", service ? Service::StateToString(service->GetState()) : Host::StateToString(host->GetState()));
|
||||||
|
|
Loading…
Reference in New Issue