Skip to content

Commit

Permalink
X env staging header addition (#33)
Browse files Browse the repository at this point in the history
* Adding local datastore setup files

* Added header X-Env to router requests if configured

* Added header X-Env to router requests if configured

* Changed X_ENV env variable name to X-ENV

* Revert "Changed X_ENV env variable name to X-ENV"

This reverts commit be627e7.
  • Loading branch information
ajaywk7 committed Aug 6, 2024
1 parent a8b62c7 commit 717880e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion elastalert/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion elastalert/elastalert.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,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:
Expand Down
7 changes: 6 additions & 1 deletion elastalert/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = ''
Expand All @@ -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']

Expand Down

0 comments on commit 717880e

Please sign in to comment.