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:

How It Works

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. 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. 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. 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. The Wi-Fi bridge receives the UDP call and sends a 2.4GHz signal to the respective LED bulb in the house. 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.



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:

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:

/// <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:

Internet connected lightbulbs Wi-Fi to bulbs bridge (comes free with the light bulbs) Regular web server (referred to as parsing server above). 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.