Skip to content

Alert clear #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
26 changes: 18 additions & 8 deletions modules/syslog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
class SyslogCheckerRule(RuleType):
required_options = set(['regex_file'])

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.regex_rules = self.load_regex_rules()

def load_regex_rules(self):
rules = None
try:
Expand All @@ -23,15 +27,11 @@ def to_localtz(self, ts):
return ts.astimezone(tz.tzlocal())

def add_data(self, data):
regex_rules = self.load_regex_rules()
if not regex_rules:
return
# check if any of the datapoints match any of the defined regexs
matched = []
for point in data:
if 'syslog_message' not in point or 'syslog_severity' not in point or 'syslog_hostname' not in point:
continue
for rule in regex_rules:
for rule in self.regex_rules:
r = re.compile(rule['regex'])
m = r.match(point['syslog_message'])
if not m:
Expand All @@ -53,6 +53,16 @@ def add_data(self, data):
point['syslog_hostname'],
point['entity']
)
if match not in matched:
self.add_match(point)
matched.append(match)
if point['status'] == 'recover':
# dont alert on points that alert and clear in the same cycle
cleared = False
for pt in self.matches:
m = '{}:{}:{}'.format(pt['name'], pt['syslog_hostname'], pt['entity'])
if m == match and pt['status'] == 'alerting':
elastalert_logger.info('{} has recovered, removing'.format(m))
self.matches.remove(pt)
cleared = True
if cleared:
continue
elastalert_logger.info('{} on {}'.format(point['status'], match))
self.add_match(point)