use strict;
use Time::Local;
# C O N F I G U R A B L E V A R I A B L E S
# Where the BBHOME is
# ---------------------------------------------------
my($bbhome) = "/usr/local/bb";
# Where to find the history logs to analyze
my($histdir) = "$bbhome/bbvar/hist";
# Where to get history external to Big Brother
my($exthistfile) = "$bbhome/bbvar/ext/sla-report/history.txt";
# The name of your configfile
# ---------------------------
my($configfile) = "$bbhome/bb/ext/sla-report/sla-report.cfg";
# Web-stuff
# ---------
my($webdir) = "$bbhome/bb/web";
my($webheader) = $webdir . "/bb_header";
my($webfooter) = $webdir . "/bb_footer";
# Data structures
# %apps will contain the break down of applications from the config file:
# $apps{GROUPNAME}->{COMPONENTS}->{COMPONENTNAME}->{HOSTS}->(array of hosts)
# {TESTS}->(array of tests)
# {TESTINFO}->{TESTNAMES host.test format}->{STATUS} known test
# {TOTAL_GREEN} Actual uptime of test
# {SW}->(array of service windows)
# {DEPENDS}->(array of dependencies)
# {TYPE}->[USER|SYSTEM|CORE]
# {TOTAL_TIME} = Total of expected uptime of component
# {TOTAL_GREEN}= Total of actual uptime of component
# {TOTAL_TIME} = Total of expected uptimes of each USER component
# {TOTAL_GREEN}= Total of actual uptime of each USER component
my(%apps);
# %components_by_test will be a reverse lookup of test (hostname.test format)
# to an array of ($apps{GROUPNAME}->{COMPONENTNAME}, GROUPNAME, COMPONENTNAME)
my(%components_by_test);
# %events_by_app will be a hash of arrays. Linking appname to a list of
# all events (including servicewindow events)
my(%events_by_app);
# %ext_events_by_test will be a hash keyed by test of all the events from an external
# history file
my(%ext_events_by_test);
my($debug)=0;
# cgi is set to 1 if this script was called from a web server
my($cgi)=0;
# -------------------------------------------------------------------
my($query);
if ( $ENV{'SERVER_SOFTWARE'} ) {
$cgi = 1;
use CGI;
$query = new CGI;
}
else {
$cgi = 0;
}
# get date from localtime
my(@date) = localtime();
# localtime returns the month as 0-11, Ugh
$date[4]++;
my($date) = scalar localtime();
# Month name to number hash
my(%months) = ( "Jan" => 1,
"Feb" => 2,
"Mar" => 3,
"Apr" => 4,
"May" => 5,
"Jun" => 6,
"Jul" => 7,
"Aug" => 8,
"Sep" => 9,
"Oct" => 10,
"Nov" => 11,
"Dec" => 12);
# select_app is a regular expression that will allow users to report only on selected
# applications
my($select_app)="/.*/";
#Use the dates given on the command line to find what period to look at
my ($todate, $fromdate);
if ( ! $cgi ) {
if ( $ARGV[0] ) {
$fromdate = $ARGV[0];
}
else {
$fromdate = "01.01.2002.00.00.00";
}
if ( $ARGV[1] ) {
$todate = $ARGV[1];
}
else {
$todate = sprintf("%02d.%02d.%04d.%02d.%02d.%02d",$date[3],
$date[4],
$date[5]+1900,
$date[2],
$date[1],
$date[0]
);
}
# Allow the user to select a specific app to report on
# This can be a regular expression to select multiple apps
if ( $ARGV[2] ) {
$select_app = $ARGV[2];
}
if ( $ARGV[3] ) {
$debug = $ARGV[3];
}
}
else {
if ( $cgi && $query->param('start-mon') ) {
$fromdate = $query->param('start-day') . "." .
$months{$query->param('start-mon')} . "." .
$query->param('start-yr')
;
}
else {
$fromdate = "01.01.2002.00.00.00";
}
if ( $cgi && $query->param('end-mon') ) {
$todate = $query->param('end-day') . "." .
$months{$query->param('end-mon')} . "." .
$query->param('end-yr')
;
}
else {
$todate = sprintf("%02d.%02d.%04d.%02d.%02d.%02d",$date[3],
$date[4],
$date[5]+1900,
$date[2],
$date[1],
$date[0]
);
}
if ( $query->param('select_app') ) {
$select_app = $query->param('select_app');
}
}
# if the // start and end the select_app string, then assume its a regular expression,
# otherwise assume an exact match and append the ^ and $ chars to force the regex interpreter
# to do the right thing
if ($select_app =~ /^\/(.*)\/$/) {
$select_app = $1;
} else {
$select_app = "^" . $select_app . "\$";
}
my($fromts, $tots) = &find_period_ts($fromdate, $todate);
if ( $tots > time()) { $tots=time(); }
&read_config;
&read_ext_history;
&read_history;
&analyze_apps;
if ( $cgi ) {
&print_web_results;
}
else {
&print_results;
}
exit;

Rispondi quotando