#!/usr/bin/perl -w # # Big Brother perl template script # Christian Birchinger # use strict; use Env; #-----------------------------[ initial setup variables ]------------------------------- $ENV{BBHOME} = '/usr/local/bbc' if !$ENV{BBHOME}; my $TEST = "test"; my $STATUS = 'green'; #--------------------------------------------------------------------------------------- my @MANDVARS = qw/BB BBDISP MACHINE/; my %BBENV; my @output; fail ("Big Brother home directory \"$ENV{BBHOME}\" not found.") if ! -d "$ENV{BBHOME}"; fail ("Big Brother default variables \"$ENV{BBHOME}/etc/bbdef.sh\" not found.") if ! -r "$ENV{BBHOME}/etc/bbdef.sh"; chdir $ENV{BBHOME}; my @env = qx|. $ENV{BBHOME}/etc/bbdef.sh;set|; foreach my $el ( @env ) { chomp $el; $el =~ /^\s*(.*?)\s*=\s*(.*)/; my $name = $1; my $valu = $2; $valu = $1 if $valu =~ /^\'(.*)\'$/; $BBENV{$name} = $valu; } foreach (@MANDVARS) { fail ("Mandatory ENV variable \"$_\" not defined.") if ! defined($BBENV{$_}); } #-----------------------------[ custom check script part ]------------------------------ # Example: push additional check result to @output push(@output, "========== $TEST check result =========="); push(@output, ""); push(@output, ""); push(@output, ""); # Example: Update status based on check results. $STATUS = 'green'; #--------------------------------------------------------------------------------------- my $datestr = localtime(); my $outputstr = join("\n", @output); my $statusline = "status $BBENV{MACHINE}.${TEST} ${STATUS} - ${datestr}\n${outputstr}"; # Remove "echo" for real usage system("echo $BBENV{BB} $BBENV{BBDISP} \"$statusline\""); if ($STATUS eq 'green') { exit 0; } else { exit 1; } sub fail { print STDERR "ERROR: $_[0]\n"; exit 1; }