Nagios, Belkin WeMo and a Plasma Globe
266
post-template-default,single,single-post,postid-266,single-format-standard,bridge-core-3.0.1,qodef-qi--no-touch,qi-addons-for-elementor-1.5.3,qode-page-transition-enabled,ajax_updown,page_not_loaded,,vertical_menu_enabled,side_area_uncovered_from_content,qode-theme-ver-28.7,qode-theme-bridge,disabled_footer_top,qode_header_in_grid,wpb-js-composer js-comp-ver-6.8.0,vc_responsive,elementor-default,elementor-kit-6

Nagios, Belkin WeMo and a Plasma Globe

Nagios, Belkin WeMo and a Plasma Globe

Plasma GlobeI monitor a number of servers using nagios and I always thought it would be neat to be able to have some sort of ambient device light up when there was a critical problem.

Yes, I get email and text alerts, and nagios is always up in one tab on my browser, but I wanted to have something there in the periphery of my vision just as an extra queue. Well a couple of years ago I got a small plasma globe and it’s really cool, but I wasn’t using it much just by itself. So it occurred to me that it would be the perfect device to have light up when nagios detected a problem. I’ve been wanting to do this for the longest time but it wasn’t until Belkin came out with WeMo that I figured out how to do it and it was pretty easy.

I plugged the plasma globe into a WeMo Switch and configured the switch with the free WeMo iPhone app. Then I created the following Perl script that I call nagios_wemo.pl:

#!/usr/bin/perl
use warnings;
use strict;

# Get the following packages from CPAN
use WebService::Belkin::WeMo::Discover;
use WebService::Belkin::WeMo::Device;

# Create connection to my WeMo switch
my $wemo = WebService::Belkin::WeMo::Device->new(ip => '192.168.1.13', db => '/etc/belkin.db');

# Grab HTML of Nagios status page
my $html = `curl --user nagiosadmin:<password> --silent 'http://<my-server>/nagios/cgi-bin/status.cgi?host=all'`;

# Look for serviceTotalsCRITICAL or hostTotalsCRITICAL
if ($html =~ m/(serviceTotalsCRITICAL|hostTotalsCRITICAL)/i ) {
$wemo->on();
} else {
$wemo->off();
}

Then I added the script to my crontable:

* * * * * /Users/thomas/code/nagios_wemo.pl

Now, any time a server or service goes critical, the plasma globe turns on, and when the problem is resolved, it turns off.

I used Perl for the script, but you could also just use a shell script such as this one here.



Mastodon