In some previous post that were release on the Codit blog we saw how to build a custom access rule expression and how to leverage the WCF extensibility by setting up a virtual service with a custom endpoint behavior .
In this post I would like to explain another extensibility point of Sentinet: Custom Alert Handlers.
Alerts or Violation Alerts are triggered in the Sentinet Service Agreements when certain configured SLA violations occurred. More details about Sentinet Service Agreements can be found here.
The main scenario for this blog post is very simple. We will create our own Custom Alert Handler class by inheriting certain interfaces, register our custom Alert Handler in Sentinet and use it as an Alert when a certain SLA is violated.
Creating the Custom Alert Handler
We start our implementation of the custom alert handler by creating a new class that inherits from the IAlertHandler interface. This interface is available through the Nevatech.Vbs.Repository.dll.
This interface contains one single method: ProcessAlerts where you put your logic to handle the alert after the SLA violation has occurred.
One more thing to do before we can start our implementation of the ProcessAlerts method is to add a reference to the Twilio REST API through NuGet. More information about Twilio can be found here.
The final implementation of our custom Alert Handler looks like below. We start by initializing some variables needed for Twilio. After that everything is pretty straight forward. We read our handler configuration, here we made the choice for a CSV configuration string, but you can perfectly go for an XML configuration and parse it to an XMLDocument or XDocument.
When we’ve read the receivers from the configuration we create an alert message by concatenating the alert description, after that we send an SMS message by using the Twilio REST API.
The first step in registering your Custom Alert is to add your dll(s) to the Sentinet installation folder. This way our dll(s) can be accessed by the “Nevatech.Vsb.Agent” process, that is responsible for generating the alert. There is no need to add your dll(s) to the GAC.
Next step is to register our Custom Alert in Sentinet itself and assign it to a desired Service Agreement.
In the Sentinet Repository window, click on the Service Agreements and navigate to alerts and then choose add Alert. Following screen will popup.
Next step is clicking on the ‘Add Custom Alert Action’ button as shown below.
In the following screen we have to add all our necessary parameters to configure our Custom Alert.
- Name: The friendly name of the Custom Alert
- Assembly: The fully qualified assembly name that contains the custom alert
- Type: The .NET class that implements the IAlertHandler interface
- Default Configuration: The optional default configuration. In this example I specified a CSV value of difference phone number. You can access this value inside your class that implements the IAlertHandler interface.
Confirm the configuration by clicking ‘OK’. In the next screen be sure to select your newly configured Custom Alert.
You will end up with following Configured Violation Alerts.
To test this alert I’ve modified my Service Agreement Metrics to a very low value (ex ‘Only 1 call is allowed per minute’). So I could easily trigger the alert. After I called my Virtual Service multiple times per minute, I received following SMS.
Service agreement “CoditBlogAgreement” has been violated one or more times. The most recent violation is reported for the time period started on 2014-07-24 18:15:00 (Romance Standard Time).
Sentinet is designed to be extensible in multiple areas of the product. In this post I’ve demonstrated how to create a Custom Alert Handler that will send an SMS when an SLA has been violated.