Skip to content

Commit

Permalink
run_test.py: Support to inject Python code, useful for deployment
Browse files Browse the repository at this point in the history
Needed for: elastic/elasticsearch#30112 (comment)

> I already have a workaround in place for this which consists of automatically deploying as many watches as I need to send different mails. Those watches are derived from my watch definition. For this, I extended [run_test.py](https://github.com/elastic/examples/blob/master/Alerting/Sample%20Watches/run_test.py) to inject Python code after the watch definition is read. Not ideal, but it is maintainable.
  • Loading branch information
ypid-geberit committed Sep 25, 2018
1 parent fcc5d2f commit f6f6689
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Alerting/Sample Watches/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def load_file(serialized_file):
parser.add_argument('--protocol', help='protocol')
parser.add_argument('--test_file', help='test file')
parser.add_argument('--keep-index', help='Keep the index where test documents have been loaded to after the test', action='store_true')
parser.add_argument('--modify-watch-by-eval', help='Python code to modify the watch before loading it into Elastic')
parser.add_argument(
'--no-execute-watch',
help='Do not force watch execution. This can be useful when you use this script to deploy the watch.',
Expand Down Expand Up @@ -79,6 +80,10 @@ def load_file(serialized_file):

# Load Watch and Execute
watch = load_file(test['watch_file'])

if args.modify_watch_by_eval:
eval(compile(args.modify_watch_by_eval, '<string>', 'exec'))

watcher = XPackClient(es).watcher
watcher.put_watch(id=test["watch_name"], body=watch)

Expand Down

0 comments on commit f6f6689

Please sign in to comment.