-#!/usr/bin/perl
+#!/usr/bin/env perl
=pod
Examine the Clearadm schedule and perform the tasks required.
+Note that sending the Cleartasks.pl process a sigusr1 will cause it to toggle
+verbose mode.
+
=cut
use strict;
use FindBin;
use Getopt::Long;
+use Sys::Hostname;
use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib";
my $VERSION = '$Revision: 1.25 $';
($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
-my $logfile = "$Clearadm::CLEAROPTS{CLEARADM_LOGDIR}/$FindBin::Script.log";
+my $logfile = "$Clearadm::CLEAROPTS{CLEARADM_LOGDIR}/$FindBin::Script";
+ $logfile =~ s/\.pl$//;
+ $logfile .= '.' . hostname() . '.log';
+
my $pidfile = "$Clearadm::CLEAROPTS{CLEARADM_RUNDIR}/$FindBin::Script.pid";
my $daemon = 1;
my ($clearadm, $clearexec);
-sub HandleSystemNotCheckingIn (%) {
+sub ToggleVerbose() {
+ if (get_verbose) {
+ display 'Turning verbose off';
+ set_verbose 0;
+ } else {
+ display 'Turning verbose on';
+ set_verbose 1;
+ } # if
+} # ToggleVerbose
+
+$SIG{USR1} = \&ToggleVerbose;
+
+sub HandleSystemNotCheckingIn(%) {
my (%system) = @_;
my $startTime = time;
system => $system{name},
);
- my ($err, $msg, $lastid) = $clearadm->AddRunlog (%runlog);
+ my ($err, $msg, $lastid) = $clearadm->AddRunlog(%runlog);
$clearadm->Error ("Unable to add to runlog (Status: $err)\n$msg") if $err;
$systemLink .= "/systemdetails.cgi?system=$system{name}";
my $runlogLink = $Clearadm::CLEAROPTS{CLEARADM_WEBBASE};
$runlogLink .= "/runlog.cgi?id=$lastid";
- my $subject = "System is not responding (Is clearagent running?)";
- $message = <<"END";
+ my $subject = "System is not responding (Is clearagent running?)";
+ $message = <<"END";
<center>
<h1><font color="red">Alert</font> System not responding!</h1>
</center>
clearagent is not setup and running on the system.</p>
END
- $clearadm->Notify (
+ $clearadm->Notify(
$notification{name},
$subject,
$message,
return;
} # HandleSystemNotCheckingIn
-sub SystemsCheckin () {
- foreach ($clearadm->FindSystem) {
+sub SystemsCheckin() {
+ for ($clearadm->FindSystem) {
my %system = %$_;
next if $system{active} eq 'false';
my $startTime = time;
- my $status = $clearexec->connectToServer (
- $system{name},
- $system{port}
- );
+ my $status = $clearexec->connectToServer($system{name}, $system{port});
unless ($status) {
HandleSystemNotCheckingIn %system;
. "$system{name}:$system{port}";
display __FILE__ . " DEBUG: System undefined 1" unless $system{name};
- $clearadm->UpdateSystem (
- $system{name},
- (lastheardfrom => Today2SQLDatetime)
- );
+ $clearadm->UpdateSystem($system{name}, (lastheardfrom => Today2SQLDatetime));
$clearadm->ClearNotifications ($system{name})
if $system{notification} and $system{notification} eq 'Heartbeat';
- } # foreach
+ } # for
return;
} # SystemsCheckin
-sub UpdateRunlog ($$$$) {
+sub UpdateRunlog($$$$) {
my ($status, $startTime, $task, $output) = @_;
my %runlog = (
} # if
} # if
- my ($err, $msg, $lastid) = $clearadm->AddRunlog (%runlog);
+ my ($err, $msg, $lastid) = $clearadm->AddRunlog(%runlog);
- $clearadm->Error ($msg, $err) if $err;
+ $clearadm->Error($msg, $err) if $err;
return $lastid;
} # UpdateRunlog
-sub MakeSystemLink ($) {
+sub MakeSystemLink($) {
my ($system) = @_;
return "$Clearadm::CLEAROPTS{CLEARADM_WEBBASE}/systemdetails.cgi?system="
. $system;
} # MakeSystemLink
-sub MakeLoadavgLink ($) {
+sub MakeLoadavgLink($) {
my ($system) = @_;
return "$Clearadm::CLEAROPTS{CLEARADM_WEBBASE}/plot.cgi?type=loadavg&system="
. "$system&scaling=Hour&points=24";
} # MakeLoadavgLink
-sub ProcessLoadavgErrors ($$$$@) {
+sub ProcessLoadavgErrors($$$$@) {
# TODO: Also need to handle the case where the error was something other
# than "Load average over threshold". Perhaps by having different return
# status. Also, runlog entry #22169 never reported!
my $when = Today2SQLDatetime;
- foreach (@output) {
+ for (@output) {
# We need to log this output. Write it to STDOUT
display $_;
END
$message .= join "\n", @output;
$message .= "</pre>";
- $clearadm->Error ($message, -1);
+ $clearadm->Error($message, -1);
last;
} # if
- $clearadm->Notify (
+ $clearadm->Notify(
$notification,
$subject,
$message,
undef,
$lastid,
);
- } # foreach
+ } # for
return;
} # ProcessLoadAvgErrors
-sub ProcessFilesystemErrors ($$$$@) {
+sub ProcessFilesystemErrors($$$$@) {
# TODO: Also need to handle the case where the error was something other
# than "Filesystem over threshold". Perhaps by having different return
# status.
my %system;
- foreach (@output) {
+ for (@output) {
# We need to log this output. Write it to STDOUT
display $_;
$system{$1} = \%fsinfo;
} # if
} # if
- } # foreach
+ } # for
- foreach my $systemName (keys %system) {
+ for my $systemName (keys %system) {
my @fsinfo;
if (ref $system{$systemName} eq 'HASH') {
push @fsinfo, @{$system{$systemName}};
} # if
- my $systemLink = MakeSystemLink ($systemName);
+ my $systemLink = MakeSystemLink($systemName);
my $subject = 'Filesystem has exceeded threshold';
my $message = <<"END";
<center>
<ul>
END
- foreach (@fsinfo) {
+ for (@fsinfo) {
my %fsinfo = %{$_};
my $filesystemLink = $Clearadm::CLEAROPTS{CLEARADM_WEBBASE};
$filesystemLink .= "/plot.cgi?type=filesystem&system=$systemName";
$message .= "<li>Filesystem <a href=\"$filesystemLink\">";
$message .= "$fsinfo{filesystem}</a> is $fsinfo{usedPct}% full. Threshold is ";
$message .= "$fsinfo{threshold}%</li>";
- } # foreach
+ } # for
$message .= "</ul>";
- $clearadm->Notify (
+ $clearadm->Notify(
$notification,
$subject,
$message,
undef,
$lastid,
);
- } # foreach
+ } # for
return;
} # ProcessFilesystemErrors
-sub NonZeroReturn ($$$$$$) {
+sub NonZeroReturn($$$$$$) {
my ($system, $notification, $status, $lastid, $output, $task) = @_;
my @output = @{$output};
$message .= "</pre></blockquote>";
- $clearadm->Notify (
+ $clearadm->Notify(
$notification,
$subject,
$message,
return;
} # NonZeroReturn
-sub ExecuteTask ($%) {
+sub ExecuteTask($%) {
my ($sleep, %task) = @_;
my ($status, @output, %system, $subject, $message);
. "execute $task{command}";
$status = -1;
} else {
- ($status, @output) = $clearexec->execute ($task{command});
+ ($status, @output) = $clearexec->execute($task{command});
$output[0] = "Unable to exec $task{command} on $system{name}"
if $status == -1;
if ($status != 0) {
if ($notification{cond}
and $notification{cond} =~ /non zero return/i) {
- NonZeroReturn (
+ NonZeroReturn(
$system{name},
$notification{name},
$status,
\%task
);
} elsif ($notification{cond} =~ /loadavg over threshold/i) {
- ProcessLoadavgErrors ($notification{name}, $task{name}, $system{name}, $lastid, @output);
+ ProcessLoadavgErrors($notification{name}, $task{name}, $system{name}, $lastid, @output);
} elsif ($notification{cond} =~ /filesystem over threshold/i) {
- ProcessFilesystemErrors ($notification{name}, $task{name}, $system{name}, $lastid, @output);
+ ProcessFilesystemErrors($notification{name}, $task{name}, $system{name}, $lastid, @output);
} # if
} else {
- $clearadm->ClearNotifications ($task{system});
+ $clearadm->ClearNotifications($task{system});
} # if
- my ($err, $msg) = $clearadm->UpdateSchedule (
+ my ($err, $msg) = $clearadm->UpdateSchedule(
$task{schedulename},
( 'lastrunid' => $lastid ),
);
- $clearadm->Error ($msg, $err) if $err;
+ $clearadm->Error($msg, $err) if $err;
$sleep -= time - $startTime;
} # ExecuteTask
# Main
-GetOptions (
+GetOptions(
'usage' => sub { Usage },
'verbose' => sub { set_verbose },
'debug' => sub { set_debug },
'pidfile=s' => \$pidfile,
) or Usage "Invalid parameter";
-Usage 'Extraneous options: ' . join ' ', @ARGV
- if @ARGV;
+Usage 'Extraneous options: ' . join ' ', @ARGV if @ARGV;
-EnterDaemonMode $logfile, $logfile, $pidfile
- if $daemon;
+EnterDaemonMode $logfile, $logfile, $pidfile if $daemon;
display "$FindBin::Script V$VERSION started at " . localtime;
my ($sleep, @workItems) = $clearadm->GetWork;
- foreach (@workItems) {
+ for (@workItems) {
my %scheduledTask = %{$_};
$scheduledTask{system} ||= 'All systems';
if ($scheduledTask{system} =~ /all systems/i) {
- foreach my $system ($clearadm->FindSystem) {
+ for my $system ($clearadm->FindSystem) {
+ next if $$system{active} eq 'false';
+
$scheduledTask{system} = $$system{name};
$sleep = ExecuteTask $sleep, %scheduledTask;
- } # foreach
+ } # for
} else {
$sleep = ExecuteTask $sleep, %scheduledTask;
} # if
- } # foreach
+ } # for
if ($sleep > 0) {
verbose "Sleeping for $sleep seconds";
sleep $sleep;
} # if
-} # foreach
+} # for
=pod
=begin html
<blockquote>
-<a href="http://clearscm.com/php/cvs_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
-<a href="http://clearscm.com/php/cvs_man.php?file=clearadm/lib/Clearexec.pm">Clearexec</a><br>
-<a href="http://clearscm.com/php/cvs_man.php?file=lib/DateUtils.pm">DateUtils</a><br>
-<a href="http://clearscm.com/php/cvs_man.php?file=lib/Display.pm">Display</a><br>
-<a href="http://clearscm.com/php/cvs_man.php?file=lib/TimeUtils.pm">TimeUtils</a><br>
-<a href="http://clearscm.com/php/cvs_man.php?file=lib/Utils.pm">Utils</a><br>
+<a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
+<a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearexec.pm">Clearexec</a><br>
+<a href="http://clearscm.com/php/scm_man.php?file=lib/DateUtils.pm">DateUtils</a><br>
+<a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
+<a href="http://clearscm.com/php/scm_man.php?file=lib/TimeUtils.pm">TimeUtils</a><br>
+<a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
</blockquote>
=end html