WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
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
17 changes: 14 additions & 3 deletions elastalert/elastalert.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ def __init__(self, args):

remove = []
for rule in self.rules:
if not self.init_rule(rule):
if 'is_enabled' in rule and not rule['is_enabled']:
self.disabled_rules.append(rule)
remove.append(rule)
elif not self.init_rule(rule):
remove.append(rule)
list(map(self.rules.remove, remove))

Expand Down Expand Up @@ -968,7 +971,7 @@ def run_rule(self, rule, endtime, starttime=None):

def init_rule(self, new_rule, new=True):
''' Copies some necessary non-config state from an exiting rule to a new rule. '''
if not new:
if not new and self.scheduler.get_job(job_id=new_rule['name']):
self.scheduler.remove_job(job_id=new_rule['name'])

try:
Expand Down Expand Up @@ -1088,6 +1091,15 @@ def load_rule_changes(self):
elastalert_logger.info('Rule file %s is now disabled.' % (rule_file))
# Remove this rule if it's been disabled
self.rules = [rule for rule in self.rules if rule['rule_file'] != rule_file]
# Stop job if is running
if self.scheduler.get_job(job_id=new_rule['name']):
self.scheduler.remove_job(job_id=new_rule['name'])
# Append to disabled_rule
for disabled_rule in self.disabled_rules:
if disabled_rule['name'] == new_rule['name']:
break
else:
self.disabled_rules.append(new_rule)
continue
except EAException as e:
message = 'Could not load rule %s: %s' % (rule_file, e)
Expand All @@ -1106,7 +1118,6 @@ def load_rule_changes(self):
# Re-enable if rule had been disabled
for disabled_rule in self.disabled_rules:
if disabled_rule['name'] == new_rule['name']:
self.rules.append(disabled_rule)
self.disabled_rules.remove(disabled_rule)
break

Expand Down
3 changes: 0 additions & 3 deletions elastalert/loaders.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ def load(self, conf, args=None):
if not rule:
logging.error('Invalid rule file skipped: %s' % rule_file)
continue
# By setting "is_enabled: False" in rule file, a rule is easily disabled
if 'is_enabled' in rule and not rule['is_enabled']:
continue
if rule['name'] in names:
raise EAException('Duplicate rule named %s' % (rule['name']))
except EAException as e:
Expand Down