#!/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','Prakash Kumar D','prakash.kumard@hp.com'); } if($help) { print "This plugin is used for testing the Clearcase service on 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; ----------