ansible / awx

AWX provides a web-based user interface, REST API, and task engine built on top of Ansible. It is one of the upstream projects for Red Hat Ansible Automation Platform.
Other
14.05k stars 3.42k forks source link

Integrated notifications with Microsoft Teams #885

Open ricalenil opened 6 years ago

ricalenil commented 6 years ago
ISSUE TYPE
COMPONENT NAME
SUMMARY

I'm trying to setup webhooks notifications with Microsoft Teams, but i'm getting errors. Maybe a misconfiguration, but there is no documentation about how to do it.

Maybe someone already achieved this by webhooks, but it would be great to add an option to do it like slack.

ENVIRONMENT
STEPS TO REPRODUCE

as described here: https://docs.ansible.com/ansible-tower/latest/html/userguide/notifications.html#webhook

and here: https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/connectors

EXPECTED RESULTS

Select notification type Microsoft Teams, and configure the options. Or a documentation of how to do it with webhook option.

ACTUAL RESULTS

With webhook I'm receiving this error. ERROR awx.main.notifications.webhook_backend Error sending notification webhook: Summary or Text is required.

ADDITIONAL INFORMATION
ghost commented 6 years ago

I'm encountering the same issue. It works using curl. I'm thinking it should be working in Tower as well.

falencastro commented 6 years ago

@ricalenil Had the same issue trying to post notifications to Rocket Chat using Webhook notification template type, as this posts a message like '{"body": "message"}', while Rocket Chat (and Mattermost, MS Teams) use Slack webhooks: '{"text": "message"}'.

I got around this by using Mattermost as the notification template type, should work for MS Teams too.

mpostument commented 6 years ago

@falencastro I am trying to use {"text": "message"} as http header but still getting the same error

ghost commented 6 years ago

Same here. I'm not a fan of Teams, but I imagine this is broken as an advertised feature in Tower.

falencastro commented 6 years ago

@Infectsoldier It's not a http header, it's the payload, which you can't alter. A WebHook Notification template type won't work for Mattermost/MS Teams/RocketChat or any other Slack compatible communication platform.

Try selecting Mattermost as the notification type and point it to your Teams webhook url; This should do the trick.

ricalenil commented 6 years ago

@falencastro this works!

Sent with GitHawk

mpostument commented 6 years ago

@falencastro I am using ansible tower not awx and looks like it does not have Mattermost as the notification type.

wenottingham commented 6 years ago

AWX is the upstream of Tower, so it may and will have a newer feature set at any particular point in time.

ghost commented 6 years ago

So then it is best to report this issue with Tower directly to RedHat?

Sent from mobile

On Mar 7, 2018 8:04 AM, "Bill Nottingham" notifications@github.com wrote:

AWX is the upstream of Tower, so it may and will have a newer feature set at any particular point in time.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ansible/awx/issues/885#issuecomment-371187712, or mute the thread https://github.com/notifications/unsubscribe-auth/Ad1pYdynHDi_Uv2A9TIKLiZA9IfEF4Ygks5tcAUQgaJpZM4RL_Oo .

wenottingham commented 6 years ago

As always, if you are having issues with Tower, contact your Red Hat support rep.

ricalenil commented 6 years ago

This is working with mattermost option, but it would be more clean to add a teams option. Someone of Awx here?

Sent with GitHawk

badstreff commented 6 years ago

Any traction on this? Seems like most of the code is already in place for this since the Mattermost notification type is seemingly working. Are PR's welcome and if so is there anything I need to do before cloning the project and starting work on this?

wenottingham commented 6 years ago

PRs are definitely welcome.

mebuzz commented 5 years ago

@falencastro - Worked like a charm on AWX. Thank you

songhanpoo commented 4 years ago

Hi All !

hope helpful

daniego commented 4 years ago

Also here are some useful custom message examples that would be great have in the documentation

HTTP HEADERS

{
  "content-type": "application/json"
}

Start Message Body

{   
    "@type": "MessageCard",
    "@context": "http://schema.org/extensions",
    "summary": "Job started: {{ job.name }}",
    "title": "Job started: {{ job.name }}",
    "themeColor": "FFFFFF",
    "sections": [
        {
            "title": "Details",
            "facts": [
                {
                    "name": "Start date",
                    "value": "{{ job.started }}"
                },
                {
                    "name": "Inventory",
                    "value": "{{ job.summary_fields.inventory.name }}"
                },
                {
                    "name": "Created by",
                    "value": "{{ job.summary_fields.created_by.first_name }} {{ job.summary_fields.created_by.last_name }}"
                }
            ]
        }
    ],
    "potentialAction": [
        {
            "@context": "http://schema.org",
            "@type": "ViewAction",
            "name": "View on Ansible",
            "target": [
                "{{ url }}"
            ]
        }
    ]
}

Success Message Body

{
    "@type": "MessageCard",
    "@context": "http://schema.org/extensions",
    "summary": "Job success: {{ job.name }}",
    "title": "Job success: {{ job.name }}",
    "themeColor": "008000",
    "sections": [
        {
            "title": "Details",
            "facts": [
                {
                    "name": "Start date",
                    "value": "{{ job.started }}"
                },
                {
                    "name": "End date",
                    "value": "{{ job.finished }}"
                },
                {
                    "name": "Inventory",
                    "value": "{{ job.summary_fields.inventory.name }}"
                },
                {
                    "name": "Created by",
                    "value": "{{ job.summary_fields.created_by.first_name }} {{ job.summary_fields.created_by.last_name }}"
                }
            ]
        }
    ],
    "potentialAction": [
        {
            "@context": "http://schema.org",
            "@type": "ViewAction",
            "name": "View on Ansible",
            "target": [
                "{{ url }}"
            ]
        }
    ]
}

Error Message Body

{
    "@type": "MessageCard",
    "@context": "http://schema.org/extensions",
    "summary": "Job error: {{ job.name }}",
    "title": "Job error: {{ job.name }}",
    "themeColor": "FF0000",
    "sections": [
        {
            "title": "Details",
            "facts": [
                {
                    "name": "Start date",
                    "value": "{{ job.started }}"
                },
                {
                    "name": "End date",
                    "value": "{{ job.finished }}"
                },
                {
                    "name": "Inventory",
                    "value": "{{ job.summary_fields.inventory.name }}"
                },
                {
                    "name": "Created by",
                    "value": "{{ job.summary_fields.created_by.first_name }} {{ job.summary_fields.created_by.last_name }}"
                }
            ]
        }
    ],
    "potentialAction": [
        {
            "@context": "http://schema.org",
            "@type": "ViewAction",
            "name": "View on Ansible",
            "target": [
                "{{ url }}"
            ]
        }
    ]
}
outcast commented 4 years ago

Also here are some useful custom message examples that would be great have in the documentation

Stealing this!

stuartluscombe commented 4 years ago

@daniego Is that layout something you've successfully used in AWX? If so, how?

daniego commented 4 years ago

@outcast Cheers! @stuartluscombe that's fully working and I'm using it in production. Just create a webhook notification, set TARGER URL with the one you get from Teams while creating the webhook, toggle CUSTOMIZE MESSAGES... on and paste the code above. As far as I can remember I don't think that the test message works, but the actual notification does!

danielsouzasp commented 4 years ago

In my case it only worked after changing from "Webhook" to "Mattermost" image

venu1428 commented 4 years ago

Hey @daniego the start,sucess,failure notications are working for me like you mentione above but when it comes to approval messages I am not able to get the notification to teams. Can I get any reason. I am using webhook type of notification. {"body": "The approval node \"{{ approval_node_name }}\" was approved. {{ workflow_url }}"} I am using same sample message body which was default for awx while creating awx webhook notification type. Can I get some help here. Thanks in advance.

daniego commented 4 years ago

Hi @venu1428 try something like this

{
    "@type": "MessageCard",
    "@context": "http://schema.org/extensions",
    "summary": "The approval node "{{ approval_node_name }}" was approved. {{ workflow_url }}",
    "title": "The approval node "{{ approval_node_name }}" was approved. {{ workflow_url }}",
    "themeColor": "008000"
}
venu1428 commented 4 years ago

Hi @venu1428 try something like this

{
    "@type": "MessageCard",
    "@context": "http://schema.org/extensions",
    "summary": "The approval node "{{ approval_node_name }}" was approved. {{ workflow_url }}",
    "title": "The approval node "{{ approval_node_name }}" was approved. {{ workflow_url }}",
    "themeColor": "008000"
}

Hey @daniego thank you for the responce I have tried this one it is working fine upto this.But I am unable to get the notification of action or potential action case. like when I put { "@type": "MessageCard", "@context": "https://schema.org/extensions", "summary": "Workflow approval node got Approved: {{ approval_node_name }}", "title": "Workflow approval node got Approved: {{ approval_node_name }}", "themeColor": "008000", }

this is working fine but when I will put

{ "@type": "MessageCard", "@context": "https://schema.org/extensions", "summary": "Workflow approval node got Approved: {{ approval_node_name }}", "title": "Workflow approval node got Approved: {{ approval_node_name }}", "themeColor": "008000", "potentialAction": [ { "@context": "http://schema.org", "@type": "ViewAction", "name": "View on Ansible", "target": [ "{{ workflow_url }}" ] } ] } It is not working. any suggestions.

howardjones commented 4 years ago

I'm running into issues with this too ("Error sending notification webhook: 400"). If I use the same content, headers and URL with curl, I can send a message just fine. I also can't see anywhere in the logs where I can see any error body that might be coming back from Teams.

willhaines commented 3 years ago

Thanks @daniego for the POST bodies for Teams. They are working great for us on manually triggered jobs, but we don't get any notification for scheduled jobs.

I dug into the problem and discovered that the webhook notifier sends an empty body (which causes Teams to ignore the notification all together) if any of the template fields trigger an UndefinedError.

On scheduled jobs "job.summary_fields.created_by" is undefined, so we removed the whole "Created by" section as a quick fix.

Benvandamme commented 3 years ago

I'm running into issues with this too ("Error sending notification webhook: 400"). If I use the same content, headers and URL with curl, I can send a message just fine. I also can't see anywhere in the logs where I can see any error body that might be coming back from Teams.

@howardjones Did you find a way to fix this?

Nevermind. Only the "test"-Button is broken.

MrEuds commented 5 hours ago

Also here are some useful custom message examples that would be great have in the documentation

HTTP HEADERS

{
  "content-type": "application/json"
}

...

This worked for me. Maybe this should be added to the documentation. The only improvement is that "job.summary_fields.created_by" is undefined on startup. So the "Created by" section can be removed for the "Start Message Body".