diff --git a/elastalert/config.py b/elastalert/config.py index 7e841799a..9cc2618bc 100644 --- a/elastalert/config.py +++ b/elastalert/config.py @@ -25,7 +25,8 @@ 'ES_PORT': 'es_port', 'ES_URL_PREFIX': 'es_url_prefix', 'STATSD_INSTANCE_TAG': 'statsd_instance_tag', - 'STATSD_HOST': 'statsd_host'} + 'STATSD_HOST': 'statsd_host', + 'X_ENV':'X_ENV'} env = Env(ES_USE_SSL=bool) diff --git a/elastalert/elastalert.py b/elastalert/elastalert.py index 1207cc198..5cf6c6210 100755 --- a/elastalert/elastalert.py +++ b/elastalert/elastalert.py @@ -704,7 +704,10 @@ def get_ch_data(self, rule, starttime, endtime, agg_key, freshquery,aggregation) "aggregations":[aggregation] } try: - res = requests.post(self.query_endpoint, json=data) + headers = {} + if 'X_ENV' in rule: + headers['X-ENV'] = rule['X_ENV'] + res = requests.post(self.query_endpoint, json=data, headers=headers) res.raise_for_status() except requests.exceptions.RequestException as e: if len(str(e)) > 1024: diff --git a/elastalert/util.py b/elastalert/util.py index 10cf76519..dedb8b42a 100644 --- a/elastalert/util.py +++ b/elastalert/util.py @@ -395,7 +395,7 @@ def build_adapter_conn_config(conf): parsed_conf['es_bearer'] = None parsed_conf['aws_region'] = None parsed_conf['profile'] = None - parsed_conf['headers'] = None + parsed_conf['headers'] = {} parsed_conf['es_host'] = conf['kibana_adapter'] parsed_conf['es_port'] = conf['kibana_adapter_port'] parsed_conf['es_url_prefix'] = '' @@ -420,6 +420,11 @@ def build_adapter_conn_config(conf): elif 'es_bearer' in conf: parsed_conf['es_bearer'] = conf['es_bearer'] + if os.environ.get('X_ENV'): + parsed_conf['headers']['X-ENV'] = os.environ.get('X_ENV') + elif 'X_ENV' in conf: + parsed_conf['headers']['X-ENV'] = os.environ.get('X_ENV') + if 'aws_region' in conf: parsed_conf['aws_region'] = conf['aws_region']