We have recently added the API Monitoring feature to Serverless360 and this opens up a wide range of monitoring opportunities. The principle of API Monitor is that you have an API endpoint that you want Serverless360 to periodically call and then you will make assertions against the response to check if the API is healthy or not.
One of the reasons I wanted to have this feature in Serverless360 is it also allows us the opportunity to leverage the Azure Management API to monitor things in Azure which we haven’t yet built advanced support for in Serverless360. This lets me cover scenarios like services that are new and in the preview that customers are starting to use but which haven’t hit the top of our backlog in Serverless360 to support or other scenarios like if a customer has a requirement that isn’t very common.
In this case, I wanted to show how you can use the API Monitor with the Azure Management API to monitor the status of an API Connection. This is a scenario Sandro and I have spoken about recently on our blogs where we discussed a few different ways this could be done with custom approaches.
Adding the API Endpoint
In my Business Application, you can see a new feature to add an API Endpoint.
I can use this in the API Endpoint and configure a GET request as shown below.
I now need to choose the OAuth authorization type.
I would add the url for my Azure AD OAuth token endpoint and indicate it’s a post request and also add the request to get a token.
For my request, I am using a service principal which I have specifically given read access to just that resource. Note we will be adding support in an upcoming release to pick up one of the service principals you have registered for Serverless360.
Next, I will add a content type header for the OAuth request to indicate it’s an application/x-wwwform-urlencoded request.
On the Authorization Response tab, I need to indicate where I can get the token from. In the response type, I choose JSON and then I leave the token prefix empty. You could add a prefix if you need one but in this case, just leave it blank.
I then add the JSON path for the access_token which will be obtained and used as the token for the request to Azure.
I can now click the Get Access token button to test if I can retrieve a token.
If you have any problems getting the token, change the $.access_token to $.error and it will show you what the error response is.
Next, I need to configure what I want the monitoring for the API Endpoint to do. If I go to the Monitoring tab and click add a rule. I can then set two rules. The first rule is straightforward I expect the status code to be 200 otherwise an error will be thrown.
The 2nd rule will use the Response body as JSON and check the JSON path properties.statuses.status to ensure it is connected.
I can now click the try it button at the bottom and it will check if my API can be successfully called.
You can see below the example body returned and that the request was successful.
You can also see on the Assertion tab that it is indicating that my tests were successful.
I can now click add and the API Endpoint will be added to my Business Application, and I can now monitor this endpoint alongside my other resources.
If my API Endpoint becomes unhealthy, then it will trigger the monitoring notifications you have configured in Serverless360 which can alert you to an issue in various ways.
Hopefully, this article shows how you can easily use the idea I blogged about a while ago about monitoring API Connections using the API Monitor feature and this article shows how you can leverage the Azure Management API for any custom monitoring you need to do.
Watch this space as I’m sure we will be doing more in this area in coming releases.