ginger technological blog header information panel

ServerGrid Door Entry Integration with Paxton Net2 and Atlassian HipChat

Published: November 18th 2014

Revisiting my ServerGrid server monitoring system recently I considered some of the extendability previously discussed with the Hubot Servergrid Scripts. I wondered if I could undertake some HipChat integration whilst at the same time collecting information from a locked-down door entry system.

The RFID Paxton Net2 system stores data on a Windows box by default, in a SQL Server instance. To begin with I considered writing some software that connected to the SQL server directly to get events out, however I noticed that there's the ability within the Net2 software to drive events out of the system.

Forming a plan

Now, the way I saw it I had the opportunity using these event tasks to get myself out of writing some PHP to SQL Server software at the same time as getting out of having to write Visual Studio style software. My hopes sank a little to begin with when I realised the Net2 system only allows EXE file launching upon events.

Curl to the rescue

So here came the cunning plan - use a Curl executable to connect to an intermediary system that can collect the event-driven data from door entry box and then push data to HipChat via their own API. The problem comes with providing options to the executable (as an aside I found a way to completely bomb the Net2 system by accidentally providing the full curl call in the "File Open" dialogue for selecting the exe to launch.

The way around this was to write a batch file that could be converted to an executable file - this would need to be undertaken for each user on the door entry system unfortunately in order to get personlised data and messages. Each batch file is a simple affair, calling an API end point much like the one I built on the Hubot system:

c:\curl.exe http://servergridbox/api/doorEntry.php/SomeAPIKeyForServerGrid/token/Person_Name/Door_Name/

Obviously, the Person_Name and Door_Name items are changed to the corresponding values to the doors and people that you want to notify about. The SomeAPIKeyForServerGrid is obviously a key you choose to communicate with your ServerGrid API
For my case, I'm simply tracking the primary front door and I'm not bothering with internal doors. In your case you might want to notify for specific doors like your server room or the main programming area.

Due to the fact the Net2 system doesn't allow .bat files to be operated I have to use a BAT to EXE converter ( I used the system to undertake this ). Once I have all of my user exe files built up I am able to create a new trigger based on the authentication of a user on a particular door.

ServerGrid API Side

Having created my curl exe files I need to create the end point for ServerGrid - I'm also going to include the HipChat API mechanism available from The HipChat Github site. This is version 1 of the API and it is becoming deprecated - you might want to consider swinging to API v2 - note that if you are not the administrator of the system you will have to ask one to create a notification token for the version 1 API (by default all user tokens now only work with v2 API).

I'm taking in a person's name and a door name for my API - I'll auto-generate the date/time stamp when the item is inserted into the database so I need to create a simple controller with a save class and an API end point:

API Code Snippet

The primary processing part of the API ( based on the Hubot example on this blog ). In this code I've provided a variety of witty messages to integrate with the user and door collection data. You can change these as necessary and drop them to more straight-laced items as required.

 $ObjDoor = new doorEntry();

 // a range of different phrases to be chosen at random to make announcements more friendly
 $responseItems = array(" opened the ",
 " rocked through the ",
 " sneaked in via the ",
 " ran through the ",
 " shook hands with the ",
 " used his magic token on the ",
 " swiped entry on the ",
 " iiiiinn thuh houuuuuse , swaggering via the ",
 " just waltzed in via the ",
 " just walked in the ",
 " barged through the ",
 " , a new contender, entered the arena via the ",
 " bypassed security on the ",
 " swooped in via the ",
 " entered combat via the "
 // select which random one to use
 $chosenResponse = $responseItems[rand(0,14)];

 $returnResponse = "";
 // check for token entry request
 if($b == "token"){
 // token swipe add door item
 $storeDoor = $ObjDoor->storeRecord($c,$d);
 if($storeDoor === true){
  $returnResponse = "Event Stored";
  $myMessage = str_replace("_"," ",$c).$chosenResponse.str_replace("_"," ",$d);

  // set your V1 API token
  // instantiate
  $hc = new HipChat\HipChat($token);
  // run the message announcement
  try {
   // modify the first item of this to the room name and the second one to the oname of the notifier as necessary    $hc->message_room('Chat', 'DoorBot', $myMessage, true, purple);
  } catch (HipChat\HipChat_Exception $e) {
   echo "Oops! Error: ".$e->getMessage();
  $returnResponse = "Event could not be stored.";

 echo $returnResponse;

Controller for Door system

Does all the main processing called from the API end point

 class doorEntry extends serverGrid{

 * Store the door access event
 public function storeRecord($staff_name, $door_name)
 // Replace underscores with spaces
 $staff_name = str_replace("_"," ",$staff_name);
 $door_name = str_replace("_"," ",$door_name);
 // run the insert into the DB
 $sql = "INSERT INTO
 // run and respond with logging
 $addDoorEvent = db::execute($sql);
  $action = "Inserting door event for ".db::escapechars($staff_name)." , on door ".db::escapechars($door_name);
  $this->logevent('Remove Server', $action);
  return true;
  $action = "Error inserting door entry item: ".$sql;
  $this->logevent('Door Entry Event', $action);
  return false;


Testing and putting together

Putting this all together, the Net2 system receives an authentication from it's reader. This fires off a Curl request to our ServerGrid API. This in turn then logs the activity and send off an API call to the HipChat system which displays the notification in the Chat room. The only thing left is to try a token on your system and see if it all fires up!

Our system now displays a notification when people enter via the main door which helps keep track of who is in the building and hopefully once the extra doorbell is installed we'll be able to program a notification directly into HipChat to warn that someone is at the door!

Happy hacking!

Next Item.. Securing the Internet of Things

Previous Item.. Hubot Servergrid Scripts