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.


In reply to Re: Pure Perl Big Brother and Nagios clients: ideas? code bits? by sam_bakki
in thread Pure Perl Big Brother and Nagios clients: ideas? code bits? by dwm042

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.