Hi everyone, I want to share with you guys a Python script to send an email notification for the new approval requests by packaging this script into a task and scheduling it to run every minute (the condition to send email is when Status = “request” in Python code from API JSON result).
if any(approval.get(“status”) == “1 requested” for approval in approvals_data[“approvals”]):
You can go to my Github to pull code:
Don’t forget to change these lines:
smtp_server = "smtp.elasticemail.com" #SMTP Server
smtp_port = 2525 #SMTP Server Port
smtp_username = "cuong.dq@csc-jsc.com" #SMTP Username
smtp_password = "REPLACE_ME" #SMTP Password
sender_email = "REPLACE_ME"
recipient_email = "REPLACE_ME"
and
url = “https://csc-morpheus.anycloud.vn/api/approvals”
headers = {
“accept”: “application/json”,
“authorization”: “Bearer CHANGE_ME”
}
To run it on schedule on Morpheus, follow these steps:
- Package Python script into a task
- To create Execute Scheduling, access Library → Automation → Excute Scheduling → Add run minute
- To execute Execute Scheduling, access Provisioning → Jobs → Add → Select Job (Python Script)
The result: