Contact Free trial Login

Custom Application Alerts and Notifications

logo cloud active logo hybrid disabled logo server disabled logo pcf disabled

Prerequisites

  • Your application must be deployed to CloudHub.
    Deploy to CloudHub

  • You Mule project must be mavenized.

How to Use Notifications

Notifications give you visibility into business-related events inside your application. For example, you can create notifications for when:

  • Your application is unable to connect to a remote service.

  • An error that requires human intervention occurs, such as a problem with data mapping.

  • You want to create a summary of what occurred inside your application, such as the number of orders processed.

In combination with alerts, you can direct these notifications to different people to act on the alerts and fix the underlying problems.

This example illustrates:

  • How to send business related events as notifications

  • How to send errors as notifications

  • How to send email alerts when notifications arrive

Deploying Your Application

To deploy your application, in the Runtime Manager click Deploy Application from the Applications menu. For more information, see Deploying to CloudHub.

Triggering Your Notification

Once your application is running, you can trigger the notification by going to your application’s URL, for example: http://YOURAPP.cloudhub.io/hello-notification. The page displays a Hello World message, and automatically creates a new notification in your Runtime Manager console.

Return to the Runtime Manager console and click the new notification indicator bell in the upper-right to display the alert message:

image2014-10-24+17-41-16-1

If the notification is sent after an exception, it attaches the exception.message and exception.stacktrace as custom properties of the notification, which are accessible from the Runtime Manager console.

Custom Alerts

Alerts allow you to send emails based on your application’s notifications. You can create standard alerts in CloudHub with the software provided. To create custom alerts, you need to get the CloudHub Connector and install it in Anypoint Studio.

Custom alerts and notifications are available only for applications deployed to CloudHub workers. They are not available for applications that you deploy to on-premises servers. See Deployment Strategies for more details.

Prerequisites

  • Install and configure the CloudHub Connector. The CloudHub Connector is available for both Mule 3 and Mule 4 applications.

  • Install Anypoint Studio.

Create a Custom Alert

  1. Create a global configuration for the CloudHub Connector to define how to sign into Anypoint Platform. It can use basic authentication or inherited token authentication.

  2. In Anypoint Studio, drag the CloudHub Connector from the Mule palette into the application flow for which you want to trigger an alert.

  3. Create the custom notification inside the application, and complete the connector configuration.

  4. Go to Runtime Manager to bind the custom notification to an alert.

  5. Click Alerts in the menu on the left.

  6. Click the blue plus sign to create a new alert.

  7. In the Create an Alert window, configure the information for your custom alert.

    • Name - Enter a meaningful name for the custom alert.

    • Severity level - Select the severity level to apply to the alert:

      • Critical

      • Warning

      • Info

    • Source - Select the alert source:

      • Applications

      • Servers

    • Application type - Select CloudHub Applications.

    • Applications - Select specific applications to which to apply the custom alert, or choose All applications to apply the alert to all the applications in the environment.

      For custom alerts, the applications you select must be applications that contain the flow you configured to trigger a custom alert.
    • Condition - Select Custom application notification.

      • Select the Priority from the drop-down list, or leave the priority as Any to send notifications regardless of priority.

      • Enter the value for the word that will trigger a notification in Contains.

        This string must match a string in the message you added in the CloudHub Connector.
    • Subject - Enter the subject line to include in the notification email.

    • Message - Enter the custom message to include in the notification.

    • Recipients - Enter the email addresses for notification recipients.

  8. Click Create Alert.

    custom alert2

    Trigger your notification again by going to your application’s URL, for example: http://YOURAPP.cloudhub.io/. The addresses you specified receive an email with your notification.

This is an example of custom properties defining where to send a notification.

<cloudhub:create-notification message="Error processing transaction." priority="ERROR">
  <cloudhub:custom-properties >
    <cloudhub:custom-property key="originalPayload">#[flowVars.originalPayload]</cloudhub:custom-property>
  </cloudhub:custom-properties>
</cloudhub:create-notification>

Then, they can be accessed as normal properties in the message, for example ${originalPayload}

Sending an Error Notification

You can use the CloudHub Connector inside a catch exception strategy to send notifications when errors happen.

  1. To do this, add the following XML to your mule-config.xml:

    <flow name="create notification from exception">
        <inbound-endpoint address="http://0.0.0.0:${http.port}/create-notification-from-exception"/>
        <scripting:component>
            <scripting:script engine="groovy">
                throw new Exception("Could not connect to remote service.")
            </scripting:script>
        </scripting:component>
        <default-exception-strategy>
            <cloudhub:create-notification message="Error processing transaction." priority="ERROR"/>
        </default-exception-strategy>
    </flow>

    This flow throws an exception and creates a notification from that exception with the message Error processing transaction. The exception stack trace for the flow is attached to the message. This can optionally be turned off using the attachStacktrace attribute.

  2. Build and deploy your application, then go to the URL: http://YOURAPP.cloudhub.io/create-notification-from-exception.

  3. Return to the Runtime Manager console, where a notification pop-up appears in the top-right.

  4. Click the notifications link, and the notification with the stack trace appears in the notifications list.

    notifications_exception
  5. To view the whole stack trace and details, click More…​ and the whole message appears in a pop-up window:

notifications_stack_trace