Skip to content

Commit

Permalink
Merge pull request #2484 from Yelp/fix_rule_disable
Browse files Browse the repository at this point in the history
Stop job when it gets disabled
  • Loading branch information
Qmando authored Sep 23, 2019
2 parents c3ac34a 3c0aa03 commit fbb9697
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 8 additions & 2 deletions elastalert/elastalert.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 23,8 @@
from croniter import croniter
from elasticsearch.exceptions import ConnectionError
from elasticsearch.exceptions import ElasticsearchException
from elasticsearch.exceptions import TransportError
from elasticsearch.exceptions import NotFoundError
from elasticsearch.exceptions import TransportError

from . import kibana
from .alerts import DebugAlerter
Expand Down Expand Up @@ -1067,7 1067,13 @@ def load_rule_changes(self):
if rule_file not in new_rule_hashes:
# Rule file was deleted
elastalert_logger.info('Rule file %s not found, stopping rule execution' % (rule_file))
self.rules = [rule for rule in self.rules if rule['rule_file'] != rule_file]
for rule in self.rules:
if rule['rule_file'] == rule_file:
break
else:
continue
self.scheduler.remove_job(job_id=rule['name'])
self.rules.remove(rule)
continue
if hash_value != new_rule_hashes[rule_file]:
# Rule file was changed, reload rule
Expand Down
9 changes: 9 additions & 0 deletions tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 1049,15 @@ def test_rule_changes(ea):
ea.load_rule_changes()
assert len(ea.rules) == 4

# Disable a rule by removing the file
new_hashes.pop('rules/rule4.yaml')
with mock.patch.object(ea.conf['rules_loader'], 'get_hashes') as mock_hashes:
with mock.patch.object(ea.conf['rules_loader'], 'load_configuration') as mock_load:
mock_load.return_value = {'filter': [], 'name': 'rule4', 'new': 'stuff', 'rule_file': 'rules/rule4.yaml'}
mock_hashes.return_value = new_hashes
ea.load_rule_changes()
ea.scheduler.remove_job.assert_called_with(job_id='rule4')


def test_strf_index(ea):
""" Test that the get_index function properly generates indexes spanning days """
Expand Down

0 comments on commit fbb9697

Please sign in to comment.