[icinga-checkins] icinga.org: icinga2/master: Compat: split cr output into (long_)output, log only output

git at icinga.org git at icinga.org
Wed Jun 26 18:27:22 CEST 2013


Module: icinga2
Branch: master
Commit: 7c0a71bc29174d1dcf632449ffe5c5ade664105a
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=7c0a71bc29174d1dcf632449ffe5c5ade664105a

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Wed Jun 26 18:23:59 2013 +0200

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 deletions(-)

diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp
index 3a2d2f5..e87395a 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 e7d93dc..7d74fef 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<ServiceState>(state_after)) << ";"
 	       << Service::StateTypeToString(static_cast<StateType>(stateType_after)) << ";"
 	       << attempt_after << ";"
+	       << output << ""
 	       << "";
 
 	{
@@ -168,6 +181,7 @@ void CompatLog::CheckResultRequestHandler(const RequestMessage& request)
 		       << Host::StateToString(Host::CalculateState(static_cast<ServiceState>(state_after), host_reachable_after)) << ";"
 		       << Service::StateTypeToString(static_cast<StateType>(stateType_after)) << ";"
 		       << attempt_after << ";"
+		       << output << ""
 		       << "";
 
 		{





More information about the icinga-checkins mailing list