Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X env staging header addition #33

Merged
merged 7 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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 = {}
ajaywk7 marked this conversation as resolved.
Show resolved Hide resolved
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')
ajaywk7 marked this conversation as resolved.
Show resolved Hide resolved
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