Improve error handling for event filters

fixes #12621
This commit is contained in:
Gunnar Beutner 2016-09-02 08:51:51 +02:00
parent b92a139a4c
commit 58cdce8d7c
5 changed files with 20 additions and 6 deletions

View File

@ -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;

View File

@ -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));

View File

@ -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;
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);

View File

@ -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;

View File

@ -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);
}