Skip to content
This repository has been archived by the owner on Apr 22, 2020. It is now read-only.

add exception class and line number #310

Merged
merged 2 commits into from
Jan 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tests/test_main_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ def test_evaluate_alert(monkeypatch):
# produce exception
alert_def['condition'] = 'value["missing-key"] > 0'
is_alert, captures = task.evaluate_alert(alert_def, req, result)
assert {'p1': 'x', 'exception': "'int' object has no attribute '__getitem__'"} == captures
assert 'p1' in captures and captures.get('p1') == 'x'
assert 'exception' in captures and "'int' object has no attribute '__getitem__'" in captures.get('exception')
assert is_alert


Expand Down
2 changes: 1 addition & 1 deletion tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def exc(*args, **kwargs):

def test_check_failure(tmpdir, monkeypatch):
execute_check(tmpdir, monkeypatch, 'invalid_python_code',
['"value": "name \'invalid_python_code\' is not defined"', '"exc": 1'])
['"value": "Traceback (most recent', 'name \'invalid_python_code\' is not defined', '"exc": 1'])


def test_check_success(tmpdir, monkeypatch):
Expand Down
7 changes: 6 additions & 1 deletion zmon_worker_monitor/zmon_worker/tasks/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import setproctitle
import socket
import sys
import traceback
import time
import urllib
from urllib3.util import parse_url
Expand Down Expand Up @@ -1201,6 +1202,10 @@ def _get_check_result_internal(self, req):

except (SyntaxError, InvalidEvalExpression), e:
raise CheckError(str(e))
except (SecurityError, InsufficientPermissionsError), e:
raise(e)
except Exception, e:
raise Exception(traceback.format_exc())

def _get_check_result(self, req):
r = self._get_check_result_internal(req)
Expand Down Expand Up @@ -1379,7 +1384,7 @@ def evaluate_alert(self, alert_def, req, result):
captures,
alert_parameters))
except Exception, e:
captures['exception'] = str(e)
captures['exception'] = traceback.format_exc()
result = True

try:
Expand Down