elastalert icon indicating copy to clipboard operation
elastalert copied to clipboard

Using environment variables for rules.

Open prateekk1709 opened this issue 8 years ago • 4 comments

Hi. I am trying to implement alerting on elasticsearch using ElastAlert for some of our customers. Right now we have around 6-7 rules configured. I want to know that is it possible that we can use some environment variables or file which can directly make the changes to all the rule files (rule.yaml files) instead of going to each rule file and changing the fields there because changing each rule file every time may result in an accidental error. Can anyone help ?? Thanks in advance.

prateekk1709 avatar Feb 06 '18 05:02 prateekk1709

@prateek1709 what changes your would like to do in rule.yaml ..Can you share some example•

sathishdsgithub avatar Feb 06 '18 07:02 sathishdsgithub

I can provide an example of what would be useful for us. We run ElastAlert rules in multiple environments (i.e. Stage and Prod). We run ElastAlert inside docker. I'd like to be able to set the current environment in an environment variable and then be able to use it in the rules yaml file to set slack_webhook_url and/or alert_subject_args so we can distinguish messages coming from different environments

herbrandson avatar Aug 22 '18 00:08 herbrandson

This can be accomplished in a couple lines in Bash:

$ cat test.yaml
name: $NAME
something: $FOO
$ export NAME="test rule"
$ export FOO="bar"
$ cat test.yaml | envsubst > test2.yaml
$ cat test2.yaml
name: test rule
something: bar

Just run this against all of your rule files before you start elastalert

Qmando avatar Aug 22 '18 19:08 Qmando

This is perfect. Thanks!

herbrandson avatar Aug 23 '18 21:08 herbrandson