Skip to content

Commit

Permalink
Send Sentry report when error log does not match regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Siecje authored and bittner committed Nov 3, 2019
1 parent 80278e1 commit 21bb824
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sentrylogs/parsers/nginx.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def parse(self, line):
csv_list = line.split(",")

regex = re.match(self.pattern, csv_list.pop(0))
if not regex:
self.level = "fatal"
self.message = line
return
self.data["date"] = regex.group("date")
self.data["time"] = regex.group("time")
self.level = self.get_sentry_log_level(regex.group("level"))
Expand Down
19 changes: 19 additions & 0 deletions tests/test_nginx.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,22 @@ def test_regex():
n.clear_attributes()
n.parse(log)
assert message == n.message


def test_error_does_not_match_regex():
"""
Test when the regex does not match
"""
logs = (
'nginx: [emerg] open() "/etc/nginx/mime.types" failed (2: No such file or directory) in /opt/bitnami/nginx/conf/server_blocks/server-block.conf:24', # noqa: E501
)

level = "fatal"

n = Nginx()
for log in logs:
message = log
n.clear_attributes()
n.parse(log)
assert level == n.level
assert message == n.message

0 comments on commit 21bb824

Please sign in to comment.