"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/Swatch/Actions.pm" between
swatch-3.2.3.tar.gz and swatchdog-3.2.4.tar.gz

About: Swatchdog (Simple WATCHdog) activly monitors log files produced by UNIX’s syslog facility (former name "Swatch").

Actions.pm  (swatch-3.2.3):Actions.pm  (swatchdog-3.2.4)
package Swatch::Actions; package Swatchdog::Actions;
use strict; use strict;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
require Exporter; require Exporter;
@ISA = qw(Exporter AutoLoader); @ISA = qw(Exporter AutoLoader);
# Items to export into callers namespace by default. Note: do not export # Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead. # names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants. # Do not simply export all your public functions/methods/constants.
@EXPORT = qw( @EXPORT = qw(
skipping to change at line 41 skipping to change at line 41
my %args = ( my %args = (
'RINGS' => 1, 'RINGS' => 1,
'DELAY' => 0.2, 'DELAY' => 0.2,
@_ @_
); );
return if exists($args{'WHEN'}) and not inside_time_window($args{'WHEN'}); return if exists($args{'WHEN'}) and not inside_time_window($args{'WHEN'});
return if (exists($args{'THRESHOLDING'}) return if (exists($args{'THRESHOLDING'})
and $args{'THRESHOLDING'} eq 'on' and $args{'THRESHOLDING'} eq 'on'
and not &Swatch::Threshold::threshold(%args)); and not &Swatchdog::Threshold::threshold(%args));
my $bells = $args{'RINGS'}; my $bells = $args{'RINGS'};
for ( ; $bells > 0 ; $bells-- ) { for ( ; $bells > 0 ; $bells-- ) {
print "\a"; print "\a";
sleep($args{'DELAY'}); sleep($args{'DELAY'});
} }
} }
################################################################ ################################################################
# "echo" Action # "echo" Action
skipping to change at line 63 skipping to change at line 63
use Term::ANSIColor; use Term::ANSIColor;
sub echo { sub echo {
my %args = ( my %args = (
'MODES' => [ ], 'MODES' => [ ],
@_ @_
); );
return if (exists($args{'WHEN'}) and not inside_time_window($args{'WHEN'})); return if (exists($args{'WHEN'}) and not inside_time_window($args{'WHEN'}));
return if (exists($args{'THRESHOLDING'}) return if (exists($args{'THRESHOLDING'})
and $args{'THRESHOLDING'} eq 'on' and $args{'THRESHOLDING'} eq 'on'
and not &Swatch::Threshold::threshold(%args)); and not &Swatchdog::Threshold::threshold(%args));
if (${$args{'MODES'}}[0] =~ /^normal$/i) { # for backward compatability if (${$args{'MODES'}}[0] =~ /^normal$/i) { # for backward compatability
print "$args{'MESSAGE'}\n"; print "$args{'MESSAGE'}\n";
} else { } else {
print colored("$args{'MESSAGE'}\n", @{$args{'MODES'}}); print colored("$args{'MESSAGE'}\n", @{$args{'MODES'}});
} }
} }
################################################################ ################################################################
# "exec" Action # "exec" Action
skipping to change at line 95 skipping to change at line 95
$command = $args{'COMMAND'}; $command = $args{'COMMAND'};
} else { } else {
warn "$0: No command was specified in exec action.\n"; warn "$0: No command was specified in exec action.\n";
return 1; return 1;
} }
return 0 if exists($args{'WHEN'}) and not inside_time_window($args{'WHEN'}); return 0 if exists($args{'WHEN'}) and not inside_time_window($args{'WHEN'});
return if (exists($args{'THRESHOLDING'}) return if (exists($args{'THRESHOLDING'})
and $args{'THRESHOLDING'} eq 'on' and $args{'THRESHOLDING'} eq 'on'
and not &Swatch::Threshold::threshold(%args)); and not &Swatchdog::Threshold::threshold(%args));
EXECFORK: { EXECFORK: {
if ($exec_pid = fork) { if ($exec_pid = fork) {
waitpid(-1, WNOHANG); waitpid(-1, WNOHANG);
return 0; return 0;
} elsif (defined $exec_pid) { } elsif (defined $exec_pid) {
exec($command); exec($command);
} elsif ($! =~ /No more processes/) { } elsif ($! =~ /No more processes/) {
# EAGAIN, supposedly recoverable fork error # EAGAIN, supposedly recoverable fork error
sleep 5; sleep 5;
skipping to change at line 128 skipping to change at line 128
# send_email -- send some mail using $MAILER. # send_email -- send some mail using $MAILER.
# #
# usage: &send_email(%options); # usage: &send_email(%options);
# #
################################################################ ################################################################
sub send_email { sub send_email {
my $login = (getpwuid($<))[0]; my $login = (getpwuid($<))[0];
my %args = ( my %args = (
'ADDRESSES' => $login, 'ADDRESSES' => $login,
'SUBJECT' => 'Message from Swatch', 'SUBJECT' => 'Message from Swatchdog',
@_ @_
); );
return if exists($args{'WHEN'}) and not inside_time_window($args{'WHEN'}); return if exists($args{'WHEN'}) and not inside_time_window($args{'WHEN'});
return if (exists($args{'THRESHOLDING'}) return if (exists($args{'THRESHOLDING'})
and $args{'THRESHOLDING'} eq 'on' and $args{'THRESHOLDING'} eq 'on'
and not &Swatch::Threshold::threshold(%args)); and not &Swatchdog::Threshold::threshold(%args));
if (! $args{'MAILER'} ) { if (! $args{'MAILER'} ) {
foreach my $mailer (qw(/usr/lib/sendmail /usr/sbin/sendmail)) { foreach my $mailer (qw(/usr/lib/sendmail /usr/sbin/sendmail)) {
$args{'MAILER'} = $mailer if ( -x $mailer ); $args{'MAILER'} = $mailer if ( -x $mailer );
} }
if ($args{'MAILER'} ne '') { if ($args{'MAILER'} ne '') {
$args{'MAILER'} .= ' -oi -t -odq'; $args{'MAILER'} .= ' -oi -t -odq';
} }
} }
skipping to change at line 192 skipping to change at line 192
$command = $args{'COMMAND'}; $command = $args{'COMMAND'};
} else { } else {
warn "$0: No command was specified in pipe action.\n"; warn "$0: No command was specified in pipe action.\n";
return; return;
} }
return if exists($args{'WHEN'}) and not inside_time_window($args{'WHEN'}); return if exists($args{'WHEN'}) and not inside_time_window($args{'WHEN'});
return if (exists($args{'THRESHOLDING'}) return if (exists($args{'THRESHOLDING'})
and $args{'THRESHOLDING'} eq 'on' and $args{'THRESHOLDING'} eq 'on'
and not &Swatch::Threshold::threshold(%args)); and not &Swatchdog::Threshold::threshold(%args));
# open a new pipe if necessary # open a new pipe if necessary
if ( !$pipe_is_open or $current_command_name ne $command ) { if ( !$pipe_is_open or $current_command_name ne $command ) {
# first close an open pipe # first close an open pipe
close(PIPE) if $pipe_is_open; close(PIPE) if $pipe_is_open;
$pipe_is_open = 0; $pipe_is_open = 0;
open(PIPE, "| $command") open(PIPE, "| $command")
or warn "$0: cannot open pipe to $command: $!\n" && return; or warn "$0: cannot open pipe to $command: $!\n" && return;
PIPE->autoflush(1); PIPE->autoflush(1);
$pipe_is_open = 1; $pipe_is_open = 1;
skipping to change at line 241 skipping to change at line 241
# #
################################################################ ################################################################
sub write_message { sub write_message {
my %args = (WRITE => '/usr/bin/write', my %args = (WRITE => '/usr/bin/write',
@_); @_);
return if exists($args{'WHEN'}) and not inside_time_window($args{'WHEN'}); return if exists($args{'WHEN'}) and not inside_time_window($args{'WHEN'});
return if (exists($args{'THRESHOLDING'}) return if (exists($args{'THRESHOLDING'})
and $args{'THRESHOLDING'} eq 'on' and $args{'THRESHOLDING'} eq 'on'
and not &Swatch::Threshold::threshold(%args)); and not &Swatchdog::Threshold::threshold(%args));
if ($args{WRITE} eq '') { if ($args{WRITE} eq '') {
warn "ERROR: $0 cannot find the write(1) program\n"; warn "ERROR: $0 cannot find the write(1) program\n";
return; return;
} }
if (exists($args{'USERS'})) { if (exists($args{'USERS'})) {
foreach my $user (split(/:/, $args{'USERS'})) { foreach my $user (split(/:/, $args{'USERS'})) {
send_message_to_pipe(COMMAND => "$args{'WRITE'} $user 2>/dev/null", send_message_to_pipe(COMMAND => "$args{'WRITE'} $user 2>/dev/null",
MESSAGE => "$args{'MESSAGE'}\n"); MESSAGE => "$args{'MESSAGE'}\n");
skipping to change at line 305 skipping to change at line 305
1; 1;
__END__ __END__
################################################################ ################################################################
# Perl Documentation # Perl Documentation
################################################################ ################################################################
=head1 NAME =head1 NAME
Swatch::Actions - actions for swatch(1) Swatchdog::Actions - actions for swatchdog(1)
=head1 SYNOPSIS =head1 SYNOPSIS
use Swatch::Actions use Swatchdog::Actions
ring_bell(RINGS => $number_of_times_to_ring, ring_bell(RINGS => $number_of_times_to_ring,
DELAY => $delay_in_seconds, DELAY => $delay_in_seconds,
WHEN => $time_window); WHEN => $time_window);
echo(MESSAGE => 'some text', MODES => @modes); echo(MESSAGE => 'some text', MODES => @modes);
exec(COMMAND => $command_string, exec(COMMAND => $command_string,
WHEN => $time_window); WHEN => $time_window);
=head1 DESCRIPTION =head1 DESCRIPTION
=head1 AUTHOR =head1 AUTHOR
E. Todd Atkins - Todd.Atkins@StanfordAlumni.ORG E. Todd Atkins - Todd.Atkins@StanfordAlumni.ORG
=head1 SEE ALSO =head1 SEE ALSO
swatch(1), Term::ANSIColor(1), perl(1). swatchdog(1), Term::ANSIColor(1), perl(1).
=cut =cut
 End of changes. 11 change blocks. 
11 lines changed or deleted 11 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS