You are here

Light Up Your Monitoring With Opsview and a Raspberry Pi

Dashboards and reports are brilliant ways to keep an eye on your systems, and an e-mail or ticket straight into your ticketing system lets you know about critical issues. However, nothing can beat a massive flashing light! Make sure none of your alerts are ever missed again by anyone in your office (or a ten block radius for that matter!).

What you will need

Opsview – An install of Opsview, which is set up to monitor whatever it is you really need to know about.

Flashing light – These can easily be found online, ours actually came from an online disco equipment store. Who wouldn’t be keen to getting some disco equipment in the office!



Raspberry Pi – Easy to set up and configure, Raspberry Pi is an affordable credit card–sized single-board computer used to drive your lights.

Remote control sockets – Plugs straight into the Raspberry Pi and can turn on and off your light. Find it here.

Raspberry Pi setup and configuration

First, just plug the plug socket controller into the Raspberry Pi, it fits straight onto the io header.

image 2.png


Plug the light into the remotely controlled socket.

image 3.png

Install an operating system onto the Pi, we used Raspbian. Then, configure networking on the Pi so you can reach it from your Opsview system. You will need access to the internet to download some packages and scripts.

Firstly, on the Pi we need to wirelessly connect the controller board to the remotely controlled socket. Instructions can be found below.

You will need a script on the Pi that can be called by Opsview to turn the light on and off, this is a Perl script that can be triggered by making web calls to the Pi.

To configure the Pi with this script:

  1. Install Apache on the Pi:

# sudo apt-get update

# sudo apt-get install apache

  1. Download the scripts, you can find them here
  2. Install the script on the Pi:

# tar –cvf OpsviewLights.tar –C /usr/lib/cgi-bin/

  1. Configure the file permissions

# chown www-data: www-data /usr/lib/cgi-bin/*

# chmod u+x /usr/lib/cgi-bin/*

  1. To control the Raspberry Pi’s io, you must have elevated access rights so we run the scripts as root, to do this you must add www-data to the sudoers file:

# sudo visudo

And add the entry:

www-data ALL=(ALL) NOPASSWD: /usr/bin/python

You can test the scripts by running them directly on the Pi:

# sudo /usr/bin/python /usr/lib/cgi-bin/

This should turn the lights on.

# sudo /usr/bin/python /usr/lib/cgi-bin/

This should turn the lights off.

To call the CGI script from your web browser:


This should turn the lights on.

http:// <RASPBERRY-PI-IP>/cgi-bin/

This should turn the lights off.

Opsview configuration

First, you will need to add the notification script to your Opsview system.

You can find a copy of the script below.  

  -h - this help text

  -H - The host URL to send to


#ENV VAR for input parameter




# Get the options


    'h'     => \$help_mode,

    'H'     => \$URL,


# Run the subroutines for the options.

if ($help_mode) {





if ($URL) {



else {




sub send_rpi_message {

    require LWP::UserAgent;

    my $req;

    my $ua = LWP::UserAgent->new;

                if ( $ENV{OPSVIEW_SERVICESTATE} ) {

                                $state = $ENV{NAGIOS_SERVICESTATE};


                elsif ( $ENV{NAGIOS_SERVICESTATE} ) {

                $state = $ENV{NAGIOS_SERVICESTATE};


                if ($state eq 'OK') {

                                 $req = HTTP::Request->new(GET => "$URL" . "?Alert=0");


                elsif ($state eq 'WARNING') {

                                 $req = HTTP::Request->new(GET => "$URL" . "?Alert=1");


                elsif ($state eq 'CRITICAL') {

                                 $req = HTTP::Request->new(GET => "$URL" . "?Alert=1");


                elsif ($state eq 'UNKNOWN') {

                                 $req = HTTP::Request->new(GET => "$URL" . "?Alert=1");


                else {

                                print "Error, unknown state";



    my $res = $ua->request($req);

    my $err_line = $res->is_success ? '' : $res->status_line;

    my $err_message = '';

    if ($err_line) {

        $err_message = $res->content;

        print "$err_message\n$URL";



sub usage {

    if ( $_ = shift ) { print "Error: $_\n" }

    print $usage;

    exit 1;


The script needs to be placed in the directory:


The script needs to be owned by the Nagios user:

# chown nagios:nagios /usr/local/nagios/libexec/notifications/

And have read and execute permissions set:

# chmod u+rx /usr/local/nagios/libexec/notifications/

Once the notification script has been created, you can configure the Notification Methods.


To use the new script, add a new notification method by clicking the green cross in the top left hand corner of the notification methods page. Example settings for the new method are shown below:


You will notice that we are using a “Contact Variables” named “RASPBERRY_URL”, this will be the url that we will pass to the notification script so it is able to turn the light on and off. We will configure this variable later in the contact settings.

Next, we configure the Shared Notification Profile by navigating to the Shared Notification Profiles page.



Create a new Shared Notification Profile using the green plus in the top left corner. Give the profile a name, select the role you would like to make the profile available to, and select the notification method in the “Notify by” section. I have named it raspberrypi in this example.


You will then need to select a system to notify against. In this example, I am using a keyword named ServiceCloud.


Here at Opsview, we are using the light to alert us to new tickets coming into our customer success team so we know about them right away. It could be used for any alerts on your systems.

For a complete guide to configuring alerts, read our “Opsview Notifications & Setting Up Alerts” guide.

Lastly, we will apply the notification to one of our Opsview users by navigating to the Contact settings page.


Under the Notifications tab in the contact menu, you can configure the Shared Notification Profiles applied to the user and set the notification variables. Make sure you select the shared notification profile you just set up and then set the “raspberry url” variable. This comes from the Contact Variable we set earlier and should be in the following format:




Run an Opsview reload and your light will be ready to go! If you want to test it, you can “Submit check result” to simulate a system failure.



Now that you have your alerts configured to notify by your Raspberry Pi, you can have your flashing light go off for all kinds of alerts out of your monitoring system. Using the remotely controlled socket, you can even control loads of other things besides lights, you could set up a siren or anything else that will grab your attention. Happy monitoring and enjoy the lights!



Get unified insight into your IT operations with Opsview Monitor

webteam's picture
by Opsview Team,
Opsview is passionately focused on monitoring that enables DevOps teams to deliver smarter business services, faster.

More like this

By Opsview Team, Administrator

In this technical overview we will look at automation and monitoring, and how they can be deployed to work hand-in...

Nagios vs the competion
By Opsview Team, Administrator

A guide on how to execute a smooth transition from Nagios to Opsview. 

Monitoring linux servers
By Opsview Team, Administrator

Opsview's dedicated “service desk module” allows seamless integration with helpdesk software (currently Atlassian’s JIRA, ServiceNow and...