[icinga-checkins] icinga.org: icinga2/master: Service::CheckCompletedHandler: Convert exceptions to fake check results.

git at icinga.org git at icinga.org
Sun Feb 3 16:32:42 CET 2013


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

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Sun Feb  3 16:32:31 2013 +0100

Service::CheckCompletedHandler: Convert exceptions to fake check results.

---

 lib/icinga/service.cpp |   47 ++++++++++++++++++++++++++++-------------------
 1 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp
index b1aab63..1f4c327 100644
--- a/lib/icinga/service.cpp
+++ b/lib/icinga/service.cpp
@@ -697,34 +697,43 @@ void Service::CheckCompletedHandler(const Dictionary::Ptr& scheduleInfo,
 	scheduleInfo->Set("execution_end", Utility::GetTime());
 	scheduleInfo->Set("schedule_end", Utility::GetTime());
 
+	Dictionary::Ptr result;
+
 	try {
 		Value vresult = task->GetResult();
 
-		if (vresult.IsObjectType<Dictionary>()) {
-			Dictionary::Ptr result = vresult;
+		if (vresult.IsObjectType<Dictionary>())
+			result = vresult;
+	} catch (const exception& ex) {
+		stringstream msgbuf;
+		msgbuf << "Exception occured during check for service '"
+		       << GetName() << "': " << ex.what();
+		String message = msgbuf.str();
 
-			if (!result->Contains("schedule_start"))
-				result->Set("schedule_start", scheduleInfo->Get("schedule_start"));
+		Logger::Write(LogWarning, "checker", message);
 
-			if (!result->Contains("schedule_end"))
-				result->Set("schedule_end", scheduleInfo->Get("schedule_end"));
+		result = boost::make_shared<Dictionary>();
+		result->Set("state", StateUnknown);
+		result->Set("output", message);
+	}
 
-			if (!result->Contains("execution_start"))
-				result->Set("execution_start", scheduleInfo->Get("execution_start"));
+	if (result) {
+		if (!result->Contains("schedule_start"))
+			result->Set("schedule_start", scheduleInfo->Get("schedule_start"));
 
-			if (!result->Contains("execution_end"))
-				result->Set("execution_end", scheduleInfo->Get("execution_end"));
+		if (!result->Contains("schedule_end"))
+			result->Set("schedule_end", scheduleInfo->Get("schedule_end"));
 
-			if (!result->Contains("active"))
-				result->Set("active", 1);
+		if (!result->Contains("execution_start"))
+			result->Set("execution_start", scheduleInfo->Get("execution_start"));
 
-			ProcessCheckResult(result);
-		}
-	} catch (const exception& ex) {
-		stringstream msgbuf;
-		msgbuf << "Exception occured during check for service '"
-		       << GetName() << "': " << ex.what();
-		Logger::Write(LogWarning, "checker", msgbuf.str());
+		if (!result->Contains("execution_end"))
+			result->Set("execution_end", scheduleInfo->Get("execution_end"));
+
+		if (!result->Contains("active"))
+			result->Set("active", 1);
+
+		ProcessCheckResult(result);
 	}
 
 	/* figure out when the next check is for this service; the call to





More information about the icinga-checkins mailing list