ASNMTAP

 view release on metacpan or  search on metacpan

applications/display.pl  view on Meta::CPAN

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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;
    $inMCV{CRITICAL}{DEPENDENT} = 1;

    $inMCV{UNKNOWN}{WARNING}    = 1;
    $inMCV{UNKNOWN}{CRITICAL}   = 1;
    $inMCV{UNKNOWN}{DEPENDENT}  = 1;

    $inMCV{DEPENDENT}{WARNING}  = 1;
    $inMCV{DEPENDENT}{CRITICAL} = 1;
    $inMCV{DEPENDENT}{UNKNOWN}  = 1;

    $groupFullView = $groupCondensedView = 0;

    foreach $dchecklist (@checklisttable) {
      ($tinterval, $tgroep, $resultsdir, $ttest) = split(/\#/, $dchecklist, 4);
      my @stest = split(/\|/, $ttest);

      my $showGroepHeader = ($prevGroep ne $tgroep) ? 1 : 0;
      my $showGroepFooter = (($prevGroep ne '') && $showGroepHeader) ? 1 : 0;
      printGroepCV($prevGroep, $showGroepHeader, 1);
      $prevGroep = $tgroep;
      printGroepFooter('', $showGroepFooter);
      printGroepHeader($tgroep, $showGroepHeader);

      foreach $dtest (@stest) {
        my ($catalogID_uniqueKey, $title, $test, $help) = split(/\#/, $dtest);

        my ($catalogID, $uniqueKey) = split(/_/, $catalogID_uniqueKey);

        unless ( defined $uniqueKey ) {
          $uniqueKey = $catalogID;
          $catalogID = $CATALOGID;
          $catalogID_uniqueKey = $catalogID .'_'. $uniqueKey unless ( $catalogID eq 'CID' );

applications/display.pl  view on Meta::CPAN

          $timeValue = $lastTimeslot;

          for (; $number <= $NUMBEROFFTESTS; $number++) {
            push (@itemTimelocal, $timeValue);
            push (@itemStatus, ($number == 1) ? 'IN PROGRESS' : 'NO DATA');
            push (@itemStarttime, sprintf ("%02d:%02d:%02d", (localtime($timeValue+$timeCorrectie))[2,1,0]));
            push (@itemTimeslot, $timeValue);
            push (@tempStatusMessage, undef);
            $timeValue -= $step;
          }

          $timeValue = $lastTimeslot;
          $inIMW = 1;

          if ($rv) {
            while (my $ref = $sth->fetchrow_hashref()) {
              $timeslot = ( $step ? int(($lastTimeslot - $ref->{timeslot}) / $step) : 0 );
              print "<", $timeslot, "><", $ref->{title}, "><", $ref->{startTime}, "><", $ref->{timeslot}, ">\n" if ($debug);

              if ($timeslot >= 0) {
                my $dstatus = ($ref->{status} eq '<NIHIL>') ? 'UNKNOWN' : $ref->{status};
	  	          $tstatus = $dstatus;

                if ($dstatus eq 'OK' and $trendline) {
                  my $tSeconden = int(substr($ref->{duration}, 6, 2)) + int(substr($ref->{duration}, 3, 2)*60) + int(substr($ref->{duration}, 0, 2)*3600);
			            $tstatus = 'TRENDLINE' if ($tSeconden > $trendline);
	  		        }

                $itemStatus[$timeslot] = $tstatus;
                $itemStarttime[$timeslot] = $ref->{startTime};
                $itemTimeslot[$timeslot]  = $ref->{timeslot};

                unless ( defined $ref->{perfdata} and $ref->{perfdata} ne '' ) { # remove performance data
                # ($ref->{statusMessage}, undef) = split(/\|/, $ref->{statusMessage}, 2);
                  my $statusMessage = reverse $ref->{statusMessage};
                  my ($_statusMessage, undef) = reverse split(/\|/, $statusMessage, 2);
                  $ref->{statusMessage} = reverse $_statusMessage;
                }

                if ( -e $RESULTSPATH .'/'. $ref->{filename} ) {
                  $ref->{filename} = $RESULTSURL .'/'. $ref->{filename};
                } else {
                  if ( -e $ref->{filename} ) {
                    $ref->{filename} =~ s/^$RESULTSPATH\//$RESULTSURL\//g;
                  } else { # work arround for when switching from ASNMTAP_PATH in mixed environment
                    $ref->{filename} =~ s*^/opt/asnmtap(-3.000.xxx)+/results/*$RESULTSPATH/*g;

                    if ( -e $ref->{filename} ) {
                      $ref->{filename} =~ s/^$RESULTSPATH\//$RESULTSURL\//g;
                    } else {
                      $ref->{filename} = '<NIHIL>';
                    }
                  }
                }

                my $tstatusMessage = ( ( $catalogID ne $CATALOGID or $ref->{filename} eq '<NIHIL>' ) ? encode_html_entities('M', $ref->{statusMessage}) : '<A HREF="'.$ref->{filename}.'" TARGET="_blank">'.encode_html_entities('M', $ref->{statusMessage...
                $statusIcon = ($acked and ($activationTimeslot - $step < $ref->{timeslot}) and ($suspentionTimeslot > $ref->{timeslot})) ? ( $instability ? $ICONSUNSTABLE {$tstatus} : $ICONSACK {$tstatus} ) : $ICONS{$tstatus};

                if ( $timeslot == 0 or $timeslot == 1 ) {
                  my ($year, $month, $day) = split (/-/, $ref->{endDate});
                  my ($hour, $minute, $seconds) = split (/:/, $ref->{endTime});
                  $itemTimelocal[$timeslot] = timelocal ( $seconds, $minute, $hour, $day, $month-1, $year-1900 );
                }

                if ( $timeslot == 0 or ( $timeslot == 1 and $itemStatus[0] eq 'IN PROGRESS' ) ) {
                  $statusOverlib = ( $timeslot ? $itemStatus[1] : $itemStatus[0] );

                  if ($pagedirOrig =~ /^(?:index|test)$/ and -s "$APPLICATIONPATH/custom/cartography.pm") {
                    require "$APPLICATIONPATH/custom/cartography.pm";
                    createGifForCartography( $catalogID_uniqueKey, $statusOverlib );
                  }

                  $inIMW = inIncidentMonitoringWindow ($catalogID, $uniqueKey, $ref->{timeslot}, $ref->{startTime}, $ref->{endTime}, $ref->{endDate}, \%timeperiodID_days, \%catalogID_uKey_timeperiodID, $debug);
                }

                if ($dstatus ne 'OK' and $dstatus ne 'OFFLINE' and $dstatus ne 'NO DATA' and $dstatus ne 'NO TEST') {
                  $tempStatusMessage[$timeslot] = '<IMG SRC="'.$IMAGESURL.'/'.$statusIcon.'" WIDTH="16" HEIGHT="16" BORDER=0 title="'.$tstatus.'" alt="'.$tstatus.'"></TD><TD class="StatusMessage">'.$ref->{startTime}.'</TD><TD class="StatusMessage">'....

                  if ( $timeslot == 0 or ( $timeslot == 1 and $itemStatus[0] eq 'IN PROGRESS' ) ) {
                    $ref->{statusMessage} =~ s/'/`/g;
                    $ref->{statusMessage} =~ s/[\n\r]/<br>/g;
                    $popup .= '<TR><TD BGCOLOR=#000080 WIDTH=100 ALIGN=RIGHT VALIGN=TOP>Status</TD><TD BGCOLOR=#0000FF><IMG SRC='.$IMAGESURL.'/'.$statusIcon.' WIDTH=15 HEIGHT=15 title= alt= BORDER=0> '.$ref->{startTime}.' '.encode_html_entities('M', ...
                  }
                }
              }
            }

            $sth->finish() or $rv = errorTrapDBI($checklist, "Cannot sth->finish: $findString");
          }

          printItemHeader($environment, $resultsdir, $catalogID_uniqueKey, $catalogID, $uniqueKey, $command, $title, $help, $popup, $statusOverlib, $comment);
          $playSoundPreviousStatus = $playSoundInProgress = 0;

          for ($number = 0; $number < $NUMBEROFFTESTS; $number++) {
            my $endTime = $itemStarttime[$number];
            $endTime .= '-'. $itemTimeslot[$number] if ($displayTimeslot);
            printItemStatus($tinterval, $number+1, $itemStatus[$number], $endTime, $acked, $itemTimeslot[$number], $activationTimeslot, $suspentionTimeslot, $instability, $persistent, $downtime, $suspentionTimeslotPersistentTrue, $suspentionTimeslotP...
          }

          for ($number = 0; $number < $NUMBEROFFTESTS; $number++) {
            push (@arrayStatusMessage, $tempStatusMessage[$number] ) if (defined $tempStatusMessage[$number]);
          }

          $itemTitle       = $title;
          $itemStatus      = ( $itemStatus[0] eq 'IN PROGRESS' ) ? $itemStatus[1] : $itemStatus[0];
          $itemTimeslot    = ( $itemStatus[0] eq 'IN PROGRESS' ) ? $itemTimelocal[1] : $itemTimelocal[0];
          $itemStatusIcon  = ( $acked and ( $activationTimeslot - $step < $itemTimeslot ) and ( $suspentionTimeslot > $itemTimeslot ) ) ? 1 : 0;
          $itemInsertInMCV = ( $instability ) ? ( $persistent ? 0 : 1 ) : ( defined $inMCV{$tLastStatus}{$tPrevStatus} ? 1 : 0 );
        }

        printItemFooter($catalogID_uniqueKey, $catalogID, $uniqueKey, $itemTitle, $itemStatus, $itemTimeslot, $itemStatusIcon, $itemInsertInMCV, $inIMW, $itemFullCondensedView, $printCondensedView, \@arrayStatusMessage, \%catalogID_uKey_timeperiodID)...
      }

      print "\n" if ($debug);
    }

    printGroepCV($prevGroep, 1, 0);

    if ($lockMySQL) {
      if ($dbh and $rv) {
        $unlockString = 'UNLOCK TABLES';
        $dbh->do ( $unlockString ) or $rv = errorTrapDBI($checklist, "Cannot dbh->do: $unlockString");

applications/display.pl  view on Meta::CPAN

  }

  # --proxy=user:pasword\@proxy
  if ($parameters =~ /--proxy=/) {
    $parameters =~ s/(--proxy=\w*:)\w*(\@\w+)/$1********$2/g;
  }

  # -p user:pasword\@proxy
  if ($parameters =~ /-p / and ($parameters !~ /-u / and $parameters !~ /--username=/)) {
    $parameters =~ s/(-p \w*:)\w*(\@\w+)/$1********$2/g;
  }

  # --password=
  if ($parameters =~ /--password=/) {
    $parameters =~ s/(--password=)\w+/$1********/g;
  }

  # --username= or -u and --password= or -p (database plugins)
  if ($parameters =~ /-p / and ($parameters =~ /-u / or $parameters =~ /--username=/)) {
    $parameters =~ s/(-p )\w+/$1********/g;
  }

  # --username= or -U and --password= or -P (ftp plugins)
  if ($parameters =~ /-P / and ($parameters =~ /-U / or $parameters =~ /--username=/)) {
    $parameters =~ s/(-P )\w+/$1********/g;
  }

  # j_username= or j_password= (J2EE based Applications)
  if ($parameters =~ /j_username=/ and $parameters =~ /j_password=/) {
    $parameters =~ s/(j_password=)\w+/$1********/g;
  }

  return ($parameters);
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub print_usage () {
  print "Usage: $PROGNAME -H <MySQL hostname> [-C <Checklist>] [-P <pagedir>] [-L <loop>] [-t <trigger>] [-c <YYYY-MM-DD HH:MM:SS> ] [-T <displayTime>] [-l <lockMySQL>] [-D <debug>] [-V version] [-h help]\n";
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub print_help () {
  print_revision($PROGNAME, $version);
  print "ASNMTAP Display for the '$APPLICATION'

-H, --hostname=<HOSTNAME>
   HOSTNAME : hostname/address from the MySQL server
-C, --checklist=<FILENAME>
   FILENAME : filename from the checklist for the html output loop (default 'DisplayCT')
-P, --pagedir=<PAGEDIR>
   PAGEDIR  : sub directory name for the html output (default 'index')
-L, --loop=F|T
   F(alse)  : loop off (default)
   T(rue)   : loop on
-t, --trigger=F|T
   F(alse)  : trigger off (default)
   T(rue)   : trigger on
-c, --creationTime=<YYYY-MM-DD HH:MM:SS>
   YYYY-MM-DD HH:MM:SS: year, month, day, hours, minutes and seconds to use instead of the current time when --loop = F
-T, --displayTime=F|T
   F(alse)  : display timeslots into html output off
   T(rue)   : display timeslots into html output (default)
-l, --lockMySQL=F|T
   F(alse)  : lock MySQL table off (default)
   T(rue)   : lock MySQL table on
-D, --debug=F|T
   F(alse)  : screendebugging off (default)
   T(true)  : normal screendebugging on
-V, --version
-h, --help

Send email to $SENDEMAILTO if you have questions regarding
use of this software. To submit patches or suggest improvements, send
email to $SENDEMAILTO

";
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



( run in 1.120 second using v1.01-cache-2.11-cpan-39bf76dae61 )