HPE Morpheus Enterprise Software
1856403 Members
6338 Online
104112 Solutions
New Discussion

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

 
CuongDuong
Frequent Advisor

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:

2 REPLIES 2
Ollie-Phillips
HPE Pro

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

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



I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
Not applicable

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

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).