Blog

How To Receive Log Alerts Via Flashing Lights In Your Office or Home

This is a guest blog post by Jason Ruane, the technical director at Moposa, a place for brides and grooms to plan and manage their wedding. In this post Jason describes how he used a Wi-Fi enabled light and Logentries alerts to receive Logentries alerts via flashing lights in his house. Jason and his team are long time users of Logentries, analyzing all their logs from multiple servers in one centralized, cloud location.

How I receive my Logentries alerts via home lighting

Previously, I wrote a small article describing how my cloud based server logs from Logentries were sending alerts to my phone via SMS. This time, for fun, I have taken it one step further and now an alert from Logentries triggers the lights in my home to flash red when there is an issue on our servers. This could easily be done in an office as well.

One of Logentries’ features I use often is an alerting system that notices when an issue occurs notifies us. This notification makes a HTTP call and which is the underpinning of how I configured Logentries to trigger a red flashing sequence on the lights in my home.

First, an overview of the topology:

Topology

How It Works

  1. My web server is hosting the production website. I just indicated it as a single machine, but in reality it is multiple frontend web servers behind an Amazon Elastic Load Balancer. They are continually piping their logs to the Logentries service.
  2. Logentries receive all these logs, storing and processing them. I have set up an alarm there which notices if a particular log entry matches a certain criteria and if so, makes a web service call via HTTP POST to the Parsing server.
  3. The Parsing server receives this HTTP call. In reality it is not a dedicated server, it’s shared for other uses as this part is rarely used. Its purpose is to translate the HTTP post from Logentries into the particular call via UDP which is required for the lights to be activated and controlled. The parsing server receives the Logentries call, interprets it and sends the respective UDP call to the house.
  4. The Wi-Fi router in the house receives the UDP datagram. A hole on a particular port has been punched through the firewall to facilitate this. Also, the use of dynamic DNS was required for the parsing server to know the IP address of the house router. So, the UDP signal passes through the Wi-Fi router and is directed to the LED light’s Wi-Fi bridge, which is on a static assigned IP within the house.
  5. The Wi-Fi bridge receives the UDP call and sends a 2.4GHz signal to the respective LED bulb in the house.
  6. The LED bulbs in the ceiling receive the signal and turn on, flash red and off 3 times to signify the alert. Then I hop off the couch and spring into superhero-sysadmin mode.

Check out this video to see this process in action:

More Detailed Instructions

The screenshot below shows how to create an alarm in Logentries and for the action, set it to “POST me a notification” to the URL of the parsing server.

Logentries_Screenshot

The code for the parsing server was written in ASP.NET C#. It could of course be written in whatever your favourite language is for getting machines to do your bidding. I am including the whole thing as a zip file download, but the important bits are shown below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
        if (!Page.IsPostBack)
        {
            // If this was a call from LogEntries, run the alert sequence
            // The call to this page would have looked like: page.aspx?logentries=alert
            if (Request.QueryString["logentries"] != null)
            {
                string logEntriesValue = Request.QueryString["logentries"].ToString().Trim();
                if (logEntriesValue == "alert")
                {
                    // Flash the light red (and then off) 3 times to indicate the alarm
                    for (int i = 0; i < 3; i++)
                    {
                        LightsAction("turnon", 0);
                        LightsAction("setcolour", 175);
                        System.Threading.Thread.Sleep(1000);
                        LightsAction("turnoff", 0);
                        System.Threading.Thread.Sleep(1000);
                    }
                    // Set the light back to a calming blue, while we go address the alarm
                    LightsAction("turnon", 0);
                    LightsAction("setcolour", 10);
                }
            }
        }

And:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
    /// <summary>
    /// Perform a standard action for the lights
    /// The UDP datagram sent is 3 bytes long and uses codes as per the manufacturer
    /// </summary>
    /// <param name="actionRequired"></param>
    /// <param name="colourRequired">An int from 0 to 255. These are special codes as per the manufaturer. Eg. 10=Blue, 175=Red</param>
    protected void LightsAction(string actionRequired, int colourRequired)
    {
        string destination = TextBoxIpHouse.Text.Trim();
        int destinationPort = 50000;
        if (actionRequired == "turnon") {SendSignalUdp(new byte[] {0x22, 0x0, 0x55}, destination, destinationPort);}
        if (actionRequired == "turnoff") { SendSignalUdp(new byte[] { 0x21, 0x0, 0x55 }, destination, destinationPort); }
        if (actionRequired == "setcolour") { SendSignalUdp(new byte[] { 0x20, byte.Parse(colourRequired.ToString()), 0x55 }, destination, destinationPort); }
        // Insert a pause before sending the next signals as they can interfere if rushed
        System.Threading.Thread.Sleep(100);
    }
    /// <summary>
    /// Send the UDP datagram
    /// </summary>
    /// <param name="byteArray"></param>
    /// <param name="destination"></param>
    /// <param name="destinationPort"></param>
    protected void SendSignalUdp(byte[] byteArray, string destination, int destinationPort)
    {
        System.Net.Sockets.UdpClient udpClient = new System.Net.Sockets.UdpClient(destination, destinationPort);
        udpClient.Send(byteArray, byteArray.Length);
        udpClient.Close();
    }

Equipment used:

  1. Internet connected lightbulbs
  2. Wi-Fi to bulbs bridge (comes free with the light bulbs)
  3. Regular web server (referred to as parsing server above).
  4. Home router: Nothing fancy but you will need to be able to open a port on it.

From Logentries – Now it’s your turn!

What cool use cases have you thought of to use Logentries? Are you making your phone ring every time an alert comes in? A Nerf missile gets fired at you? Some other idea we haven’t even thought of? Let us know and we’ll feature you up here on the Logentries blog!

About Moposa

Here at Moposa, we are building a place for brides and groom to plan and manage their wedding. We have been using Logentries from the moment we heard of them. Cloud based logging was the perfect solution, for both our scale-up and then scale-out setups. We are building on .NET with C# and every time I jump into Logentries it is a joy to see the happy humming of multiple servers stream into the one unified location.Logentries_Try_It_Free_Promo_W


Share This Post


Posted in Howto, Logentries

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <p>

Current day month ye@r *