Tuesday, July 15, 2014

Raspberry Pi Powered Siren of Shame via Node.js

If you have a spare Raspberry Pi sitting around (and who doesn't) or are seeking an excuse to buy that newly released Model B+ model with 4 USB ports, then have you considered combining it with a Siren of Shame to hassle your build breaking office mates whether you're at the office or not?  If that sounds good this article is for you.

Getting Started


You'll need a Siren of Shame device and a Raspberry Pi that's running and connected to the Internet.  Element14 has a great getting started set of videos if you're completely new to Raspberry Pi.  This post used the Raspbian OS, but theoretically it shouldn't matter what OS you use.

libusb


Libusb provides an API for applications to interface with USB devices, including Human Interface Devices (HID) such as the Siren of Shame.  To install libusb use apt-get (the universal Linux installer).

If this is a new Raspberry Pi with a fresh install of Linux then you will need to update your list of available packages with

sudo apt-get update

Follow that up with:

sudo apt-get install libusb-dev

You should now be able to run lsusb from the command line to list devices.  Plug in a Siren of Shame, run lsusb, and you should get a device with an id of 16d0:0646 called GrauTec.  It should look like:

lsusb

...
Bus 001 Device 011: ID 16d0:0646 GrauTec

If your device doesn't show up, it could be an issue with the cable.  Andy Lowry, who has an excellent blog post where he lights up his siren of shame when freight trains are near, reports that he had to try several cables before finding one that worked.

Node.js


Thanks exclusively to Joe Ferner and his node-sos-device project we have a solution for connecting Siren of Shame's to linux using Node.js.  To install Node.js it should be as easy as:

sudo apt-get install nodejs
sudo apt-get install npm

Incidentally, rather than using node-sos-device directly, we will be using the higher-level node-sos-client, which knows how to monitor Jenkins and Bamboo CI servers.

Node-sos-client


If you haven't configured your device to work with git you could do it the right way with SSH and generate an ssh key or you could just:

git clone https://github.com/AutomatedArchitecture/node-sos-client.git

and

cd node-sos-client

Next you'll need to download all Node dependencies.  If this is a fresh install you'll need to tell the node package manager (npm) where to retrieve dependencies from:

npm config set registry http://registry.npmjs.org/

Now you can install all dependencies for node-sos-client by running

npm install

Upgrading Node


For some fortunate users (Andy Lowry for one) installing node via apt-get works fine.  If, however, you get an error about node being out of date you'll have to uninstall, download, and update your path.

First, to uninstall the old version of node:

sudo apt-get remove npm
sudo apt-get remove node

No download and unpack:

cd ~
wget http://nodejs.org/dist/v0.10.2/node-v0.10.2-linux-arm-pi.tar.gz
tar -xvzf node-v0.10.2-linux-arm-pi.tar.gz

To add it to your path

nano .bashrc

And add the following two lines at the bottom:

NODE_JS_HOME=/home/pi/node-v0.10.2-linux-arm-pi
PATH=$PATH:$NODE_JS_HOME/bin

If you restart your command prompt and type node --version you should get v0.10.2.

Now retry npm install.

cd node-sos-client
npm install

And you should be good to go.

Running node-sos-client


First make a copy of the default configuration file:

cp config.json.example config.json

We'll configure it correctly later.  Next pick up the dependency on node-sos-device by running:

npm install sos-device

To run the app you should be able to run

sudo node build/sos-client.js

However, if you had to install node with the wget method, then you'll need to run

sudo $NODE_JS_HOME/bin/node build/sos-client.js

If you're lucky you'll see the app print out the device stats as json and a configuration error, something like:

deviceInfo: { version: 1,
  hardwareType: 1,
  hardwareVersion: 1,
  externalMemorySize: 0,
  audioMode: 0,
  audioPlayDuration: 0,
  ledMode: 0,
  ledPlayDuration: 0,
  ledPatterns:
   [ { id: 2, name: 'On/Off' },
     { id: 3, name: 'Fade' },
     { id: 4, name: 'Chase' },
     { id: 5, name: 'Fade Chase' } ],
  audioPatterns:
   [ { id: 1, name: 'Sad Trombone' },
     { id: 2, name: 'Ding!' },
     { id: 3, name: 'Plunk' } ] }
Failed to poll: bamboo0 { [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }

However, if you have a cable that doesn't work well, or are connecting through a non-powered USB hub you may see:

Error: usb_detach_kernel_driver_np: -113 could not detach kernel driver from interface 0: No route to host

In this case try experimenting with the way you connect the device to the Pi.

Configuring the Connection

Today node-sos-client can connect to two CI servers: Bamboo, and Jenkins.  To connect to Jenkins update the config file to something like:

{
  "builds": [
    {
      "type": "jenkins",
      "config": {
        "url": "http://127.0.0.1/jenkins/api/json/",
        "username": "[username]",
        "password": "[password]"
      }
    }
  ]
}

And you're done.  With any luck running sudo node build/sos-client.js will light the siren and sound the speaker on initial connection, and whenever the build breaks.

Summary


And now you too can terrorize your build breaking colleagues, even when you're not at the office.  Enjoy!

Saturday, April 19, 2014

Released 2.2.0

Today we released Siren of Shame 2.2.0, adding some good stuff including the #1 most requested feature:

Custom Audio Sounds 


"Sounds", it's a new option in the menu:


Click it to add/delete/preview MP3's or WAV's:


Then configure rules to play them:


With per-user rules and our fancy rule engine you can now taunt co-workers by name when they break the build.  How cool is that?

Visual Studio Online


If you're into TFS (by choice or divine mandate) and using the Microsoft-hosted cloud version (previously called Team Foundation Services) we now have your back.  See Configuring Visual Studio Online for details.

Keyboard Shortcuts


If you're a keyboard kind of person (and what self-respecting developer isn't?) you'll appreciate the following new keyboard shortcuts:

  • 1-9 - Go to the build detail page for the appropriate build
  • Backspace - Go to the home page
  • Alt+1-9 - Go to the the user detail page for the appropriate user
  • F - Go full-screen

Bug Fixes

  • Can now treat unstable as passing for Jenkins (Issue #30)
  • When new users are added, the leaders tab now immediately updates (Issue #26) 
  • Fixes an issue with Team City authentication 
  • Fixes a bug with users that have comma's in their user names 
  • Fixes a bug with hidden users 
  • Fixes some issues with build dates (thank you @mightymuke) 
  • Fixed authentication issues in Travis 
  • Fixed issue #48 typo 
  • Fixed a bug with user mappings (thank you @gregorycu) 
  • Improved pretty date calculations 

Configuring Visual Studio Online for Siren of Shame

As of Siren of Shame 2.2.0 we now support Visual Studio Online (previously Team Foundation Services).

You will need to configure Visual Studio Online to enable authentication from Siren of Shame.  To do this:

1. Log in to Visual Studio Online
2. Edit your Profile



3. Click Credentials and select "Enable alternate credentials"



4. Enter a username and password
5. When you add a server in Siren of Shame the URL should be https://[myproject]/visualstudio.com/, and the username/password should be what you entered in alternate authentication credentials


Sunday, January 5, 2014

My CI Gets Localized

We recently talked with a Siren of Shame user who proudly announced that Siren of Shame was the second app they installed on their new smartphone.  Naturally we asked: "So what did you think?" to which they sheepishly responded "Um, it installed".

The problem was that the Siren of Shame app (Android in this case, but all the apps work the same way) showed global leader boards and global news.  The user could see the state of their builds, and the push notifications were nice, but they wanted localized gamification data.  They wanted to know their reputation within their team and to see news relevant to their project rather than competing with a bunch of people they didn't know.

Today we are proud to announce two new features for My CI customers that help make data more localized and relevant.

My CI News Feed


First, My CI customers now get news on their My CI page.  In fact, the page should look nearly identical to the Siren of Shame desktop app itself. The My CI page used to look like this:


And now the My CI page looks like this:


Better?  We think so, but feel free to respond in the comments.

Localized Mobile Apps


The second feature we want to announce is that effective immediately all mobile apps including Android, iPhone, Windows Phone, and Windows 8 now will show localized news and leader boards if you're signed up for My CI.  For instance here is the iPhone news feed, complete with check-in comments aggregated across build definitions:



The Leaders page looks similar in that only those individuals listed above will be shown.

Summary


We hope you enjoy the new localized data.  Please post in the comments if you feel we're headed in the right direction (or not) because there is more great stuff to come along these lines in 2014 (hint: it's called Team CI and it's nearly ready).

Saturday, June 29, 2013

How to Add Support for a new CI Server to Siren of Shame

Siren of Shame supports eight CI servers today, but adding additional ones is pretty easy.  Read on if you you're interested in adding support for achievements, reputation, or push notifications to mobile devices to your favorite CI server.

Architecture Overview

We use a plugin model to interact with CI server's via the Managed Extensibility Framework (MEF).  The main project (SirenOfShame.csproj) looks in the \plugins directory to find class libraries (.dll's) that export classes (via MEF's ExportAttribute) that inherit from ICiEntryPoint.  Theoretically you could export multiple CiEntryPoints per assembly, but we only do one per C# project to separate concerns.

If you'd like to start with a reference project for either reading through or copying, consider checking out HudsonServices.csproj as it is one of our more mature plugins.

ICiEntryPoint

public interface ICiEntryPoint
{
   
ConfigureServerBase CreateConfigurationWindow(
        SirenOfShameSettings settings,
       
CiEntryPointSetting ciEntryPointSetting
        );

    string Name { get; }

    string DisplayName { get; }

    WatcherBase GetWatcher(SirenOfShameSettings settings);

}

 

The ICiEntryPoint interface requires a Name and DisplayName.  Name (e.g. "Hudson") is used extensively in a user's persisted settings as an ID.  It is never displayed to a user, and should never be changed.

DisplayName (e.g. "Hudson/Jenkins") is displayed in the dropdown of available CI servers in the Add CI Server dialog and may be changed over time if necessary.

SirenOfShame calls ICiEntryPoint's CreateConfigurationWindow() when a user adds an instance of a new build definition to watch.  It should return a class that inherits from ConfigureServerBase, which in turn inherits from UserControl.  The control will be embedded in a windows forms page when a user selects the associated CI server on the add CI server dialog or goes to edit an existing CI server.  This form should be used to allow a user to connect to a CI server, select the build definitions to watch, and optionally persist a username and password.  For example:

public ConfigureServerBase CreateConfigurationWindow(
   
SirenOfShameSettings settings,
   
CiEntryPointSetting ciEntryPointSetting) {


   
return new ConfigureHudson(settings, this, ciEntryPointSetting);

}

Finally, GetWatcher() is called when the system starts watching CI servers (e.g. after adding a CI server, or on startup).  Its job is to instantiate and return a class that inherits from WatcherBase whose job is to handle polling for build status changes.  For example:

public WatcherBase GetWatcher(SirenOfShameSettings settings) {

    return new HudsonWatcher(settings, this);

}

WatcherBase 

Pretty must the only responsibility of WatcherBase that's important is overriding:

protected override IList<BuildStatus> GetBuildStatus();

This method is called very frequently by the rules engine (RulesEngine.cs) to check for build status changes.  It is is expected to retrieve the build definitions that the user is watching and return a BuildStatus for each one.  It could utilize a separate class, such as one that inherits from ServiceBase, like HudsonService.cs does, but this isn't strictly necessary.

The build engine is run on a background thread, to free up the UI thread, but it does call GetBuildStatus synchronously.  Consequently any long delays inside GetBuildStatus decrease the frequency that users get build statuses.  For example if the user has set the polling interval as 10 seconds and GetBuildStatus takes 10 seconds to run then the user actually gets build statuses every 20 seconds.  For this reason it might be a good idea to request build statuses for each build definition in parallel like HudsonService.cs does:

public IList<HudsonBuildStatus> GetBuildsStatuses(
       
string rootUrl,
       
string userName,
       
string password,
       
BuildDefinitionSetting[] watchedBuildDefinitions) {

    rootUrl = GetRootUrl(rootUrl);

   
var parallelResult = from buildDefinitionSetting in watchedBuildDefinitions
                        
select GetBuildStatus(rootUrl, buildDefinitionSetting, userName, password);
   
return parallelResult.AsParallel().ToList();
}

At any time GetBuildStatus() can throw ServerUnavailableException to indicate that something is temporarily wrong (e.g. the web connection is down or the server is down for maintenance).  In response the main engine will notify the user and continue polling the server periodically until the situation has resolved itself.  If you choose the overload with an exception, the user will be given the opportunity to click on the error message and send the result back to us for diagnosis.

Next Steps

If you have any questions feel free to e-mail us at support at our domain name.  And once you get it working we hope you'll consider initiating a pull request from our GitHub project.

Saturday, June 1, 2013

Released 2.1.1

In the excitement of announcing My CI we forgot to announce what else is new with versions 2.1 and 2.1.1.

Merge Duplicate Users

This oft-requested feature allows you to merge two users that are actually the same person.  Frequently this occurs for those monitoring multiple CI servers.  To perform a merge right-click on the user:



Then select who to merge that user with:


Notice the caveats above.  Specifically the system will not attempt to merge any previous check-ins, reputation, achievements, or stats.  However, the system will merge these going forward.

My CI

Again, as mentioned in our previous post 2.1 enables My CI, where you can get push notifications to mobile phones, a dedicated page on our site with your build information, and e-mails about build status changes and new achievements. 

If you were a beta user of 2.1, then 2.1.1:
  • Sync's users and their reputation, achievements and stats up to My CI
  • Sync's in-progress builds

Other Features

  • Full Screen mode now displays dates as pretty dates (e.g. 5 minutes ago).
  • Improved pretty date calculations

Bugs Fixed

  • The system was excessively updating the tray icon (Issue #16)
  • Full screen mode was displaying dates with incorrect time zone (Issue  #9)
  • Fixed a bug where the Jon Skeet achievement was too easy to get (Issue #42)
  • Fixed various smaller anonymously submitted bugs including null reference exceptions

Thursday, May 30, 2013

Introducing My CI: Turn a Smart Phone Into a Siren of Shame

Today we're proud to release a new, free, service called My CI and in conjunction Siren of Shame 2.1.1 (see also our official 2.1.1 release nodes).

Why?

Continuous integration can be awesome.  It can significantly improve quality on projects.  But incorporating it into daily life for the entire team can be hard.  It ultimately only works if everyone on a team is both aware of the state of the build, and is actively engaged in fixing it when it breaks.

We built My CI to help team leads achieve both ends: generate awareness, while encouraging everyone to fix broken builds; hopefully while making things a little more fun along the way.

What Is It?

My CI is a service that you turn on from our desktop software (2.1.1 or later) to enable some new features. First, it allows anyone to turn a smart phone or tablet into a mini Siren of Shame.  Second, it enables e-mail build notifications with fun user stats and updates about new teammates' achievements.  Finally, it turns on a customized web page we host on our website that displays your team's real time build status, build history, and team member stats like reputation, achievements, CSB, and FSB.

We have a pretty new webpage on our site to describe My CI at a high level here, but read on if you're interested in details.


Turn On My CI

Enabling My CI is easy.  After you pick up the Siren of Shame 2.1.1 desktop software, create an account, open up the SoS Online settings page and turn on My CI like this:


Or, if you use Travis to monitor a Github project you can add the account directly from the My CI page and we'll monitor it for you.  The only downside is we do not yet support achievements and reputation for projects monitored from our server.



Your My CI Page

Once you've enabled My CI you can log onto http://sirenofshame.com/myci and you should see something like the following:




Your builds are on the left with most recent check-in comments, author, and build status.

Notice the team members listed on the right with their baseball card stats including Consecutive Successful Builds (CSB), Fail %, # of Times Fixed Someone else's Build (FSB), Total Builds (T), Reputation, and achievement counts.

We designed this view to be something you could throw up on a projector or put on a dedicated monitor from a machine that isn't running the desktop software.  We hope your team will find the baseball card stats to be motivating and add an element of friendly competition.

If you click on a user you can view individual achievements earned:


If you click on a build from the My CI page you can view build history:



Email Notifications

Typically an e-mail from a build server is bad news.  Wouldn't it be nice if your build failed e-mails contained a silver lining?



Or wouldn't it be nice to occasionally pass on good news to your teammates?



Mobile Sirens of Shame

We saved the best for last.  We now have apps for just about every smartphone and tablet.  We have apps for


Push Notifications

Now when the build breaks we send push notifications to your device(s).  You'll get a modal dialog that pops up with who broke the build and their check-in comments.  In Android you'll get build updates to your notification area.  In Windows 8 and Windows Phone you'll get live tile updates with recent check-in details.



Badges

In iPhone, Windows Phone and Win8 if any of the builds your monitor are broken we'll throw a badge on the Siren of Shame icon to show a count of broken builds without even needing to open the app.


Build Status, Leaders, News

When you open the app you can see all of your builds.  In Android it looks like this.


You can drill down to view recent check-ins.



We also show news from the Siren of Shame leader board like this in iOS:



Or the leaders from the Siren of Shame leaderboard like this in Windows Phone.



Summary
We hope you enjoy this new service.  We've got some big plans for it in the works, so stay tuned in here, on Facebook, or on twitter.  And as always please feel free to add comments we'd love to hear your feedback.