ASNMTAP

 view release on metacpan or  search on metacpan

applications/htmlroot/cgi-bin/generateChart.pl  view on Meta::CPAN

        if ( $uKey2 eq 'none' and $applicationTitle2 eq '<NIHIL>' ) {
          if ( $selChart eq "Status" ) {
            $chartTitle = "Status";
          } elsif ( $selChart eq "ErrorDetails" ) {
            $chartTitle = "Error Details";
          } elsif ( $selChart eq "Bar" ) {
            $chartTitle = "Bar";
          } elsif ( $selChart eq "HourlyAverage" ) {
            $chartTitle = "Hourly Average";
          } elsif ( $selChart eq "DailyAverage" ) {
            $chartTitle = "Daily Average";
          }

          $chartTitle .= " for '$applicationTitle1' ";
        } else {
          $chartTitle = "Comparing '$applicationTitle1'";

          if ( $uKey3 eq 'none' and $applicationTitle3 eq '<NIHIL>' ) {
            $chartTitle .= " and '$applicationTitle2' ";
          } else {
            $chartTitle .= ", '$applicationTitle2' and '$applicationTitle3' ";
          }
        }

        $chartTitle .= " from $CcatalogID ";
      }

      if ( $rv ) {
        my $addAreaBOffset = 22;
        $addAreaBOffset = 8  if ( $selChart eq "HourlyAverage" );
        $addAreaBOffset = 36 if ( $selChart eq "DailyAverage" );

        if ($inputType eq "fromto") {
          if ( defined $endDateIN ) {
            $chartTitle  .= "from $startDateIN to $endDateIN";
          } else {
            $chartTitle  .= "on $startDateIN";	
          }
        } elsif ( $inputType eq "year" ) {
          $chartTitle  .= "for $selYear";
        } elsif ( $inputType eq "quarter" ) {
          $chartTitle .= "for $selYear quarter $selQuarter";
        } elsif ( $inputType eq "month" ) {
          $chartTitle  .= "for ". $arrMonths[$selMonth -1] .' '. $selYear;
        } elsif ( $inputType eq "week" ) {
          $chartTitle .= "for $selYear week $selWeek from $CcatalogID";
        } else {
          $rv = 0; $errorMessage = "Whoops - title error! ($inputType)";
        }

        my ($sqlStartDate, $sqlEndDate);

        if ( $rv ) {
          $AreaBOffset += $addAreaBOffset;
         ($goodDate, $sqlStartDate, $sqlEndDate, undef) = get_sql_startDate_sqlEndDate_numberOfDays_test ($STRICTDATE, $FIRSTSTARTDATE, $inputType, $selYear, $selQuarter, $selMonth, $selWeek, $startDateIN, $endDateIN, $currentYear, $currentMonth, $cu...

          if ( $goodDate ) {
            $sqlPeriode = "AND startDate between '$sqlStartDate' AND '$sqlEndDate' ";

            if ( $timeperiodID > 1 ) {
              $sql = "select timeperiodName, sunday, monday, tuesday, wednesday, thursday, friday, saturday from $SERVERTABLTIMEPERIODS where catalogID = '$CcatalogID' and timeperiodID = '$timeperiodID'";
              $sth = $dbh->prepare( $sql ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot dbh->prepare: $sql", $debug, '', "", '', "", 0, '', $sessionID);
              $sth->execute() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->execute: $sql", $debug, '', "", '', "", 0, '', $sessionID) if $rv;

              if ( $rv ) {
                ($slaWindow, my ($sunday, $monday, $tuesday, $wednesday, $thursday, $friday, $saturday)) = $sth->fetchrow_array() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->fetchrow_array: $sql", $debug,...
                $sth->finish() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->finish", $debug, '', "", '', "", 0, '', $sessionID);
                my $slaPeriode = create_sql_query_from_range_SLA_window ($sunday, $monday, $tuesday, $wednesday, $thursday, $friday, $saturday);
                $chartTitle .= ", $slaWindow" if ( defined $slaWindow );
                $sqlPeriode .= "$slaPeriode " if ( defined $slaPeriode );
              }
            }
          } else {
            $rv = 0; $errorMessage = "Wrong Startdate and/or Enddate";
          }
        }

        if ( $rv and $uKey1 ne 'none' ) {
          if ( $selChart eq "Status" ) {
            my ($title, $status, $aantal, %problemSummary);
            $sql = create_sql_query_events_from_range_year_month ($inputType, $sqlStartDate, $sqlEndDate, "select SQL_NO_CACHE title, status, count(status) as aantal", $forceIndex, "WHERE catalogID = '$CcatalogID' and uKey = '$uKey1'", $sqlPeriode, "...
            $sth = $dbh->prepare( $sql ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot dbh->prepare: $sql", $debug, '', "", '', "", 0, '', $sessionID);
            $sth->execute() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->execute: $sql", $debug, '', "", '', "", 0, '', $sessionID) if $rv;
            $sth->bind_columns( \$title, \$status, \$aantal ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->bind_columns: $sql", $debug, '', "", '', "", 0, '', $sessionID) if $rv;

		        if ( $rv ) {
  		        if ( $sth->rows ) {
                my %labels = ();

                while( $sth->fetch() ) {
                  if ($status eq '<NIHIL>') { $status = "UNKNOWN" }

                  if (exists $labels{$status}) {
                    $labels{$status} += $aantal;
                  } else {
                    $labels{$status}  = $aantal;
                  }
                }

                foreach my $label (keys %labels) {
                  push (@labels, $label);

                  if ($label eq 'OK') {
                    push (@icons, "$IMAGESPATH/$ICONS{OK}");
                    $labels{$label} *= 8 if ($uKey1 eq 'KBO-WI-P-01'); # KBO-WI specific
                  } elsif ($label eq 'WARNING') {
                    push (@icons, "$IMAGESPATH/$ICONS{WARNING}");
                    $labels{$label} *= 8 if ($uKey1 eq 'KBO-WI-P-01'); # KBO-WI specific
                  } elsif ($label eq 'CRITICAL') {
                    push (@icons, "$IMAGESPATH/$ICONS{CRITICAL}");
                  } elsif ($label eq 'UNKNOWN') {
                    push (@icons, "$IMAGESPATH/$ICONS{UNKNOWN}");
                  } elsif ($label eq 'NO TEST') {
                    push (@icons, "$IMAGESPATH/$ICONS{'NO TEST'}");
                  } elsif ($label eq 'NO DATA') {
                    push (@icons, "$IMAGESPATH/$ICONS{'NO DATA'}");	
                  } elsif ($label eq 'OFFLINE') {
                    push (@icons, "$IMAGESPATH/$ICONS{OFFLINE}");
                  }

                  push (@data, $labels{$label});
				        }
              } else {
			          $hight = 380; $rv = 0; $errorMessage = "NO DATA FOR THIS PERIOD (1)";
              }

              $sth->finish() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->finish", $debug, '', "", '', "", 0, '', $sessionID);
            }
          } elsif ( $selChart eq "ErrorDetails" ) {
            my ($title, $statusmessage, $aantal, %problemSummary);
            $sql = create_sql_query_events_from_range_year_month ($inputType, $sqlStartDate, $sqlEndDate, "select SQL_NO_CACHE title, statusmessage, count(statusmessage) as aantal", $forceIndex, "WHERE catalogID = '$CcatalogID' and uKey = '$uKey1'", ...
            $sth = $dbh->prepare( $sql ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot dbh->prepare: $sql", $debug, '', "", '', "", 0, '', $sessionID);
            $sth->execute() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->execute: $sql", $debug, '', "", '', "", 0, '', $sessionID) if $rv;
            $sth->bind_columns( \$title, \$statusmessage, \$aantal ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->bind_columns: $sql", $debug, '', "", '', "", 0, '', $sessionID) if $rv;

		        if ( $rv ) {
  		        if ( $sth->rows ) {
                while( $sth->fetch() ) {
                  my ($dummy, $rest) = split(/:/, $statusmessage, 2);
                  $rest = $dummy unless ( $rest );

                  if ($rest) {
                  # ($rest, undef) = split(/\|/, $rest, 2); # remove performance data
                     my $_rest = reverse $rest;
                     my ($_rest, undef) = reverse split(/\|/, $_rest, 2);
                     my $rest = reverse $_rest;

                    ($dummy, $rest) = split(/,/, $rest, 2);
                    $rest = $dummy unless ( $rest);
                  } else {
                    $rest = ' UNDEFINED';
                  }
				  
                  if (exists $problemSummary{$rest}) {
                    $problemSummary{$rest} += $aantal;
                  } else {
                    $problemSummary{$rest}  = $aantal;
                  }
                }

                foreach my $rest (sort {$problemSummary{$b} <=> $problemSummary{$a}} (keys(%problemSummary))) {
                  push (@data, $problemSummary{$rest});
                  push (@labels, substr($rest, 1, 38));
                }
              } else {
			          $hight = 380; $rv = 0; $errorMessage = "NO ERRORS FOR THIS PERIOD";
              }

              $sth->finish() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->finish", $debug, '', "", '', "", 0, '', $sessionID);
            }
          } elsif ( $selChart eq "Bar" ) {
            my ($seconden, $duration, $startDate, $startTime, $status, $step);
            my ($dataOK, $dataWarning, $dataCritical, $dataUnknown, $dataNoTest, $dataOffline);
            $sql = create_sql_query_events_from_range_year_month ($inputType, $sqlStartDate, $sqlEndDate, "select SQL_NO_CACHE duration, startDate, startTime, status, step", $forceIndex, "WHERE catalogID = '$CcatalogID' and uKey = '$uKey1'", $sqlPeri...
            $sth = $dbh->prepare( $sql ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot dbh->prepare: $sql", $debug, '', "", '', "", 0, '', $sessionID);
            $sth->execute() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->execute: $sql", $debug, '', "", '', "", 0, '', $sessionID) if $rv;
            $sth->bind_columns( \$duration, \$startDate, \$startTime, \$status, \$step ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->bind_columns: $sql", $debug, '', "", '', "", 0, '', $sessionID) if $rv;

		        if ( $rv ) {
  		        if ( $sth->rows ) {
                my $counter = 0;
                $numberOfLabels = ($sth->rows < 25) ? $sth->rows : 25;
                my $labelCounter = int($sth->rows / $numberOfLabels);
                my $limitTrendvalue = ($trendvalue) ? $trendvalue * 2.5 : 9000;
                my $moreDays = (defined $endDateIN or $inputType eq "year" or $inputType eq "quarter" or $inputType eq "month" or $inputType eq "week") ? 1 : 0;

                while( $sth->fetch() ) {
                  $dataOK = $dataWarning = $dataCritical = $dataUnknown = $dataNoTest = $dataOffline = "0";
                  $seconden = int(substr($duration, 6, 2)) + int(substr($duration, 3, 2)*60) + int(substr($duration, 0, 2)*3600);
                  $seconden += 0.5 if ($seconden == 0); # correction for to fast testresults

                  if ($status eq 'OK') {
                    $dataOK = ($seconden < $limitTrendvalue) ? $seconden : $limitTrendvalue;
                  } elsif ($status eq 'WARNING') {
                    $dataWarning = "-5";
                  } elsif ($status eq 'CRITICAL') {
                    $dataCritical = "-5";
                  } elsif ($status eq 'UNKNOWN') {
                    $dataUnknown = "-5";
                  } elsif ($status eq 'NO TEST') {
                    $dataNoTest = "-5";
                  } elsif ($status eq 'OFFLINE') {
                    $dataOffline = "-5";
                  }
				
                  push (@dataOK,       $dataOK);
                  push (@dataWarning,  $dataWarning);
                  push (@dataCritical, $dataCritical);
                  push (@dataUnknown,  $dataUnknown);
                  push (@dataNoTest,   $dataNoTest);
                  push (@dataOffline,  $dataOffline);

                  if ($labelCounter == 1 or $labelCounter == $counter or ($counter == 0 and $labelCounter >= 2)) {
                    if ($moreDays) {
                      push (@labels, $startDate . " ~ " . substr($startTime, 0, 5));
                    } else {
                      push (@labels, substr($startTime, 0, 5));
                    }

                    $counter = 1;
                  } else {
                    push (@labels, "");
                    $counter++;
                  }
                }

                $AreaBOffset += 36 if ($moreDays);
              } else {
			          $hight = 380; $rv = 0; $errorMessage = "NO DATA FOR THIS PERIOD (2)";
              }

              $sth->finish() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->finish", $debug, '', "", '', "", 0, '', $sessionID);
            }
          } elsif ( $selChart eq "HourlyAverage" or $selChart eq "DailyAverage" ) {

applications/htmlroot/cgi-bin/generateChart.pl  view on Meta::CPAN

      $layer = $c->addBarLayer2($perlchartdir::Stack);

      # Set the sub-bar gap to 0, so there is no gap between stacked bars with a group
      $layer->setBarGap(-1.7E-100, 0);
	
      # Add the first two data sets to the chart as a stacked bar group
      $layer->addDataSet(\@dataOK, $layer->yZoneColor($trendvalue, $COLORSRRD {OK}, $COLORSRRD {TRENDLINE}), " Duration");
      $layer->addDataSet(\@dataWarning,  $COLORSRRD {WARNING},  " Warning");
      $layer->addDataSet(\@dataCritical, $COLORSRRD {CRITICAL}, " Critical");
      $layer->addDataSet(\@dataUnknown,  $COLORSRRD {UNKNOWN},  " Unknown");
      $layer->addDataSet(\@dataOffline,  $COLORSRRD {OFFLINE},  " Offline");
      $layer->addDataSet(\@dataNoTest,   $COLORSRRD {"NO TEST"},  " No Test");
    } elsif ( $selChart eq "HourlyAverage" or $selChart eq "DailyAverage" ) {
      if ( $selChart eq "HourlyAverage" ) {
        for($i = 1; $i < $numberOfDays; ++$i) { my $xMark1 = $c->xAxis()->addMark((24 * $i), 0x0000FF); }
        my $xCorrectie = 95 - $xOffset;

        for($i = 0; $i < $numberOfDays; ++$i) {
          my $cdate = Date_to_Text_Long ( Add_Delta_Days($yearFrom, $monthFrom, $dayFrom, $i) );
          my $x = ($numberOfDays > 1) ? ($i * 600) + 300 + $xCorrectie : ($width/2) + $xCorrectie;
          $c->addText($x, 40, $cdate, "arialbi.ttf", 10, 0x000000, 5, 0);
        }
      }

      # Add a line layer to the chart
      $layer = $c->addSplineLayer();

      # Add the first two data sets to the chart as a stacked bar group
      $layer->addDataSet(\@avg1, 0xcf4040, "$applicationTitle1")->setDataSymbol($perlchartdir::DiamondSymbol, 8);
      if ($uKey2 ne 'none') { $layer->addDataSet(\@avg2, 0x6699cc, "$applicationTitle2")->setDataSymbol($perlchartdir::DiamondSymbol, 8); }
      if ($uKey3 ne 'none') { $layer->addDataSet(\@avg3, 0x009900, "$applicationTitle3")->setDataSymbol($perlchartdir::DiamondSymbol, 8); }

      # Enable data label on the data points.
      $layer->setDataLabelFormat("{value|2,.}");
    }

    # Set the bar border to transparent
    $layer->setBorderColor($perlchartdir::Transparent);

    if ($pf eq 'on') {
      $c->addLegend(2, $hight - 32, 0, "arial.ttf", 8)->setBackground($perlchartdir::Transparent);
    } else {
      $c->addLegend(2, $hight - 32, 0, "arial.ttf", 8)->setFontColor($forGround);
    }
  }
}

# Output the chart
binmode(STDOUT);
print "Content-type: image/png\n\n";
print $c->makeChart2($perlchartdir::PNG);

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

sub getAverage {
  my ($number, $dbh, $rv, $uKey, $sqlStartDate, $sqlEndDate, $sqlPeriode, $selChart, $debug) = @_;

  my ($sql, $sth, $errorMessage, $dbiErrorCode, $dbiErrorString, $startDate, $hour, $average, @avg, @labels);

  if ( $selChart eq "HourlyAverage" ) {
    $sql = create_sql_query_events_from_range_year_month ($inputType, $sqlStartDate, $sqlEndDate, "select SQL_NO_CACHE startDate, hour(startTime) as hour, round(avg(time_to_sec(duration)), 2)", $forceIndex, "WHERE catalogID = '$CcatalogID' and uKey =...
  } else {
    $sql = create_sql_query_events_from_range_year_month ($inputType, $sqlStartDate, $sqlEndDate, "select SQL_NO_CACHE startDate, round(avg(time_to_sec(duration)), 2)", $forceIndex, "WHERE catalogID = '$CcatalogID' and uKey = '$uKey'", $sqlPeriode, "...
  }

  $sth = $dbh->prepare( $sql ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot dbh->prepare: $sql", $debug, '', "", '', "", 0, '', $sessionID);
  $sth->execute() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->execute: $sql", $debug, '', "", '', "", 0, '', $sessionID) if $rv;

  if ( $selChart eq "HourlyAverage" ) {
    $sth->bind_columns( \$startDate, \$hour, \$average ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->bind_columns: $sql", $debug, '', "", '', "", 0, '', $sessionID) if $rv;
  } else {
    $sth->bind_columns( \$startDate, \$average ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->bind_columns: $sql", $debug, '', "", '', "", 0, '', $sessionID) if $rv;
  }

  if ( $rv ) {
    if ( $sth->rows ) {
      while( $sth->fetch() ) {
        push (@avg, $average);

        if ( $selChart eq "HourlyAverage" ) {
          push (@labels, $startDate .":". $hour);
        } else {
          push (@labels, $startDate);
        }
      }
    } else {
      $hight = 380; $rv = 0; $errorMessage = "NO DATA FOR THIS PERIOD (3)";
    }

    $sth->finish() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->finish", $debug, '', "", '', "", 0, '', $sessionID);
  }

  if ( $number == 1 ) {
    @avg1 = @avg; @labels1 = @labels;
  } elsif ( $number == 2 ) {
    @avg2 = @avg; @labels2 = @labels;
  } elsif ( $number == 3 ) {
    @avg3 = @avg; @labels3 = @labels;
  }

  return ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString);
}

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

sub rebuildDataArrayHourlyAverage {
  my ($arr_full, $arr_part, $arr_data) = @_;

  my (@arr_res, $found, $cdate1, $time1, $cdate2, $time2, $year1, $month1, $day1, $year2, $month2, $day2);

  for (my $i = 0; $i < @$arr_full; $i++) {			
    ($cdate1, $time1) = split(/:/, @$arr_full[$i]);
	($year1, $month1, $day1) = split(/-/, $cdate1);
    $found = 0;

    for (my $j = 0; $j < @$arr_part; $j++) {
      ($cdate2, $time2) = split(/:/, @$arr_part[$j]);
      ($year2, $month2, $day2) = split(/-/, $cdate2);
				
      if (($time1 == $time2) and ($day1 == $day2)) {
        push (@arr_res, @$arr_data[$j]);
        $found = 1;
      }



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