xMatters to MS Teams alert using Python.

Here is some code I used to create an alert to send the number of people in xMatters to MS Teams so I could track the number of people created. We have an automated task that creates user and I need to track it to make sure we don’t have any spikes. I created the xMatters call using Postman and then selected the code option and chose Python. This is great for getting it working and also hashing the authorization data.

#!/usr/bin/env python3

import requests
import json
url = "https://yourAccount.xmatters.com/api/xm/1/people/"

payload = {}
headers = {
    'Authorization': 'Basic your authorization from Xmatters'
}

response = requests.request("GET", url, headers=headers, data=payload)
data = response.json()
print("Count: " + str(data["count"]))
print("Total: " + str(data["total"]))

teamsURL = "Your teams web hook url"

# "Count": str(data["count"]),
# "Total": str(data["total"])

teamsPayload = {
    "text": "Count:" + str(data["count"]) + '  ' + "Total:" + str(data["total"])

}
headers = {
    'Content-Type': 'application/json'
}

teamsResponse = requests.post(teamsURL, headers=headers,
                              data=json.dumps(teamsPayload))
//print(teamsResponse.text.encode('utf8'))

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.