Skip to content

Commit

Permalink
Improve error handling for event filters
Browse files Browse the repository at this point in the history
fixes #12621
  • Loading branch information
gunnarbeutner committed Sep 2, 2016
1 parent b92a139 commit 58cdce8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
3 changes: 3 additions & 0 deletions lib/base/context.cpp
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion lib/base/debuginfo.cpp
Expand Up @@ -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);
Expand All @@ -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));
Expand Down
12 changes: 9 additions & 3 deletions lib/remote/eventqueue.cpp
Expand Up @@ -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)
Expand All @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion lib/remote/eventqueue.hpp
Expand Up @@ -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;
Expand All @@ -59,6 +59,8 @@ class I2_REMOTE_API EventQueue : public Object
static void Unregister(const String& name);

private:
String m_Name;

mutable boost::mutex m_Mutex;
boost::condition_variable m_CV;

Expand Down
2 changes: 1 addition & 1 deletion lib/remote/eventshandler.cpp
Expand Up @@ -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);
}

Expand Down

0 comments on commit 58cdce8

Please sign in to comment.