Overview
This article will cover how to add a script to the post order hook point that notifies admins of an order completion only when the order fails
Procedure
Create the action
In your Cloudbolt instance, navigate to Admin → Orchestration Actions → Post-Order Execution
Select “Add an action”
Create a new Cloudbolt Plugin
Disable all other actions under that hookpoint
If there are any other actions enabled under the “Post-Order Execution” hookpoint, make sure you disable them before trying to use this plugin, or it will not work.
Add code to newly created action
Copy the contents of the below code snippet and add it to the action that we created in previous steps.
from utilities.mail import email_admin from portals.models import PortalConfig import urllib.parse from utilities.logger import ThreadLogger logger = ThreadLogger(__name__) def run(order, *args, **kwargs): if order.status =="FAILURE": portal = PortalConfig.get_current_portal() site_url=portal.site_url url = urllib.parse.urljoin(site_url,order.get_absolute_url()) logger.info(f"THE URLS IS {url} and status is {order.status}") body_text = '{} FAILED. THIS IS AT POST ORDER here: {}.'.format(order, url) email_context = {"message":body_text, "subject":"Support Action Required POST ORDER: User order failed. "} email_admin(slug='job-failure', context=email_context) return "SUCCESSFUL", "", "" else: return "SUCCESSFUL", "", ""
Additional information
This plugin uses the “Admin Email” field under Admin → Email Settings → Admin Email, make sure to set that, or no one will receive any emails.
0 Comments