ASNMTAP
view release on metacpan or search on metacpan
applications/display-test.pl view on Meta::CPAN
#!/usr/bin/env perl
# ----------------------------------------------------------------------------------------------------------
# © Copyright 2003-2011 Alex Peeters [alex.peeters@citap.be]
# ----------------------------------------------------------------------------------------------------------
# 2011/mm/dd, v3.002.003, display-test.pl for ASNMTAP::Asnmtap::Applications::Display
# ----------------------------------------------------------------------------------------------------------
use strict;
use warnings; # Must be used in test mode only. This reduces a little process speed
#use diagnostics; # Must be used in test mode only. This reduces a lot of process speed
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
BEGIN { if ( $ENV{ASNMTAP_PERL5LIB} ) { eval 'use lib ( "$ENV{ASNMTAP_PERL5LIB}" )'; } }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
use DBI;
use File::stat;
use Time::Local;
use Getopt::Long;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
use ASNMTAP::Time v3.002.003;
use ASNMTAP::Time qw(&get_datetimeSignal &get_hour &get_timeslot);
# because it is not yet exported by the ASNMTAP::Asnmtap::Applications::Display module
use ASNMTAP::Asnmtap::Applications v3.002.003;
use ASNMTAP::Asnmtap::Applications qw($SERVERTABLDISPLAYDMNS $SERVERTABLPLUGINS $SERVERTABLTIMEPERIODS $SERVERTABLVIEWS);
use ASNMTAP::Asnmtap::Applications::Display v3.002.003;
use ASNMTAP::Asnmtap::Applications::Display qw(:APPLICATIONS :DISPLAY :DBDISPLAY &encode_html_entities);
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
use vars qw($opt_H $opt_V $opt_h $opt_C $opt_P $opt_D $opt_L $opt_t $opt_c $opt_T $opt_l $PROGNAME);
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$PROGNAME = "display.pl";
my $prgtext = "Display for the '$APPLICATION'";
my $version = do { my @r = (q$Revision: 3.002.003$ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r }; # must be all on one line or MakeMaker will get confused.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
my $checklist = "DisplayCT"; # default
my $htmlOutput = $HTTPSPATH .'/nav/index/index'; # default
my $pagedir = 'index'; # default
my $pageset = 'index'; # default
my $debug = 0; # default
my $loop = 0; # default
my $trigger = 0; # default
my $creationTime; # default
my $displayTime = 1; # default
my $lockMySQL = 0; # default
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
my $displayTimeslot = 0; # only for extra debugging information
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub print_help ();
sub print_usage ();
Getopt::Long::Configure('bundling');
GetOptions (
"V" => \$opt_V, "version" => \$opt_V,
"h" => \$opt_h, "help" => \$opt_h,
"H=s" => \$opt_H, "hostname=s" => \$opt_H,
"C:s" => \$opt_C, "checklist:s" => \$opt_C,
"P:s" => \$opt_P, "pagedir:s" => \$opt_P,
"D:s" => \$opt_D, "debug:s" => \$opt_D,
"L:s" => \$opt_L, "loop:s" => \$opt_L,
"t:s" => \$opt_t, "trigger:s" => \$opt_t,
"c:s" => \$opt_c, "creationTime:s" => \$opt_c,
"T:s" => \$opt_T, "displayTime:s" => \$opt_T,
"l:s" => \$opt_l, "lockMySQL:s" => \$opt_l
);
if ($opt_V) { print_revision($PROGNAME, $version); exit; }
if ($opt_h) { print_help(); exit; }
($opt_H) || usage("MySQL hostname/address not specified\n");
my $serverName = $1 if ($opt_H =~ /([-.A-Za-z0-9]+)/);
($serverName) || usage("Invalid MySQL hostname/address: $opt_H\n");
if ($opt_C) { $checklist = $1 if ($opt_C =~ /([-.A-Za-z0-9]+)/); }
if ($opt_P) { $pagedir = $opt_P; }
if ($opt_D) {
if ($opt_D eq 'F' || $opt_D eq 'T') {
$debug = ($opt_D eq 'F') ? 0 : 1;
} else {
usage("Invalid debug: $opt_D\n");
}
}
if ($opt_L) {
if ($opt_L eq 'F' || $opt_L eq 'T') {
$loop = ($opt_L eq 'F') ? 0 : 1;
if ($opt_c) {
if ($opt_c =~ /^20\d\d-(?:0\d|1[0-2])-(?:[0-2]\d|3[0-1]) (?:[0-1]\d|2[0-3]):[0-5]\d:[0-5]\d$/) {
$creationTime = $opt_c;
} else {
usage("Invalid creation time <YYYY-MM-DD HH:MM:SS>: $opt_c\n");
}
applications/display-test.pl view on Meta::CPAN
sub read_tableSoundStatusCache {
my ($checklist, $debug) = @_;
%tableSoundStatusCache = ();
if (-e "$APPLICATIONPATH/tmp/$checklist-sound-status.cache") {
my $rvOpen = open(READ, "$APPLICATIONPATH/tmp/$checklist-sound-status.cache");
if ($rvOpen) {
while (<READ>) {
chomp;
if ($_ ne '') {
my ($key, $value) = split (/=>/, $_);
$tableSoundStatusCache { $key } = $value;
}
}
close(READ);
if ($debug) {
print "$APPLICATIONPATH/tmp/$checklist-sound-status.cache: READ\n";
print "-->\n";
while ( my ($key, $value) = each(%tableSoundStatusCache) ) { print "'$key' => '$value'\n"; }
print "<--\n";
}
}
}
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub write_tableSoundStatusCache {
my ($checklist, $debug) = @_;
my $rvOpen = open(WRITE, ">$APPLICATIONPATH/tmp/$checklist-sound-status.cache");
if ($rvOpen) {
print "\n$APPLICATIONPATH/tmp/$checklist-sound-status.cache: WRITE\n-->\n" if ($debug);
while ( my ($key, $value) = each(%tableSoundStatusCache) ) {
print WRITE "$key=>$value\n";
print "'$key' => '$value'\n" if ($debug);
}
close(WRITE);
print "<--\n" if ($debug);
}
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub do_crontab {
my ($Cenvironment) = @_;
$pagedir = $pagedirOrig;
$pagedir .= "/$Cenvironment" unless ($Cenvironment eq 'P');
my $directory = $HTTPSPATH .'/nav/'. $pagedir;
create_dir ($directory) unless ( -e "$directory" );
$htmlOutput = $directory .'/'. $pageset;
$rvOpen = open(HTML, ">$htmlOutput.tmp");
unless ( $rvOpen ) {
print "Cannot open $htmlOutput.tmp to create the html information\n";
exit 0;
}
$rvOpen = open(HTMLCV, ">$htmlOutput-cv.tmp");
unless ( $rvOpen ) {
print "Cannot open $htmlOutput-cv.tmp to create the html information\n";
exit 0;
}
$rvOpen = open(HTMLMCV, ">$htmlOutput-mcv.tmp");
unless ( $rvOpen ) {
print "Cannot open $htmlOutput-mcv.tmp to create the html information\n";
exit 0;
}
$prevGroep = '';
my $dstatusMessage;
my $creationDate;
if ( defined $creationTime ) {
my ($date, $time) = split (/ /, $creationTime);
my ($year, $month, $day) = split (/-/, $date);
my ($hour, $minute, $seconds) = split (/:/, $time);
$creationDate = timelocal ( $seconds, $minute, $hour, $day, $month-1, $year-1900 );
printHtmlHeader( $APPLICATION .' - '. $ENVIRONMENT{$Cenvironment} .' from '. $CATALOGID .' ('. scalar(localtime($creationDate)) .')' );
} else {
$creationDate = time();
printHtmlHeader( $APPLICATION .' - '. $ENVIRONMENT{$Cenvironment} .' from '. $CATALOGID );
}
$rv = 1;
$dbh = DBI->connect("DBI:mysql:$DATABASE:$serverName:$SERVERPORTREADWRITE", "$SERVERUSERREADWRITE", "$SERVERPASSREADWRITE") or $rv = errorTrapDBI($checklist, "Cannot connect to the database");
if ($lockMySQL) {
if ($dbh and $rv) {
$lockString = 'LOCK TABLES ' .$SERVERTABLEVENTS. ' READ';
$dbh->do ( $lockString ) or $rv = errorTrapDBI($checklist, "Cannot dbh->do: $lockString");
}
}
$configNumber = $playSoundStatus = 0;
$doChecklist = ($dbh and $rv) ? 1 : 0;
$emptyFullView = $emptyCondencedView = $emptyMinimalCondencedView = 1;
if ($doChecklist) {
my %inMCV = ();
$inMCV{WARNING}{CRITICAL} = 1;
$inMCV{WARNING}{UNKNOWN} = 1;
$inMCV{WARNING}{DEPENDENT} = 1;
$inMCV{CRITICAL}{WARNING} = 1;
$inMCV{CRITICAL}{UNKNOWN} = 1;
applications/display-test.pl view on Meta::CPAN
my $InIMW;
my ($year, $month, $day) = split (/[-\/]/, $endDate);
if (defined $year and defined $month and defined $day) {
my $Year = $year-1900;
my $Month = $month-1;
my $wDay = (localtime( timelocal( 0, 0, 0, $day, $Month, $Year ) ))[6];
my $timeperiodes = ( exists $$catalogID_uKey_timeperiodID{$catalogID}->{$uniqueKey}->{SDE_IMW}->{$wDay} ) ? $$catalogID_uKey_timeperiodID{$catalogID}->{$uniqueKey}->{SDE_IMW}->{$wDay} : $$timeperiodID_days{$catalogID}->{$$catalogID_uKey_timeperio...
if ($debug) {
# (localtime)[6]: weekday Number of days since Sunday (0 - 6)
my %WDAYS = ('0'=>'sunday','1'=>'monday','2'=>'tuesday','3'=>'wednesday','4'=>'thursday','5'=>'friday','6'=>'saturday');
print "catalogID: $catalogID, uniqueKey: $uniqueKey, year: $year, month: $month, day: $day, wDay: $wDay, ". $WDAYS{$wDay} .", timeperiodes: $timeperiodes\n";
print "catalogID_uKey_timeperiodID: ". $$catalogID_uKey_timeperiodID{$catalogID}->{$uniqueKey}->{ASNMTAP} ."\n";
}
for my $timeperiode (split (/,/, $timeperiodes)) {
my ($from, $to) = split (/-/, $timeperiode);
if ( defined $from and defined $to ) {
$to =~ s/24:00/23:59/g;
print "$from, $to\n" if ($debug);
my ($from_hour, $from_min) = split (/:/, $from);
my ($to_hour, $to_min) = split (/:/, $to);
if ( defined $from_hour and defined $from_min and defined $to_hour and defined $to_min ) {
print "$from_hour, $from_min, $to_hour, $to_min\n" if ($debug);
my $from_time = timelocal(0, $from_min, $from_hour, $day, $Month, $Year );
my $to_time = timelocal(59, $to_min, $to_hour, $day, $Month, $Year );
if ( defined $from_time and defined $to_time ) {
$InIMW = ( ( $from_time <= $timeslot and $timeslot <= $to_time ) ? 1 : ( ( defined $InIMW ) ? $InIMW : 0 ) );
if ($debug) {
print "$from_time, $timeslot, $to_time\n";
print scalar (localtime($from_time)), "\n";
print scalar (localtime($timeslot)), "\n";
print scalar (localtime($to_time)), "\n";
print "$InIMW !\n";
}
}
}
}
}
$InIMW = 1 unless (defined $InIMW);
} else {
$InIMW = 1;
}
return ($InIMW);
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub printHtmlHeader {
my $htmlTitle = shift(@_);
print_header (*HTML, $pagedir, "$pageset-cv", $htmlTitle, "Full View", 60, "ONLOAD=\"startRefresh(); initSound();\"", 'T', "<script type=\"text/javascript\" src=\"$HTTPSURL/overlib.js\"><!-- overLIB (c) Erik Bosrup --></script>", undef);
print HTML '<TABLE WIDTH="100%">', "\n";
print_header (*HTMLCV, $pagedir, "$pageset-mcv", $htmlTitle, "Condenced View", 60, "ONLOAD=\"startRefresh(); initSound();\"", 'T', "<script type=\"text/javascript\" src=\"$HTTPSURL/overlib.js\"><!-- overLIB (c) Erik Bosrup --></script>", undef);
print HTMLCV '<TABLE WIDTH="100%">', "\n";
print_header (*HTMLMCV, $pagedir, "$pageset", $htmlTitle, "Minimal Condenced View", 60, "ONLOAD=\"startRefresh(); initSound();\"", 'T', "<script type=\"text/javascript\" src=\"$HTTPSURL/overlib.js\"><!-- overLIB (c) Erik Bosrup --></script>", undef...
print HTMLMCV '<TABLE WIDTH="100%">', "\n";
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub printGroepHeader {
my ($title, $show) = @_;
if ($show) {
$groupFullView = $groupCondensedView = 0;
delete @multiarrayFullCondensedView[0..@multiarrayFullCondensedView];
}
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub printStatusHeader {
my ($title, $configNumber, $emptyFullView, $emptyCondencedView, $emptyMinimalCondencedView, $playSoundStatus) = @_;
my ($emptyFullViewMessage, $emptyCondencedViewMessage, $emptyMinimalCondencedViewMessage);
if ( $configNumber ) { # Monitored Applications
if ( $emptyFullView ) {
$emptyMinimalCondencedViewMessage = $emptyCondencedViewMessage = $emptyFullViewMessage = 'Contact ASAP the server administrators, probably collector/config problems!';
} else {
$emptyCondencedViewMessage = 'All Monitored Applications are OK' if ( $emptyCondencedView );
$emptyMinimalCondencedViewMessage = 'All Monitored Applications are OK' if ( $emptyMinimalCondencedView );
}
} elsif ( $emptyFullView and $emptyCondencedView and $emptyMinimalCondencedView ) {
if ( $doChecklist ) {
$emptyMinimalCondencedViewMessage = $emptyCondencedViewMessage = $emptyFullViewMessage = 'No Monitored Applications';
} else {
$emptyMinimalCondencedViewMessage = $emptyCondencedViewMessage = $emptyFullViewMessage = 'Contact ASAP the server administrators, probably database problems!';
}
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if (defined $emptyFullViewMessage) {
print HTML '<TR><TD class="StatusHeader" COLSPAN="', $colspanDisplayTime, '"><BR><H1>', $emptyFullViewMessage, '</H1></TD></TR>', "\n", '</TABLE>', "\n";
} else {
print HTML '<TR><TD class="StatusHeader" COLSPAN="', $colspanDisplayTime, '">', $STATUSHEADER01, '</TD></TR>', "\n", '</TABLE>', "\n";
}
print_legend (*HTML);
print HTML '<TABLE WIDTH="100%">', "\n";
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if (defined $emptyCondencedViewMessage) {
print HTMLCV '<TR><TD class="StatusHeader" COLSPAN="', $colspanDisplayTime, '"><BR><H1>', $emptyCondencedViewMessage, '</H1></TD></TR>', "\n", '</TABLE>', "\n";
} else {
print HTMLCV '<TR><TD class="StatusHeader" COLSPAN="', $colspanDisplayTime, '">', $STATUSHEADER01, '</TD></TR>', "\n", '</TABLE>', "\n";
}
print_legend (*HTMLCV);
print HTMLCV '<TABLE WIDTH="100%">', "\n";
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
applications/display-test.pl view on Meta::CPAN
<title>$APPLICATION @ $BUSINESS</title>
<META HTTP-EQUIV="Expires" CONTENT="Wed, 10 Dec 2003 00:00:01 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<META HTTP-EQUIV="Refresh" CONTENT="60">
<link rel="stylesheet" type="text/css" href="$HTTPSURL/asnmtap.css">
</HEAD>
<BODY>
EOM
print PNG '<IMG SRC="', $RESULTSURL, '/', $resultsdir, '/', $command, '-', $catalogID_uniqueKey, '-sql.png"></BODY></HTML>', "\n";
close(PNG);
} else {
print "Cannot create $htmlFilename!\n";
}
}
}
my ($posTokenFrom, $posTokenTo, $groep, $test, $serverID);
$posTokenFrom = index $title, '[';
if ($posTokenFrom eq -1) {
$groep = '';
$test = $title;
} else {
$posTokenTo = index $title, ']', $posTokenFrom+1;
$groep = substr($title, $posTokenFrom, $posTokenTo+2);
$test = substr($title, $posTokenTo+2);
}
$posTokenFrom = index $test, ' {';
if ($posTokenFrom eq -1) {
$serverID = '';
} else {
$posTokenTo = index $test, '}', $posTokenFrom+2;
$serverID = substr($test, $posTokenFrom+2); chop ($serverID);
$test = substr($test, 0, $posTokenFrom);
}
# http://www.bosrup.com/web/overlib/?Command_Reference
my $_exclaim = '';
if (-s "$APPLICATIONPATH/custom/sde.pm") {
require "$APPLICATIONPATH/custom/sde.pm";
$_exclaim .= printRelationshipsSDE( $serverName, $checklist, $catalogID, $uniqueKey );
}
if (-s "$APPLICATIONPATH/custom/cartography.pm") {
require "$APPLICATIONPATH/custom/cartography.pm";
$_exclaim .= printLinkToCartography( $serverName, $checklist, $catalogID, $uniqueKey );
}
# debug: toggleDiv(), pop-up: overlib() & pop-down: nd()
# onClick: overlib(), onDblClick: nd() & toggleDiv()
$_exclaim = "<TABLE WIDTH=100% BORDER=0 CELLSPACING=1 CELLPADDING=2 BGCOLOR=#000000><TR><TD BGCOLOR=#000080 WIDTH=100 ALIGN=RIGHT>Plugin</TD><TD BGCOLOR=#0000FF>$test</TD></TR>$popup<TR><TD BGCOLOR=#000080 WIDTH=100 ALIGN=RIGHT>Unique Key</TD><TD B...
my $exclaim = '<TD WIDTH="56"><a href="javascript:void(0);" onDblClick="nd(); return toggleDiv(\''.$catalogID_uniqueKey.'\');" onClick="return overlib(\''.$_exclaim.'\', CAPTION, \'Exclaim\', STICKY, CLOSECLICK, CAPCOLOR, \'#000000\', FGCOLOR, \'#...
my $_comment = ( defined $comment ? 'onmouseover="return overlib(\''.$comment.'\', CAPTION, \'Comments\', STICKY, CLOSECLICK, CAPCOLOR, \'#000000\', FGCOLOR, \'#000000\', BGCOLOR, \''.$COLORS{$statusOverlib}.'\', HAUTO, VAUTO, WIDTH, 692, OFFSETX, ...
my $comments = '<a href="'. $HTTPSURL .'/cgi-bin/comments.pl?pagedir='.$pagedir.'&pageset='.$pageset.'&debug=F&CGICOOKIE=1&action=listView&catalogID='.$catalogID.'&uKey='.$uniqueKey.'" target="_self" '.$_comment.'><IMG SRC="...
my $helpfile = (defined $help and $help eq '1') ? '<A HREF="'. $HTTPSURL .'/cgi-bin/getHelpPlugin.pl?pagedir='.$pagedir.'&pageset='.$pageset.'&debug=F&CGICOOKIE=1&catalogID='.$catalogID.'&uKey='.$uniqueKey.'" target="_self"><IMG...
$checkOk = $checkSkip = $printCondensedView = $problemSolved = $verifyNumber = 0;
$inProgressNumber = -1;
$itemFullCondensedView = ' <TR>'."\n".' '.$exclaim.$comments.$helpfile."\n";
if ( $catalogID ne $CATALOGID or defined $creationTime ) {
$itemFullCondensedView .= ' <TD class="ItemHeader">'.$groep. encode_html_entities('T', $test) .'</TD>'. "\n";
} else {
$itemFullCondensedView .= ' <TD class="ItemHeader">'.$groep.'<A HREF="#" class="ItemHeaderTest" onClick="openPngImage(\''. $RESULTSURL .'/'. $resultsdir .'/'. $command .'-'. $catalogID_uniqueKey ."-sql.html',912,576,null,null,'ChartDirector',1...
}
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub printGroepCV {
my ($title, $showGroup, $showFooter) = @_;
if ($showGroup and $title ne '') {
if ($groupFullView) {
$emptyFullView = ( scalar ( @multiarrayFullCondensedView ) ? 0 : 1 );
unless ( $emptyFullView ) {
print HTML '<TR><TD class="GroupHeader" COLSPAN=', $colspanDisplayTime, '>', encode_html_entities('T', $title), '</TD></TR>', "\n";
foreach my $arrayFullCondensedView ( @multiarrayFullCondensedView ) {
print HTML @$arrayFullCondensedView[4];
}
}
print HTML '<tr style="{height: 4;}"><TD></TD></TR>', "\n", if $showFooter;
}
if ($groupCondensedView) {
$emptyCondencedView = ( scalar ( @multiarrayFullCondensedView ) ? 0 : 1 );
unless ( $emptyCondencedView ) {
@multiarrayFullCondensedView = ( sort { $a->[2] <=> $b->[2] } @multiarrayFullCondensedView );
@multiarrayFullCondensedView = ( sort { $b->[0] <=> $a->[0] } @multiarrayFullCondensedView );
@multiarrayFullCondensedView = ( sort { $a->[3] <=> $b->[3] } @multiarrayFullCondensedView );
@multiarrayFullCondensedView = ( sort { $a->[1] <=> $b->[1] } @multiarrayFullCondensedView );
print HTMLCV '<TR><TD class="GroupHeader" COLSPAN=', $colspanDisplayTime, '>', encode_html_entities('T', $title), '</TD></TR>', "\n";
foreach my $arrayFullCondensedView ( @multiarrayFullCondensedView ) {
print HTMLCV @$arrayFullCondensedView[4] if ( @$arrayFullCondensedView[5] );
}
}
print HTMLCV '<tr style="{height: 4;}"><TD></TD></TR>', "\n", if $showFooter;
}
}
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub printItemStatus {
my ($interval, $number, $status, $endTime, $acked, $timeslot, $activationTimeslot, $suspentionTimeslot, $instability, $persistent, $downtime, $suspentionTimeslotPersistentTrue, $suspentionTimeslotPersistentFalse, $catalogID_uniqueKey, $catalogID, $...
my $statusIcon = ($acked and ($activationTimeslot - $step < $timeslot) and ($suspentionTimeslot > $timeslot)) ? ( $instability ? $ICONSUNSTABLE {$status} : $ICONSACK {$status} ) : $ICONS{$status};
( run in 0.954 second using v1.01-cache-2.11-cpan-39bf76dae61 )