Twine is a neat little project that started on Kickstarter. Definitely go to their web site and read up on it. Their current notification options are email, SMS, LED blinking and HTTP. However if you look at the forum, you can see something we have known for years: SMS over email isn't a reliable solution for critical message. Enter xMatters.
Our Engineering team runs an innovation program called 555. Over time it has also trickled out to our field engineering groups. For our January Engineering 555 I decided to throw my hat in the ring and give the Twine something it deserves: true critical notification capabilities. And here is how I did it:
First of all, it should come as no surprise that my evil plan involved relevance engines. I built a relevance engine for Sensor Data, and I built a form for each one of the alerts that I planned on sending. Why build forms? Because our forms also dynamically build a REST API for programatic access. They are fairly simple forms, at least with our relevance engine design tools (good luck trying this with other "players" in the space) - here is a sample:
With the forms I also built messages:
And responses:
Now all I had to do was enable my form for REST access:
In less then 10 minutes of work, the system is now able to hand me my REST URL on a platter, allowing me to access with a quick copy and paste:
So xMatters was the easy part. Unfortunately Twine only generates an HTTP URL string, which is a "GET". A REST web call needs to generate a POST and JSON. I poked around at various web-based ETL tools (IFTTT, Tarpipe, COSM, Boomi) and none of them can generate a defined JSON request. That is weird... anyone want to build a startup that does that?
So the final step here is to take a Twine HTTP rule and setup something to convert it to a POST. Here is a sample Twine rule that I built which tells me if somebody left a server room door open for more then 3 minutes:
000webhost.com was kind enough to offer free web hosting, so I took them up on it. Their hosting covered PHP hosting... I have never used PHP before, but my 555 had a few hours left, so I had time to figure out how to make a basic JSON request:
<?php if ($twineField = $_GET['moisture']) { echo "Moisture is " . $twineField . " "; $rebURL = "https://acme.na1.xmatters.com/reapi/2012-03-01/engines/Sensor%20Array/Twine%20Moisture%20Detection"; $postField = "{\"properties\":{\"moisture\":\"" . $twineField . "\"}}"; } elseif ($twineField = $_GET['orientation']) { echo "Orientation is " . $twineField . " "; $rebURL = "https://acme.na1.xmatters.com/reapi/2012-03-01/engines/Sensor%20Array/Twine%20Orientation"; $postField = "{\"properties\":{\"orientation\":\"" . $twineField . "\"}}"; } elseif ($twineField = $_GET['door']) { echo "Door is " . $twineField . " "; $rebURL = "https://acme.na1.xmatters.com/reapi/2012-03-01/engines/Sensor%20Array/Twine%20Door%20Detection"; $postField = "{\"properties\":{\"door\":\"" . $twineField . "\"}}"; } elseif ($twineField = $_GET['temperature']) { echo "Temperature is " . $twineField . " "; $rebURL = "https://acme.na1.xmatters.com/reapi/2012-03-01/engines/Sensor%20Array/Twine%20Temperature"; $postField = "{\"properties\":{\"temperature\":\"" . $twineField . "\"}}"; } else { echo "No recognized Twine variables"; } if ($postField) { $curl = curl_init(); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $postField); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD, "***:***"); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, falst); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json', 'Accept: application/json', 'Connection: close')); curl_setopt($curl, CURLOPT_URL, $rebURL); curl_exec($curl); curl_close($curl); } ?>
I am sure some of you PHP experts out there can whip up something cleaner using specific PHP libraries to make it easier to pass in the other JSON elements like recipients and handling. In fact, that is what I am hoping:)
I think that just about covers it. My Twine can now detect temperature, moisture, door state and other issues, and it can send me carrier grade voice, SMS, email, fax (haha... but yes, seriously) and any other format supported by xMatters on demand:
Now go get your Twine and have some fun. Oh, and if you have better PHP code, hook me up!