Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Pure Perl Big Brother and Nagios clients: ideas? code bits?

by dwm042 (Priest)
on Apr 24, 2012 at 16:38 UTC ( #966895=perlquestion: print w/ replies, xml ) Need Help??
dwm042 has asked for the wisdom of the Perl Monks concerning the following question:

A really sharp architect named Jeremy Bumpus once showed me that it was straightforward to write a script that could speak with a Big Brother server, and thus do tests independent of the BB client. The advantage, of course, is that you don't have to jump through hoops to get the bb user to run tests that only a privileged user should. The code uses IO::Socket, which has been a part of every Perl I've tested, even stripped down system Perls.

A bit of test code (half pseudocode) might look something like this:
my $bbhost = $ENV{BBHOST}; my $machine = `hostname`; chomp($machine); if ( -f $bbhost/etc/bbaliasname ) { # fetch aliasname and assign it to machine. } # $test would be the name of the test as BB displays it. my $test = "app"; # green, yellow and red are alert levels. my $color = 'green'; # # run test here, reset color if necessary # my $conn = new IO::Socket::INET ( PeerAddr => 'my_bb_server.domain.biz', PeerPort => '1984', Proto => 'tcp', ) || warn("Cannot create socket to port 1984 on localhost\n"); my $date = `date`; print $conn "status $machine.$test $color $date "; print $conn "test blah blah blah.\n"; print $conn "moretestinfo"; close($conn);

The cool thing about this test is that it can be run on servers that don't have a compiler (the ordinary BB client install requires cc and make), leading to the notion that the whole bb-local client piece could be replaced with a pure Perl solution on servers for which, for business reasons, you can't install a compiler and for which you have no dev or QA systems to compile from.

And since I've written some tests of this kind for Big Brother, it's making me wonder how much of this technology is transferrable to Nagios. Yes, things aren't entirely thought out or thought through, and I'm fishing for ideas here, particularly from the Perl enabled folks who might understand Nagios client to server protocols.

All I'm trying to do is push some useful tests across a broad heterogenous enterprise, where the monitoring solution in place can go from Big Brother to Big Sister to free Nagios to commercial Nagios to Icinga to Zenoss. Some Perl tools for Joe Admin would be appreciated.

Thanks!

David

Comment on Pure Perl Big Brother and Nagios clients: ideas? code bits?
Download Code
Re: Pure Perl Big Brother and Nagios clients: ideas? code bits?
by sam_bakki (Pilgrim) on Apr 25, 2012 at 05:47 UTC

    Hi

    Few years back, I wrote Nagios plugins in pure perl. Which monitors Clearcase source code management system, NFS share avilability , etc etc.. plugins

    Writing Nagios plugin is actually simple, Read their docs

    Bellow is a working script for Nagios

    #!/usr/bin/perl -w #check_clearcase.pl use lib "/opt/nagios/plugins"; use NagiosUtils; use Getopt::Long; $SIG{ALRM} = sub { die "TIMEOUT" }; my $albd=0; my $mvfs=""; my @allvobs; my @umvobs; my $mu=0; my $vob; my $sview; my @ps; my $version; my $help; my $TIMEOUT = 40; my $process; GetOptions('help|?' => \$help,'version' => \$version); if($version) { NagiosUtils::print_revision('check_clearcase.pl','1.0','Prakas +h Kumar D','prakash.kumard@hp.com'); } if($help) { print "This plugin is used for testing the Clearcase service o +n the specific host,\n"; print "from where the script is executed\n\n"; NagiosUtils::print_usage('Usage: check_clearcase.pl check_clearcase.pl --help | --? | -h check_clearcase.pl --version | -v Options: -v, --version Print version,Author and contact e-mail information -h, --help|--? Print the Detailed Usage options'); } unless(@ps=`ps -ef`) { print "Could not get process tree"; exit ($ERRORS{'UNKNOWN'}); } foreach $process(@ps) { # checking for albd server if($process =~/albd_server/) { #print "albd_server is Running\n"; #$msg.= "albd_server is Running,"; $albd=1; last; } } if ($albd == 0) { print "albd_server is Not Running"; exit ($ERRORS{'CRITICAL'}); } # checking for MVFS file system is mounted eval { alarm ($TIMEOUT); $mvfs=`ls -d /view` || die "/view Not Found"; alarm (0); }; #print "Return=$@\n"; if($@) { if($@ =~/view Not Found/) { print "/view is not mounted. Problem with MVFS"; exit ($ERRORS{'CRITICAL'}); } if($@ =~/TIMEOUT/) { print "/view check TIMEOUT"; exit ($ERRORS{'CRITICAL'}); } else { print "$!"; exit ($ERRORS{'UNKNOWN'}); } } # checking wheather All Vobs are Mounted eval { alarm ($TIMEOUT); @allvobs=`/usr/atria/bin/cleartool lsvob` or die "NO Vobs Found"; alarm (0); }; #print "Return=$@\n"; if ($@) { if($@ =~/NO Vobs Found/) { print "VOBs are NOT Mounted"; exit ($ERRORS{'CRITICAL'}); } if($@ =~/TIMEOUT/) { print "VOB Check TIMED OUT"; exit ($ERRORS{'CRITICAL'}); } else { print "$!"; exit ($ERRORS{'UNKNOWN'}); } } #if ($um == 1) #{ # print $#umvobs+1," Vob(s) NOT Mounted"; # exit ($ERRORS{'CRITICAL'}); #} # Check for cc_test View which is created in CBM eval { alarm ($TIMEOUT); $sview=`/usr/atria/bin/cleartool startview cc_test 2>&1`; alarm (0); }; #print "VIEW=$sview\n"; if ($sview) { print "Clearcase setview is not working"; exit ($ERRORS{'CRITICAL'}); } if($@ =~/TIMEOUT/) { print "Setview TIMEOUT"; exit ($ERRORS{'CRITICAL'}); } foreach $vob(@allvobs) { if($vob =~/^\*/) { push(@umvobs,$vob); $mu++; } } print "ClearCase OK,",$#allvobs+1," Vobs are mounted."; exit ($ERRORS{'OK'}); ------------ NagiosUtils.pm package NagiosUtils; use Exporter; @ISA= qw(Exporter); @EXPORT=qw($TIMEOUT %ERRORS &print_revision &usage); ## Global Variables %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=> +4); # print_revision ('plugin name','Plug in version','Author name','mail- +id') sub print_revision ($$$$) { my $commandName = shift @_; my $pluginRevision = shift @_; my $author=shift @_; my $email=shift @_; print "$commandName: $pluginRevision\n"; print "Author: $author\n"; print "Email: $email\n"; exit $ERRORS{'UNKNOWN'}; } sub print_usage ($) { my $usage_string=shift @_; print $usage_string,"\n"; exit $ERRORS{'UNKNOWN'}; } 1; ----------

    Thanks & Regards,
    Bakkiaraj M
    My Perl Gtk2 technology demo project - http://code.google.com/p/saaral-soft-search-spider/ , contributions are welcome.

Re: Pure Perl Big Brother and Nagios clients: ideas? code bits?
by JavaFan (Canon) on Apr 25, 2012 at 08:32 UTC
    It's been over 5 years since I worked with Nagios, but what I remember of it is that writing plugins is easier than trivial (of course, collecting the data you want to monitor may be difficult). All a plugin needs to do is writing 4 lines to STDOUT. It's trivial enough that for some plugins, Perl would be overkill: a few lines of bash will do.
Re: Pure Perl Big Brother and Nagios clients: ideas? code bits?
by pklausner (Scribe) on Apr 25, 2012 at 18:10 UTC
    The closest to your BB interface above is the Nagios Service Check Acceptor NSCA. It accepts a plain text format on a TCP socket. Besides the binary send_ncsa there is Net::NSCA::Client, which I do _not_ know.

    But keep in mind that pure passive checks are a bit at odds with Nagios' state polling philosophy. If you are not allowed to add an agent like NRPE or the excellent check_mk, you may consider check_by_ssh. Since years OpenSSH offers the ControlMaster option to re-use existing connections. Without the very expensive key exchange phase, the transfer performance is not much different from raw TCP such as with NRPE. It just needs a bit of thought with your templates to coordinate master and slave.

Re: Pure Perl Big Brother and Nagios clients: ideas? code bits?
by pileofrogs (Priest) on Apr 25, 2012 at 20:01 UTC

    The best thing I ever did with Nagios was defining my tests in the test and not in the nagios server.

      I hope this is not too much to ask, but can you provide a complete example please.

      My guess is this is no small feat for you, but I would really like to simplify checks. I'll leave it up to you as to how to provide a complete example, but beg you to do so in any form.

      Very funny Scotty... Now PLEASE beam down my PANTS!

        Sorry, I've been away for a time. I doubt this is still something you need, but what the hey.

        I use s system where H2 tags mean a test name and H3 tags mean an expected value and a dynamic value sooo

        <h1>My Tests</h1> <p>Heres some text that my parser will ignore!</p> <h2>SSI ENABLED</h2> <h3>foobarbaz</h3> <h3><!--#echo "foobarbaz" --></h3> <h2>SSI EXEC PROHIBITED</h2> <h3>[error: exec forbidden]</h3> <h3><!-- #exec cmd="echo Holy Crap" --></h3>

        Writing the parser as a nagios module is an exercise left up to the reader...

        Also, the SSI above is made-up and won't really work.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://966895]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2014-09-23 15:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (227 votes), past polls