Update:
I was using a test API key in "Suppress Notifications" mode for my tests detailed below. But my production service which already uses roughly the same code with a non-"Suppress Notifications" API key could attach tags to alerts as expected. This is probably a bug on OpsGenie side.
Original post:
I'm using Python 3.7 http.client library to post alerts to this API https://docs.opsgenie.com/docs/alert-api#create-alert
def request(method, url, params, headers):
parsed = urllib.parse.urlparse(url)
conn = http.client.HTTPSConnection(parsed.netloc)
full_path = parsed.path
headers = headers or {}
body = json.dumps(params)
headers['Content-Type'] = 'application/json'
logging.info("full_path:%r body:%r headers:%r", full_path, body, headers)
conn.request(method, full_path, body, headers)
params = dict(
message='I am testing OpsGenie API',
description='describe it!',
tags=['Tag0', 'Tag1'],
details=dict(detail0='Detail0', detail1='Detail1'),
source=socket.gethostname()
)
I can see the resulting alert has message, description, and source fields as expected (as well as entity, alias, and source, when I add them)
but I can't seem to add tags and details. As if the API discards them.
The logger displays something like this
'{"message": "I am testing OpsGenie API", "description": "describe it!", "tags": ["Tag0", "Tag1"], "details": {"detail0": "Detail0", "detail1": "Detail1"}, "source": "mymachine.local"}'which looks like a valid JSON payload. Could any of you shed some light on this problem?