Email Notifications with Stream Analytics

2.8k views Asked by At

I'm looking for an elegant way to send an email notification in case a Stream Analytics job detects that a threshold was passed - roughly the same as shown on Channel 9 by Santosh Balasubramanian.

Upon passing the threshold, a record is written to a SQL table. This should trigger an email to be sent.

For a second, I thought I could a Mobile Services 'insert' script defined on that table as explained here, but of course, the Stream Analytics job doesn't pass through the Mobile Services API...

Best option I could think of so far is using a Mobile Services Scheduled Job instead, which would poll the table every 5 minutes or so, and send an email if new records are found.

Is there a better way? Or should I add a feature request for Stream Analytics to enable Mobile Services as output type?

2

There are 2 answers

1
Phuc H Duong On BEST ANSWER

A possible implementation that I have done which emails you in the event of an anomaly detection is the following:

  1. In Stream Analytics, write a Stream Query that detects your desired anomaly thresholds.
  2. Send the output of the Stream Analytics to an other Azure Event Hub who has no other senders, we will call this the anomaly detection Event Hub. Any message that ever hits this Event Hub will be an anomaly.
  3. Write an Event Hub receiver app that is subscribed to the anomaly detection hub. This app can then be programmed to take action (like send emails) when it sees any events in the subscribed Event Hub.

Please refer to this documentation on how to subscribe to an Azure Event Hub. https://azure.microsoft.com/en-us/documentation/articles/service-bus-event-hubs-csharp-ephcs-getstarted/

You will want to send the email in the following section of the documentation mentioned above:

foreach (EventData eventData in messages)
    {
        string data = Encoding.UTF8.GetString(eventData.GetBytes());

        Console.WriteLine(string.Format("Message received.  Partition: '{0}', Data: '{1}'",
            context.Lease.PartitionId, data));
        // SEND EMAIL HERE
    }
0
Dag König On

I should solve it by sending the event, that you want to create an email for, through a new event hub queue, instead of to a SQL Table. (So the output of the streaming analytics job is an event hub queue.) From that queue you can have a eventprocessor that creates the mail and send it. I should use SendGrid to send the mail.

/dag