8 print "Arg is not a directory";
11 my $me = basename $dir;
12 my ($status, $details);
16 $command =~ /^(\w+)(\s+(.*))?$/;
17 my ($do, $args) = ($1, $3);
19 open MAIL, '|-', qq!mail -s "$me $status" $args! or die "Could not mail";
20 print MAIL $details,"\n";
22 } elsif ($do eq 'exec') {
24 } elsif ($do eq 'pipe') {
25 open PIPE, '|-', $args;
26 print PIPE "$status\n";
33 my ($checkcommand, $every, %on);
38 open CONFIG, "$dir/check";
40 my @words = split(/\s+/);
41 my $command = shift @words;
42 if ($command eq 'check') {
43 $checkcommand = join(' ', @words);
44 } elsif ($command eq 'on') {
45 my $when = shift @words;
46 if ($when eq 'failure') {
47 push @{$on{failure}}, join(' ', @words);
48 } elsif ($when eq 'success') {
49 push @{$on{success}}, join(' ', @words);
50 } elsif ($when eq 'change') {
51 push @{$on{change}}, join(' ', @words);
53 print "Unknown event in 'on', $dir/check line $.\n";
55 } elsif ($command eq 'every') {
58 print "Unknown command '$command', $dir/check line $.\n";
63 unless ($checkcommand) {
64 print "Check command not specified in $dir/check\n";
67 unless (@{$on{failure}} || @{$on{success}} || @{$on{change}}) {
68 print "No actions specified in $dir/check. This is probably a mistake.\n";
71 open STATUS, "$dir/checkstatus";
72 chomp(my $oldstatus = <STATUS>);
73 my $oldtime = (stat(STATUS))[9];
76 my $td = time() - $oldtime;
78 # Not time to recheck yet
79 #print "Not rechecking; ", $every - $td, " seconds to go.\n";
83 my ($pid, $hung, $exitstatus);
90 $pid = open CHECK, '-|', $checkcommand;
92 $details = join('', <CHECK>);
96 $details = 'Check did not complete within ten seconds';
99 $exitstatus = $? >> 8;
102 if ($exitstatus == 0 && $oldstatus != 0) {
103 do_command($_) foreach @{$on{success}};
105 if ($exitstatus != 0 && $oldstatus == 0) {
106 do_command($_) foreach @{$on{failure}};
108 if ($exitstatus != $oldstatus) {
109 do_command($_) foreach @{$on{change}};
112 open STATUS, ">$dir/checkstatus";
113 print STATUS "$exitstatus\n";
114 print STATUS "$status\n";
115 print STATUS "$details\n";