📜 ⬆️ ⬇️

LED Continuous Integration Server Status Monitor

The active implementation of Jenkins based servers (fork Hudson) in the company Continuous Integraion gave rise to a lot of talk about the “red lamp” - the usual such lamp that would stand in front of the development manager and signal if the build was unsuccessful. Interest took up, and at the weekend passed from words to deeds. As a result, such a device turned out:


What it can do:


It was built on the basis of the popular platform Arduino (more precisely, its equally popular clone - Seeeduino).
')
The basic concept of the device is simple:
  1. A program is started on the working machine that listens to the status of the specified Jenkins projects;
  2. When the status changes, the program sends a certain signal via the UART (via the Serial Port, also known as the COM port) to the Arduino;
  3. Arduino receives a signal and turns on the corresponding LED in the desired mode.


Software part on Arduino


Arduino on board has built-in support for SerialPort, so there are no problems with connecting to a PC. By team
  1. Serial . begin (9600);

listening to the port at the specified frequency is initialized (it is important here that the program running on the computer works with the same frequency in the same mode), and then the command
  1. incomingByte = Serial . read ();

in an infinite loop, the signal from the port is read. Depending on what has come, one of five modes is selected for one of six LEDs:
  1. The last build was successful (green diode);
  2. Assembly in progress (flashing green diode);
  3. The last build was unsuccessful (red diode);
  4. The last build was manually interrupted (red diode);
  5. It is impossible to get a response from the server, or the status is undefined (diode off).

You can make another mode - blinking in turn green-red, if for someone this set of statuses seems insufficient.

To save the conclusions of the Arduino, two-pin red-green LEDs were selected. When current flows in one direction, such a diode glows green, in the opposite direction - red:


We connect it to two Arduino pins (do not forget about the current-limiting resistor) and, exposing low and high potential on these legs, we set the desired operation mode of the LED:

Flashing mode is obtained by alternating the on and off of the LED by timer.

Conclusions 0 and 1 are used for communication via UART, they cannot be used. I limited myself to six indicators, hanging them, respectively, on conclusions 2-13.


If desired, you can use the remaining 6 conclusions of the Arduino, as well as expand the number of indicators, using, for example, shift registers. True, the firmware code will have to be further conjured.

A complete sketch for Arduino can be viewed in the archive with the source code .

Iron part


The iron part of the interface is implemented as an Arduino expansion card - see the photo. The pins are inserted into the connectors, it turns out tough durable design without wires and loops. Convenient and reliable.
The board is made by the LUT method, about which many times already wrote on Habré. A good description in pictures is on the site easyelectronics.ru .
LEDs and current-limiting resistors are used in chip format, but, of course, any will do.



As a “chip”, he erased the name of the projects right on the board. The photograph had to “cover up”, because These are the names of specific customers of our company. You could just write Server01, Server02, etc. But I wanted to make Beautiful :)

Programmed part on PC


The server status monitoring program is written in Perl. In principle, any language that can send signals to SerialPort will do. Which language to use is a matter of taste for everyone.
I note that for Perl I had to install the DeviceSerial (for Mac OS X), Win32-API (for Windows) and Win32-Serial (for Windows) packages.

The main steps of the program:
  1. Connect to SerialPort;
    In Perl, this is done through
    1. my $ port = Win32 :: SerialPort-> new ( "COM8" ); # COM8 - the name of the port in which the device was defined
    2. # For Mac OS X it will be like this: my $ port = Device :: SerialPort-> new ("/ dev / tty.usbserial-A100eEO6");
    3. $ port -> databits (8);
    4. $ port -> baudrate (9600);
    5. $ port -> parity ( "none" );
    6. $ port -> stopbits (1);
  2. In an infinite loop, view the status of the specified service and send the corresponding code via UART.
    Departure is carried out by the team
    1. $ port -> write ( “Any string” );


The most difficult part in Perl for me was setting up a connection to a Jenkins server. We use authorization, and without entering the Perl username / password, the script did not get the desired result. The issue was resolved as follows:
  1. my $ realm = 'Enter you domain credentials' ; # Realm server
  2. my $ user = 'pavel' ; # Username
  3. my $ pass = 'sfD90_df13' ; User password. Of course, not real :)
  4. my $ browser ;
  5. $ browser = LWP :: UserAgent-> new;
  6. $ browser -> credentials ( 'localhost: 443' , $ realm , $ user => $ pass );


The status of the current server status is taken from the Jenkins API. If the project works at
https://localhost/job/Project
then by
https://localhost/job/Project/api/json
In plain text mode, various project information is displayed. We are interested, in particular, in a fragment that begins with a “color”: '.
Jenkins in this place displays the current status. Examples


Through
  1. $ response = $ browser -> get ( $ url ); # where $ url is a direct link to API for json
  2. # For example, https: // localhost / job / Project / api / json

get the content of the page. Next - the matter of technology. We find the necessary fragment and compare it with the known variants of the “color solutions”. If you do not find a known option or the page is not available - extinguish the corresponding LED.

The full Perl code is also available in the source code archive .

Device in operation: www.youtube.com/watch?feature=player_embedded&v=IsgqKsnJ8Uo

Source: https://habr.com/ru/post/117261/


All Articles