Home United States USA — software Automating API Monitoring Using MuleSoft Flow Designer

Automating API Monitoring Using MuleSoft Flow Designer

362
0
SHARE

This tutorial will help you learn to automate your API monitoring and URL pinging using the MuleSoft Flow Designer. Get the instructions and source code here.
I have created a Mule application that pings URLs to ensure that they are up, and if the URL is down for some reason, the Mule application is capable of sending out an email notification. At the time of this writing, the Mule application could send out email notifications, and I plan to incorporate more types of notification as I continue to improve it.
The source code is fully obtainable via GitHub.
Figure 1.0 shows an abstract diagram of what the API monitor expects. Users would submit a JSON payload consisting of an array of target URLs to be pinged by the API monitor. In conjunction with the target URL, users would also need to specify notification interval; the notification interval is useful in that users won’t be spammed with notification messages if the ping is very frequent, e.g. 5 seconds. For instance, if the notification interval is set to 1 hour, and users are trying to ping a target URL that is down for every minute, and if the target URL is down for 2 hours, then users would essentially only receive 2 notification emails (instead of getting one email every minute the target URL is down) . Figure 1.0a shows an example of an input payload.
If the URL is pingable, then the API monitor will set isUp to true (green) ; otherwise, it would set isUp to false and send out a notification to the user. The output payload from the API monitor would contain enriched data like the timestamp on which the URL is pinged, and also the status of the URL.
The returned notification timestamp would be the same as the previous notification timestamp if the notification interval has not expired. If the notification interval has expired, then it would be updated with a new timestamp.
The output JSON payload would also have the latest timestamp on the current ping attempt. Figure 1.0b shows an example of a JSON output payload.
Now that you have an API monitor that is capable of pinging URLs and sending out notifications if the URL is down, the next step is to automate the pinging. We can easily achieve this via the new Design Center’s Mule Flow (assuming that you will be deploying the API monitor into CloudHub) . Let’s step through how we can achieve this. First, from CloudHub, you have to select “Design Center” (depicted in Figure 2.0) .
When in Design Center, click on the “create” button on your right (Figure 2.0a) , and select Mule Application.
You will then be prompted with a pop-up dialog. Key in the same text as per depicted in Figure 2.0b
Select “scheduler” as the first component and set it to 10 seconds, as per Figure 2.0c
Next, select an HTTP requester component, and key in the URL as per figure 2.0d.
Then, if you see a text box marked with f (x) on its right-hand side like the one you see at Figure 2.0d, it means that it accepts Dataweave expressions. Flow Designer Mule Applications run on Mule Runtime 4.0; to learn more about it, go to the following links:
Extracting component of Mule Event .
F (x) Expression explained .
Dataweave syntax explained .
All the links I have shared above are for Mule 4.0.
You need to click on the map button beside the f (x) sign (Figure 2.0d) . When you click on the map button, you will see the following pop up dialog in Figure 2.0e.
Click on the script tab and cut and paste your desired payload into the middle pane, and this will be the payload that will be submitted to the API manager every 10 seconds to ping the list of URLs you have specified in your payload.
When you finish your Flow Designer configuration, it should look like the following Figure 2.0f.
You need to click on the deploy button on the top right of the screen shown in Figure 2.0f. Once the application is deployed, you will see the small green marking on all the message processors, indicating that they have been executed successfully, as shown in figure 2.0g.
Right after you click “deploy” at figure 2.0f, CloudHub will deploy an instance of your Flow Designer Mule application at the runtime manager. If you go to your runtime manager in CloudHub, you will see your application at Figure 3.0a.
If you click on it and browse to the Logs Menu at Figure 3.0b, you will see the output payload returned by the API monitor application created earlier.
If you followed all the setup steps in the earlier sections, your Flow Designer application is actually running on the Design environment. You could download and version your application via the download icon at the top right of the CloudHub screen: You could also promote it to other environments by clicking on the promote icon: This is how you can easily automate URL/API monitoring.

Continue reading...