Automation Python script to send an email to receiver about new Approval Requests

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:

Python Approval List Alert

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:

  1. Package Python script into a task
  2. To create Execute Scheduling, access Library → Automation → Excute Scheduling → Add run minute
  3. To execute Execute Scheduling, access Provisioning → Jobs → Add → Select Job (Python Script)

The result:

4 Likes

That’s a great contribution @Cuong_Duong. Please keep them coming!

2 Likes

Thats really nice script.

Personally I really think that should be incorporated into product rather then scheduling script to run on schedule basis (this is real gap on Morpheus side).

2 Likes