* Requirement Analysis: The organization needs to send email alerts to the internal operations team whenever a policy applied to an API instance is deleted in the CloudHub runtime plane.
* Solution: The most effective approach is to implement a new Mule application that uses the Audit Log REST API to detect when a policy is deleted and then sends an email using the SMTP connector.
* Implementation Steps:
* Access Audit Logs:
* Use the Anypoint Platform's Audit Log REST API to monitor and detect policy deletion events.
* Example of accessing the Audit Log REST API:
GET /accounts/api/v2/organizations/{orgId}/audit-logs
* This endpoint will provide logs, including events related to policy deletions.
* Create Email Notification Application:
* Create a Mule application that periodically polls the Audit Log REST API to check for policy deletion events.
* Use the SMTP connector to send email notifications to the operations team.
* Example Mule flow:
<flow name="policy-deletion-alert-flow"> <scheduler frequency="60000" /> <http:request config-ref="AuditLogAPIConfig" path="/audit-logs" method="GET"> <http:request-builder>
<http:uri-params> <http:uri-param key="orgId" value="your-org-id" /> </http:uri-params>
<http:query-params> <http:query-param key="eventType" value="PolicyDeleted" /> </http:query-params>
</http:request-builder> </http:request> <choice> <when expression="#[payload contains 'PolicyDeleted']">
<smtp:send config-ref="SMTP_Config" to="
[email protected]" subject="Policy Deletion Alert">
<smtp:body>Policy deletion detected: #[payload]</smtp:body> </smtp:send> </when> </choice> </flow>
* Scheduler: Configures the application to check the audit logs at regular intervals (e.g., every minute).
* HTTP Request: Makes a GET request to the Audit Log REST API to fetch the logs.
* Choice Router: Checks if the payload contains a policy deletion event.
* SMTP Connector: Sends an email to the operations team with details about the policy deletion.
* Advantages:
* Automation: Automates the detection of policy deletions and the notification process, reducing manual monitoring efforts.
* Timeliness: Ensures the operations team is promptly informed of any policy deletions, enabling them to take immediate action if necessary.
References
* MuleSoft Documentation on Audit Log REST API
* MuleSoft Documentation on SMTP Connector
* MuleSoft Documentation on MuleSoft Scheduler Component