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, %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";
56 print "Unknown command '$command', $dir/check line $.\n";
61 unless ($checkcommand) {
62 print "Check command not specified in $dir/check\n";
65 unless (@{$on{failure}} || @{$on{success}} || @{$on{change}}) {
66 print "No actions specified in $dir/check. This is probably a mistake.\n";
69 open STATUS, "$dir/checkstatus";
70 chomp(my $oldstatus = <STATUS>);
73 open CHECK, '-|', $checkcommand;
75 $details = join('', <CHECK>);
77 my $exitstatus = $? >> 8;
79 if ($exitstatus == 0) {
80 foreach my $command (@{$on{success}}) {
84 foreach my $command (@{$on{failure}}) {
88 if ($exitstatus != $oldstatus) {
89 foreach my $command(@{$on{change}}) {
94 open STATUS, ">$dir/checkstatus";
95 print STATUS "$exitstatus\n";