From 7c0a71bc29174d1dcf632449ffe5c5ade664105a Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 26 Jun 2013 18:23:59 +0200 Subject: [PATCH] Compat: split cr output into (long_)output, log only output status.dat requires output, and long_output seperated for proper representation by guis and addons (they cannot be changed for compatibility reasons, we must change). logging an ALERT requires only the output (first line of the check result output). fixes #3882 fixes #4348 --- components/compat/compatcomponent.cpp | 14 +++++++++++++- components/compat/compatlog.cpp | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp index 3a2d2f509..e87395a42 100644 --- a/components/compat/compatcomponent.cpp +++ b/components/compat/compatcomponent.cpp @@ -336,14 +336,25 @@ void CompatComponent::DumpServiceStatusAttrs(std::ostream& fp, const Service::Pt { ASSERT(service->OwnsLock()); + String raw_output; String output; + String long_output; String perfdata; double schedule_end = -1; Dictionary::Ptr cr = service->GetLastCheckResult(); if (cr) { - output = cr->Get("output"); + raw_output = cr->Get("output"); + size_t line_end = raw_output.Find("\n"); + + output = raw_output.SubStr(0, line_end); + + if (line_end > 0 && line_end != String::NPos) { + long_output = raw_output.SubStr(line_end+1, raw_output.GetLength()); + boost::algorithm::replace_all(long_output, "\n", "\\n"); + } + boost::algorithm::replace_all(output, "\n", "\\n"); schedule_end = cr->Get("schedule_end"); @@ -387,6 +398,7 @@ void CompatComponent::DumpServiceStatusAttrs(std::ostream& fp, const Service::Pt << "\t" << "current_state=" << state << "\n" << "\t" << "state_type=" << service->GetStateType() << "\n" << "\t" << "plugin_output=" << output << "\n" + << "\t" << "long_plugin_output=" << long_output << "\n" << "\t" << "performance_data=" << perfdata << "\n" << "\t" << "last_check=" << schedule_end << "\n" << "\t" << "next_check=" << service->GetNextCheck() << "\n" diff --git a/components/compat/compatlog.cpp b/components/compat/compatlog.cpp index e7d93dc12..7d74fefe9 100644 --- a/components/compat/compatlog.cpp +++ b/components/compat/compatlog.cpp @@ -147,6 +147,18 @@ void CompatLog::CheckResultRequestHandler(const RequestMessage& request) return; /* Nothing changed, ignore this checkresult. */ } + String raw_output; + String output; + + if (cr) { + raw_output = cr->Get("output"); + size_t line_end = raw_output.Find("\n"); + + output = raw_output.SubStr(0, line_end); + + boost::algorithm::replace_all(output, "\n", "\\n"); + } + std::ostringstream msgbuf; msgbuf << "SERVICE ALERT: " << host->GetName() << ";" @@ -154,6 +166,7 @@ void CompatLog::CheckResultRequestHandler(const RequestMessage& request) << Service::StateToString(static_cast(state_after)) << ";" << Service::StateTypeToString(static_cast(stateType_after)) << ";" << attempt_after << ";" + << output << "" << ""; { @@ -168,6 +181,7 @@ void CompatLog::CheckResultRequestHandler(const RequestMessage& request) << Host::StateToString(Host::CalculateState(static_cast(state_after), host_reachable_after)) << ";" << Service::StateTypeToString(static_cast(stateType_after)) << ";" << attempt_after << ";" + << output << "" << ""; {