Webhook notification setup

Hello Team,

I’m looking for some guidance on setting up webhook notification in AWX. Haven’t found any relevant documentation or examples online.

My requirement is to create an incident when a job is failed in AWX, there are two mandatory fields required by the incident creation API ie; short_description & assignment_group.

I tried passing this info as variables via http headers but gets an error (code 417). Also, dictionary is not allowed under http headers.

I did not find any other way to pass this info to the API, has anyone figured this out ?

Any help is much appreciated.

AWX Version: 21.5.0 hosted on K8s Cluster.

Regards,
Vibin

Hello Team,

Any input is highly appreciated.

Regards,
Vibin

Can you clarify what you are attempting to do?
Are you using a web hook notification template inside AWX and trying to send an HTTP request to an incident management system on job failure?
If so, here is the documentation around doing that: https://docs.ansible.com/automation-controller/latest/html/userguide/webhooks.html#payload-output

-The AWX Team

Hello Team,

Thanks for the response.

Yes, you are spot on. So if I understand correctly, I should be able to send the payload using awx_webhook_payload variable. But where should I declare that variable ? Because in the webhook notification template, there’s only option to mention HTTP HEADERS.

I tried passing variables like below in the HTTP HEADERS section but it didn’t allow dictionary type input.

{
extra_vars: {
description: test,
group: abc
}
}

Does replacing extra_vars with awx_webhook_payload in the above declaration work ?

Or did I get it completely wrong ?

Regards,
Vibin

Hi Team,

I tried multiple ways but couldn’t figure out how to send payload to the webhook endpoint.

Those which doesn’t need any input works fine.

Please provide your comments.

Regards,
Vibin

Hello Team,

I was unable to find the awx_webhook_payload under extra_vars of the job template as mentioned in the url.

I tried passing it manually using variables section of the job template but nothing worked.

Appreciate if you could point me in the right direction.

Regards,
Vibin

Hello. Watch this video for webhook variables understanding
https://youtu.be/LVbFyjgwvQY

You have to enable notification for your template with webhook

For enabling mail notification watch this video:
https://youtu.be/tVoPkYfFgS4

пт, 12 мая 2023 г. в 09:45, Vibin K Madampath <mm.vibin@gmail.com>:

Hello Team,

I’m not looking for AWX integration with Github webhook.

Just to be very clear, am trying to create a notification template of type Webhook. I need to send couple of inputs to the target URL but unable to do so. Looking for some guidance on how to accomplish this.

Please see the screenshot below and advise.

(attachments)


do you see any errors or messages related to that target URL in your k8s logs (either on task container or web containers)?

AWX Team

Yes, please see the messages pasted below.

“POST /api/v2/notification_templates/9/test/ HTTP/1.1” 202 598 “https://awx.abc.com/” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36”

POST /api/v2/notification_templates/9/test/ => generated 598 bytes in 207 msecs (HTTP/1.1 202) 15 headers in 620 bytes (1 switches on core 0)

DEBUG [5ba28775cf584172af70e6901e00fb39] awx.analytics.performance request: <WSGIRequest: GET ‘/api/v2/notifications/3873/’>, response_time: 0.219s

“GET /api/v2/notifications/3873/ HTTP/1.1” 200 852 “https://awx.abc.com/” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36”

GET /api/v2/notifications/3873/ => generated 852 bytes in 222 msecs (HTTP/1.1 200) 14 headers in 580 bytes (1 switches on core 0)

{
“id”: 3873,
“type”: “notification”,
“url”: “/api/v2/notifications/3873/”,
“related”: {
“notification_template”: “/api/v2/notification_templates/9/”
},
“summary_fields”: {
“notification_template”: {
“id”: 9,
“name”: “test”,
“description”: “”
}
},
“created”: “2023-05-25T08:32:25.014485Z”,
“modified”: “2023-05-25T08:32:25.014505Z”,
“notification_template”: 9,
“error”: “Header part ({‘short_description’: ‘Test Incident’, ‘assignment_group’: ‘A106’}) from {‘extra_vars’: {‘short_description’: ‘Test Incident’, ‘assignment_group’: ‘A106’}} must be of type str or bytes, not <class ‘dict’>”,
“status”: “failed”,
“notifications_sent”: 0,
“notification_type”: “webhook”,
“recipients”: “https://servicenow-API.abc.com/api/dabas/incident_api/create/incident”,
“body”: {
“body”: “Test Notification 9 https://awx.abc.com/
}
}

Regards,
Vibin

The error you are getting (must be of type str or bytes not <class ‘dict’>) is because that setting expects a dictionary of string: string. i.e.
{
“header1”: “value1”,
“header2”: “value2”
}

But you have:
{
“extra_vars”: {…}
}

So you are attempting to set the extra_vars header as a dict, not a string.
You may want to do something like:
{
“short_description”: “Test Incident”,
“assignment_group”: “A106”
}

That should give you two headers set to two different values. If you really need to merge the values into a single header, you will need to look at the docs for what you are calling into and see how they allow for that.

-The AWX Team

Hi,

This is the way I call the API directly and it works - curl -k -u svcaccount -X POST -H “Content-Type: application/json” https://servicenow-API.abc.com/api/dabas/incident_api/create/incident -d ‘{ “short_description”: “Test Incident”, “assignment_group”: “A106” }’

But when I pass it as two headers set to two different values also, it doesn’t take and throws error 417 which means the API didn’t get the payload what it was looking for.

So the question is how should we pass this payload in a way that the target API understands it correctly.

{

“short_description”: “Test Incident”,
“assignment_group”: “A106”
}

Error:

{
“id”: 4006,
“type”: “notification”,
“url”: “/api/v2/notifications/4006/”,
“related”: {
“notification_template”: “/api/v2/notification_templates/9/”
},
“summary_fields”: {
“notification_template”: {
“id”: 9,
“name”: “test”,
“description”: “”
}
},
“created”: “2023-05-29T07:14:35.629791Z”,
“modified”: “2023-05-29T07:14:35.629806Z”,
“notification_template”: 9,
“error”: “Error sending webhook notification: 417”,
“status”: “failed”,
“notifications_sent”: 0,
“notification_type”: “webhook”,
“recipients”: “https://servicenow-API.abc.com/api/dabas/incident_api/create/incident”,
“body”: {
“body”: “Test Notification 9 https://awx.abc.com/
}
}

Regards,
Vibin

Hello Team,

Any further inputs is much appreciated.

Regards,
Vibin

Hi Team,

Did you get a chance to check on this?

Just wondering whether this is a bug, because the feature is neither working as expected nor any clear documentation is available.

Would you like me to raise this as a bug.

Regards,
Vibin

From your curl command posted:
curl -k -u svcaccount -X POST -H “Content-Type: application/json” https://servicenow-API.abc.com/api/dabas/incident_api/create/incident -d ‘{ “short_description”: “Test Incident”, “assignment_group”: “A106” }’

The -d is not a header, its a data sent via the HTTP POST body. Please look at the previously supplied documentation to see if there is a way to send post data with a webhook notification.

-The AWX Team.

Hi,

The mentioned documentation talks about the integration of github webhook with AWX and nothing about the webhook type notification template. Also, there is no field/option to send the data/payload to the webhook url in the GUI.

AFAIK, with the current setup there is no possibility to send data/payload to the webhook type notification url and this should be a feature to get added in future releases. Also, more meaningful error messages will be helpful.

Regards,
Vibin