Application Insights Module: Alerting Added

alerts

The Application Insights for Sitecore Module now comes with Alerting built in. The module periodically queries the Azure Monitor Application Insights Endpoint for each of the resources that you specify. It then summarises the data and stores it locally in a database. Now with alerting added in, before storing the data, it runs a few checks to see if everything is as it should be. If not, it alerts the relevant people.

The following alerts are available out of the box:

  • Exception Contains String
  • Exception Spike
  • Schedule Task Inactivity
  • Cron Task Inactivity
  • Custom Event
  • Webpage Down
  • Service Bus Queue Exceeds

You can easily extend the module and add in alerts that are specific to your own scenarios.

To add an alert, select one of the resources you are monitoring (i.e. /sitecore/system/Modules/ApplicationInsights/CM) and insert a child item of type "App Insights Alerts Folder".

Then add any one of the alert items shown above
(found here: /sitecore/templates/Modules/ApplicationInsights/Alerts).

Common Fields

All alerts derive from the base template "App Insight Alert". With that template comes some common fields. These are:

  • Enabled - checkbox to switch it on/off
  • Next Run - this is automatically set by the module and is checked every time the task runs to see if the alert needs to be checked.
  • Delay Between Alerts - this is to stop people getting bombarded by emails about an issue. Set a sensible time (in minutes) before the alert needs to be checked again after triggered.

Types of alert

Exception contains string

This alert scans all of the exceptions (and all textual parts - i.e. innermost message etc) that are returned from the Application Insights resource and looks for the given string. To configure this alert, set the following:

  • Exception String - the string to search for
  • Threshold - how many occurences of the exception need to be found before triggering the alert

Example: You might have added a new feature and want to be alerted if any exception contains 'yournewcontroller' to monitor and issues.

Exception Spike

Like it or not, alot of applications regularly register exceptions. On a normal day you might get (pick a number). But what if that number suddenly increased tenfold? Then I am fairly sure you would want to know about it. To configure this alert, set the following:

  • Percentage Threshold - what percentage of the last weeks daily average count should trigger the alert?

Example: In the example above, you would set 1000 as the percentage threshold, as this is 10 times the average normal amount.

Schedule Task Inactivity

This alert regularly checks a specified scheduled task to see if it has ran in a given period. To configure this alert, set the following:

  • Linked Scheduled Task - A droptree to select the scheduled task
  • Inactivity Threshold in Mins - After how long does inactivity become a problem

Example: You have a regular import from an external system that is suppoed to run every night. But sometimes, people remove the schedule or last run (to get it to run asap) and forget to add it back. Set theshold to 1440 minues (24hrs)

Cron Task Inactivity

This is the same as the above scheduled task inactivity alert, but allows you to linked to a Crom task instead. To configure:

  • Linked Cron Task - droptree to select
  • Inactivity Threshold in Mins - as above

Custom Event

This is another task that reviews the data coming back from the Application Insights API. In order for it to work, you need to have previously set your application to register 'custom events' against your application insights resource. This alert then checks for the occurence of that event in a given timeframe. To configure:

  • Event Desired - check this to specify if the event should be present
  • Custom Event - title of custom event
  • Hours Since Custom Event - how far back do you search for the event

Example: Say you have a daily routime that once completes registers a 'I am done' custom event. You might tick 'desired' and enter '24'. Then if the alerting process does not find an 'I am done' event in the last 24 hours, it will fire an alert.
Alternatively, you might register a custom event inside a try/catch saying 'major problem'. In that case, you would not tick 'desired' and enter '1'. To say alert me if you find that event in the last hour.

Webpage Down

This alert simply sends a http request to a specified web URI and triggers if the status code is not OK. To configure the alert:

  • Url - the URL to check

Example: you have other sites in your estate you want to manage. Add the URL here and be alerted if there is a non OK status

Service Bus Queue Exceeds

This alert checks to see if the number of messages in a service bus queue exceed our defined maximum. To configure, set the following:

  • Service Bus Connection - connection string to the resource
  • Service Bus Queue - the queue you are interested in
  • Service Bus Queue Limit - how many messages should trigger the alert

Example: You have a webjob that has a service bus trigger. If there are more than 0 messages in the queue it means the webjob is not operating correctly. In this situation, specify the queue and set the limit to '1'.


Add subscribers

This module is only current setup to alert people via email. But you could easily add the functionality to send a SMS, WhatsApp, Telegram message. Or perhaps post something in a teams channel.

In order to add a subscriber, pick a single alert that you have added and then add a child item directly below of template "Subscriber". In that item, you will find a single field called "Email", add a valid email address.

Now when ever an alert is triggered, every subscriber that is a direct descendant of the alert will be sent an email.

Leave a Reply

Your email address will not be published. Required fields are marked *