Serverless360 is an excellent tool to monitor all 3 types of messaging brokers: Messaging, Event Hubs, and Relays. When something is wrong the tool will send a detailed notification to one of the configured notification channels, so you can take actions when it is needed. If you have not yet managed to configure a channel I would recommend reading one of the previous blogs (Introducing Notification Channels in Serverless360).
We understand that our clients use a variety of tools to manage their alerts and notifications, thus we try our best to develop and deliver each one of them to our product. Currently, there are dozens of custom tooling and ready-made solutions like PagerDuty, JIRA, Freshdesk and more. Therefore, it will take some time before we can reach to every one of them, so we decided to create something that will help our customers to achieve this on their own.
A WebHook is an HTTP callback: an HTTP POST that occurs when something happens; a simple event-notification via HTTP POST. That is how we came up with an idea to develop WebHook notification channel that will send the notifications in one of the popular formats XML or JSON to your custom-made solution. This channel opens new possibilities to our customers:
- Send notifications to any system of your choice or multiple systems at the same time
- Automate processes based on the notification: Disable a queue when it is close to size limit or stop a process sending messages to that queue
In this blog, we will look how we can create the WebHook channel, then we will inspect the schema of the notification and lastly, we will use Azure Logic App to show how we can use it in real life scenario.
Creating the channel
The management section of notification channels is in the settings page of Serverless360. Simply log in to your account and from the top right-hand corner click on the gear icon. Once you are in the settings page, from the left-hand side menu click on Notification Channel. You should now be in the management section of notification channels, in the top right-hand side you will see “Create New Channel”.As you click, it will open a new blade with a list of channels that you can configure, in this case, we are interested in the WebHook, so select it from the list. The UI should update with new fields to enter, first a friendly name that will help you identify the channel when you map it to your alarms.
The next page is the configuration of the channel you have selected, in the case of WebHook the following details need to be filled in:
- HTTP Request Method – select the appropriate method used by your WebHook either POST or PUT.
- WebHook URL – the URL where the notification will be sent to.
- Message Content Type – you can choose between two main standards of content type XML or JSON, that is supported by your API.
- Default Headers – Any additional headers that will be sent with the request. You can use it to forward Authentication tokens or any additional details required by your API to be successfully authorized.
- Authorization Key – Fill in, if your API is secured by a raw authorization key, or leave it blank. We are planning to bring more authorization options in the future.
Once you have filled in all the details, press “Add” and wait few seconds for the channel to be created.
Understanding the schema
We have the channel, but before we hook it up to one of your services it would be nice if we get to know the schema of the payload which will be sent to you by Serverless360. The schema can be found here, however, by the time you are reading this blog, it could have changed. Therefore, the easiest way to get the latest up to date schema is to use requestbin, which will output all the headers and payload in a nice readable format for you to analyze.
The process is very simple just visit https://requestb.in/ and click on the green button saying “Create a RequestBin”, then you will be forwarded to a new page. Now edit the channel or create a new channel that points to the URL of the page you have been forwarded to. Next, go to one of your namespaces and map the channel to one of your alarms by going to the last page of alarm configuration where you can select channels that you want the alarm to use to notify you of any issues. Lastly, when the alarm triggers a notification wait few seconds and refresh the request bin page, if everything went fine you should be able to see all the headers and body of the notification.
Real Life scenario
Finally, we will look at how we can utilize all the information we have gathered in previous steps to implement some real-life scenario. Let us assume that Contoso is using Freshservice to handle the IT support tickets, currently, Serverless360 does not have a connector which would allow them to directly connect to this service, but they can utilize our WebHook Notification channel.
Now the easiest way to handle the notifications is to create a logic app, as it has everything we need to handle Serverless360 notifications. Head to your Azure portal and create a new logic app using Request-Response template, in the request paste in the schema of the notification.
- New Logic App Request-Response
2. Request Schema
Add “Parse JSON” action and put in the body of the request together with the schema. Now add “For Each” and as an input use body of the “Parse JSON” output. At this point, we need to create an azure function which will parse the issues and create a meaningful string which can be sent as a body of the ticket. The code of the azure function can be found here, it simply loops through the alert issues and composes a nice readable string. Head back to your Logic App and add next step to create a Freshservice ticket, it will ask you to fill in the authorization details. You can either use an API key from your profile as your login and password or you can use your actual login credentials. Once successfully validated, use the body of azure function as your description and set all the other parameters up to your requirements.
3. Parse JSON
4. Azure Function
5. Freshservice Create Ticket
The last few steps will require you to copy the logic app request URL and paste it in your WebHook notification channel within Serverless360. When your alarms will start triggering alerts you should see new tickets being added to your freshservice.
6. New Tickets
7. Ticket ContentKeep in mind that the WebHook notification channel can be used to do more than just notify people of problems in your environment. It can also take actions like deleting queues, stopping queues from receiving more messages, etc.
I hope this blog will be helpful when you plan to develop your own custom notification channel. If you are going to face any issues, please do let us know and we will be more than happy to assist you.
Below are the links for the workflow template, azure function, and alert schema.
Watch our video on WebHook Notification Channel.
Please let us know your valuable feedback or suggestions at support@Serverless360.com.
Serverless360 is a one platform tool to operate, manage and monitor Azure Serverless components. It provides efficient tooling that is not and likely to be not available in Azure Portal. Try Serverless360 free for 30 days!