Automated messages to Microsoft teams with Python.

url = "https://<Your webhook URL>"

IssueType="CPU USAGE"
Severity=1
ServerName="SERVER-007"
SevImage={
1: "https://icons.iconarchive.com/icons/custom-icon-design/flatastic-10/128/Trafficlight-red-icon.png",
2: "https://icons.iconarchive.com/icons/hopstarter/soft-scraps/128/Button-Blank-Yellow-icon.png",
3: "https://icons.iconarchive.com/icons/custom-icon-design/flatastic-10/128/Trafficlight-green-icon.png"
}

AssignTo={
"CPU USAGE": "john.doe@outlook.com",
"MEM USAGE": "john.smith@outlook.com",
"DISK USAGE": "jack.daniel@outlook.com"
}
payload={
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"themeColor": "A9CCE3",
"summary": "Server Alert",
"sections": [{
"activityTitle": "New task reported for: %s" %IssueType ,
"activitySubtitle": "Server Monitoring",
"activityImage": SevImage[1],
"facts": [{
"name": "Assigned to",
"value": AssignTo[IssueType]
}, {
"name": "Severity",
"value": Severity
}, {
"name": "Server name",
"value": ServerName
}, {
"name": "Issue Type",
"value": IssueType
}]
}],
"potentialAction": [{
"@type": "OpenUri",
"name": "View details on console",
"targets": [{
"os": "default",
"uri": "https://<LINK-TO-SERVER-LOG-CONSOLE>"
}]
},{
"@type": "OpenUri",
"name": "Update Service Incident",
"targets": [{
"os": "default",
"uri": "https://<LINK-TO-INCIDENT-MANAGEMENT-TOOL>"
}]
}]
}
headers = {'Content-Type': 'application/json','Accept': 'application/json'}

json_payload = json.dumps(payload)
response = requests.request("POST", url, headers=headers, data=json_payload)print(response.text)
import requests
import json

url = "https://<Your webhook URL>"

IssueType="CPU USAGE"
Severity=1
ServerName="SERVER-007"

SevImage={
1: "https://icons.iconarchive.com/icons/custom-icon-design/flatastic-10/128/Trafficlight-red-icon.png",
2: "https://icons.iconarchive.com/icons/hopstarter/soft-scraps/128/Button-Blank-Yellow-icon.png",
3: "https://icons.iconarchive.com/icons/custom-icon-design/flatastic-10/128/Trafficlight-green-icon.png"
}

AssignTo={
"CPU USAGE": "john.doe@outlook.com",
"MEM USAGE": "john.smith@outlook.com",
"DISK USAGE": "jack.daniel@outlook.com"
}

payload={
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"themeColor": "A9CCE3",
"summary": "Server Alert",
"sections": [{
"activityTitle": "New task reported for: %s" %IssueType ,
"activitySubtitle": "Server Monitoring",
"activityImage": SevImage[1],
"facts": [{
"name": "Assigned to",
"value": AssignTo[IssueType]
}, {
"name": "Severity",
"value": Severity
}, {
"name": "Server name",
"value": ServerName
}, {
"name": "Issue Type",
"value": IssueType
}]
}],
"potentialAction": [{
"@type": "OpenUri",
"name": "View details on console",
"targets": [{
"os": "default",
"uri": "https://<LINK-TO-SERVER-LOG-CONSOLE>"
}]
},{
"@type": "OpenUri",
"name": "Update Service Incident",
"targets": [{
"os": "default",
"uri": "https://<LINK-TO-INCIDENT-MANAGEMENT-TOOL>"
}]
}]
}

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

json_payload = json.dumps(payload)
response = requests.request("POST", url, headers=headers, data=json_payload)
print(response.text)

--

--

--

Automation Engineer | https://shelwyn.in/ | Currently in Bengaluru

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Cwincapital Announces Partnership with Project Moonwarriors.

Taraxa Weekly Update — Week 31

HUFFMAN ENCODING

IOTA Meets Couchbase

The Importance of Attending Tech Conferences!!

How to Create AWS Hybrid Cloud Architecture Diagram

Running a Free VPN Server on AWS

3 Ways To Manage Resources On AWS

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Shelwyn Corte

Shelwyn Corte

Automation Engineer | https://shelwyn.in/ | Currently in Bengaluru

More from Medium

Spreedsheats API — Python

The Important Steps You Cannot Miss When Building Python Library Part 1

The Important Steps You Cannot Miss When Building Python Library Part 1"

Problems with Python on MacOS

Python OOPS Concepts(Constructors)