Coder Social home page Coder Social logo

a2-teams-notification's Introduction

Chef Automate Teams Notifications

Introduction

Greetings! This repo contains a workaround to allow Chef Automate to send failure notifications to Microsoft Teams

Components

To facilitate the notifications, this repo uses an Azure Function with an HttpTrigger to intercept the webhook from Automate, translate it into a payload for Teams, then send that new payload to the Teams webhook URL.

webhook flow

This may sound complicated, but it's really not bad at all. Automate sends a JSON payload with a lot of data in it. This is great in that we get a lot of detail, but bad because Teams expects a simple text payload. This function picks out some important bits and concatenates them into a simple text string for Teams. It also adds a link so you can go straight to the full message in Automate.

We end up with a nice message like these:

example notifications

Usage

It may feel weird, but we need to set up things starting at the destination, then working back to the origin of the notification.

Teams

The first task is to set up a channel and a webhook connector. If you want send the notifications to an existing channel, skip to the create connector steps.

  1. Create a channel by clicking the ... to the right of the team name, then select add channel create channel
  2. Next, click the ... to the right of the channel name, then select connectors
  3. Now, select Configure for the Incoming Webhook connector list of connectors
  4. Give the connector a name and provide a icon if desired, then click Create connector config screen
  5. Finally, copy the webhook URL for use in the next section. webhook url

Azure Function

In this example, I'm using azcli commands to set up the function, feel free to use other options if there's one you like better.

# create a resource group to hold the function and stuff
az group create -n my-rg-name -l centralus

# create storage account for function
az storage account create -g my-rg-name -n automatenotifications

# create the function
az functionapp create -g my-rg-name -n automate-notifications -s automatenotifications --runtime powershell --deployment-source-url https://github.com/jmassardo/a2-teams-notification.git --consumption-plan-location centralus

# create app setting for Teams Webhook URL
az functionapp config appsettings set --resource-group my-rg-name --name automate-notifications --settings teamsURL=https://outlook.office.com/webhook/xxxxxxx-xxxxxxx-xxxxxxxx-xxxxxxxxxxx

NOTE: Consider cloning/forking the GitHub repo in the 3rd step to give you better control of how code enters your environment.

Now we need to get the invoke url for the function. You can get it via the Azure Portal or use the Azure Function Core Tools.

get function url

# List the function with the invoke url
func azure functionapp list-functions automate-notifications --show-keys

# Output
Functions in automate-notifications:
    HttpTrigger - [httpTrigger]
        Invoke url: https://automate-notifications.azurewebsites.net/api/httptrigger?code=xxxxxxxxxxxxxxxxxxxxxxxxx

Automate

That wasn't too bad. Let's move onto the last bit and set up the actual notification.

  1. Log into your automate server and go to the Settings > Notifications page https://automate.example.com/settings/notifications.
  2. Select Create Notification
  3. Check the Webhooks box
  4. Give the notification a name, select the failure type, then enter the invoke url for the function and click Save Notification.

Customizing

In the highly likely event one would like to customize the notifications, the heavy lifting is done by the run.ps1 script. Lines 13-17 assemble the message for converge failures and lines 25-29 assemble the message for compliance failures.

While the example above only shows a few data points, the notification payloads contain quite a bit of information. You can see example payloads in the Automate Docs

Closing

If all went well, you should start seeing notifications within a few minutes (give or take, depending on your client interval/splay).

Hopefully, you find this to be useful. If you have any questions or feedback, please feel free to contact me: @jamesmassardo.

a2-teams-notification's People

Contributors

jmassardo avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.