Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by sam_bakki (Monk)
on Apr 25, 2012 at 05:47 UTC ( #966994=note: print w/ replies, xml ) Need Help??


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

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.


Comment on Re: Pure Perl Big Brother and Nagios clients: ideas? code bits?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://966994]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (13)
As of 2014-08-27 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (233 votes), past polls