From 58cdce8d7ccaaefff1af9cfa7504687cfc0bcb75 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 2 Sep 2016 08:51:51 +0200 Subject: [PATCH] Improve error handling for event filters fixes #12621 --- lib/base/context.cpp | 3 +++ lib/base/debuginfo.cpp | 5 ++++- lib/remote/eventqueue.cpp | 12 +++++++++--- lib/remote/eventqueue.hpp | 4 +++- lib/remote/eventshandler.cpp | 2 +- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/base/context.cpp b/lib/base/context.cpp index efee1e5f9..921af6688 100644 --- a/lib/base/context.cpp +++ b/lib/base/context.cpp @@ -48,6 +48,9 @@ ContextTrace::ContextTrace(void) void ContextTrace::Print(std::ostream& fp) const { + if (m_Frames.empty()) + return; + fp << std::endl; int i = 0; diff --git a/lib/base/debuginfo.cpp b/lib/base/debuginfo.cpp index bc94c6b4b..ce5aa3b4d 100644 --- a/lib/base/debuginfo.cpp +++ b/lib/base/debuginfo.cpp @@ -62,7 +62,7 @@ void icinga::ShowCodeLocation(std::ostream& out, const DebugInfo& di, bool verbo if (di.Path.IsEmpty()) return; - out << "Location: " << di << "\n"; + out << "Location: " << di; std::ifstream ifs; ifs.open(di.Path.CStr(), std::ifstream::in); @@ -71,6 +71,9 @@ void icinga::ShowCodeLocation(std::ostream& out, const DebugInfo& di, bool verbo char line[1024]; while (ifs.good() && lineno <= di.LastLine + EXTRA_LINES) { + if (lineno == 0) + out << "\n"; + lineno++; ifs.getline(line, sizeof(line)); diff --git a/lib/remote/eventqueue.cpp b/lib/remote/eventqueue.cpp index 09727700b..211fe717c 100644 --- a/lib/remote/eventqueue.cpp +++ b/lib/remote/eventqueue.cpp @@ -23,8 +23,8 @@ using namespace icinga; -EventQueue::EventQueue(void) - : m_Filter(NULL) +EventQueue::EventQueue(const String& name) + : m_Name(name), m_Filter(NULL) { } EventQueue::~EventQueue(void) @@ -44,8 +44,14 @@ void EventQueue::ProcessEvent(const Dictionary::Ptr& event) ScriptFrame frame; frame.Sandboxed = true; - if (!FilterUtility::EvaluateFilter(frame, m_Filter, event, "event")) + try { + if (!FilterUtility::EvaluateFilter(frame, m_Filter, event, "event")) + return; + } catch (const std::exception& ex) { + Log(LogWarning, "EventQueue") + << "Error occurred while evaluating event filter for queue '" << m_Name << "': " << DiagnosticInformation(ex); return; + } boost::mutex::scoped_lock lock(m_Mutex); diff --git a/lib/remote/eventqueue.hpp b/lib/remote/eventqueue.hpp index b34b36c8b..3ed9d6013 100644 --- a/lib/remote/eventqueue.hpp +++ b/lib/remote/eventqueue.hpp @@ -38,7 +38,7 @@ class I2_REMOTE_API EventQueue : public Object public: DECLARE_PTR_TYPEDEFS(EventQueue); - EventQueue(void); + EventQueue(const String& name); ~EventQueue(void); bool CanProcessEvent(const String& type) const; @@ -59,6 +59,8 @@ public: static void Unregister(const String& name); private: + String m_Name; + mutable boost::mutex m_Mutex; boost::condition_variable m_CV; diff --git a/lib/remote/eventshandler.cpp b/lib/remote/eventshandler.cpp index d782a8088..7a7d87735 100644 --- a/lib/remote/eventshandler.cpp +++ b/lib/remote/eventshandler.cpp @@ -75,7 +75,7 @@ bool EventsHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request EventQueue::Ptr queue = EventQueue::GetByName(queueName); if (!queue) { - queue = new EventQueue(); + queue = new EventQueue(queueName); EventQueue::Register(queueName, queue); } -- 2.40.0