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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.