ASNMTAP

 view release on metacpan or  search on metacpan

applications/bin/generateReports.pl  view on Meta::CPAN

    $daysAfter = $opt_a;
  } elsif ($opt_a =~ /^F$/) {
    $daysAfter = 0;
  } else {
    usage("Invalid days after: $opt_a\n");
  }
}

my $uKeySqlWhere = (defined $opt_u) ? $SERVERTABLREPORTS.'.uKey = "' .$opt_u .'" AND' : '';

if ($opt_y) {
  if ($opt_y =~ /^20\d\d$/) {
    $currentYear = $opt_y;
  } else {
    usage("Invalid current year: $opt_y\n");
  }
}

if ($opt_m) {
  if ($opt_m =~ /^([1-9]|1[012])$/) {
    $currentMonth = $opt_m;
  } else {
    usage("Invalid current month: $opt_m\n");
  }
}

if ($opt_d) {
  if ($opt_d =~ /^([1-9]|[12][0-9]|3[01])$/) {
    my $daysInMonth = Days_in_Month($currentYear, $currentMonth); 

    if ( $opt_d <= $daysInMonth) {
      $currentDay = $opt_d;
    } else {
      usage("Invalid current day: $opt_d\n");
    }
  } else {
    usage("Invalid current day: $opt_d\n");
  }
}

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

my $logger = LOG_init_log4perl ( 'generate::reports', undef, $debug );

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

my ($emailReport, $rvOpen) = init_email_report (*EMAILREPORT, "generateReports.txt", $debug);

create_dir ($RESULTSPATH);

my @arrayDays   = ('<NIHIL>', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');
my @arrayMonths = ('<NIHIL>', 'January', 'Februari', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

for (my $dayAfter = ( $daysAfter ) ? 1 : 0; $dayAfter <= $daysAfter; $dayAfter++) {
  my ($urlAccessParametersDay, $urlAccessParametersWeek, $urlAccessParametersMonth, $urlAccessParametersQuarter, $urlAccessParametersYear);
  my $emailMessage = "\n";

  # Yesterday - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  my ($dayReportYear, $dayReportMonth, $dayReportDay) = Add_Delta_Days ( $currentYear, $currentMonth, $currentDay, -$dayAfter );
  $emailMessage .= "Report Daily     : for day $dayReportDay from the month $dayReportMonth into the year $dayReportYear\n";
  $urlAccessParametersDay = "inputType=fromto&startDate=$dayReportYear-$dayReportMonth-$dayReportDay&endDate=";
  my $dayReportDayOfWeek = Day_of_Week ($dayReportYear, $dayReportMonth, $dayReportDay);

  # Last day of the week  - - - - - - - - - - - - - - - - - - - - - - - -
  my $weekReportWeek = 0;

  if ($dayReportDayOfWeek == 7) {
    my $weekReportYear;
    ($weekReportWeek, $weekReportYear) = Week_of_Year( $dayReportYear, $dayReportMonth, $dayReportDay ); 
    $emailMessage .= "Report Weekly    : for week $weekReportWeek into the year $weekReportYear\n";
    $urlAccessParametersWeek = "inputType=week&year=$weekReportYear&week=$weekReportWeek";
  }

  # Last day of the month - - - - - - - - - - - - - - - - - - - - - - - -
  my $dayReportDaysInMonth = Days_in_Month($dayReportYear, $dayReportMonth);

  if ($dayReportDay == $dayReportDaysInMonth) {
    $emailMessage .= "Report Monthly   : for month $dayReportMonth into the year $dayReportYear\n";
    $urlAccessParametersMonth = "inputType=month&year=$dayReportYear&month=$dayReportMonth";
  }

  # Last day of a quarter - - - - - - - - - - - - - - - - - - - - - - - -
  my $quarterReportQuarter = 0;

  if (($dayReportMonth == 3 or $dayReportMonth == 6 or $dayReportMonth == 9 or $dayReportMonth == 12) and $dayReportDay == $dayReportDaysInMonth) {
    $quarterReportQuarter = int(($dayReportMonth + 2) / 3);
    $emailMessage .= "Report Quarterly : for quarter $quarterReportQuarter into the year $dayReportYear\n";
    $urlAccessParametersQuarter = "inputType=quarter&year=$dayReportYear&quarter=$quarterReportQuarter";
  }

  # Last day of the year - - - - - - - - - - - - - - - - - - - - - - - - -
  my $yearReportYear = 0;

  if ($dayReportMonth == 12 and $dayReportDay == 31) {
    $yearReportYear = $currentYear - 1;
    $emailMessage .= "Report Yearly    : for the year $yearReportYear\n";
    $urlAccessParametersYear = "inputType=year&year=$yearReportYear";
  }

  if ( $debug ) { print $emailMessage; } else { print EMAILREPORT $emailMessage; }

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

  # Init parameters
  my ($rv, $dbh, $sth, $sql);

  # open connection to database and query data
  $rv  = 1;

  $dbh = DBI->connect("dbi:mysql:$DATABASE:$SERVERNAMEREADONLY:$SERVERPORTREADONLY", "$SERVERUSERREADONLY", "$SERVERPASSREADONLY" ) or $rv = DBI_error_trap(*EMAILREPORT, "Cannot connect to the database", \$logger, $debug);

  if ($dbh and $rv) {
    my ($id, $catalogID, $uKey, $reportTitle, $periode, $status, $errorDetails, $bar, $hourlyAverage, $dailyAverage, $showDetails, $showComments, $showPerfdata, $showTop20SlowTests, $printerFriendlyOutput, $formatOutput, $userPassword, $timeperiodID,...
    $sql = "select id, $SERVERTABLREPORTS.catalogID, $SERVERTABLREPORTS.uKey, concat( LTRIM(SUBSTRING_INDEX($SERVERTABLPLUGINS.title, ']', -1)), ' (', $SERVERTABLENVIRONMENT.label, ')' ), periode, status, errorDetails, bar, hourlyAverage, dailyAverag...
    $sth = $dbh->prepare( $sql ) or $rv = DBI_error_trap(*EMAILREPORT, "Cannot dbh->prepare: $sql", \$logger, $debug);
    $sth->execute() or $rv = DBI_error_trap(*EMAILREPORT, "Cannot sth->execute: $sql", \$logger, $debug) if $rv;
    $sth->bind_columns( \$id, \$catalogID, \$uKey, \$reportTitle, \$periode, \$status, \$errorDetails, \$bar, \$hourlyAverage, \$dailyAverage, \$showDetails, \$showComments, \$showPerfdata, \$showTop20SlowTests, \$printerFriendlyOutput, \$formatOutpu...

    my @commands = (); my @pdfFilenames = ();

    if ( $rv ) {



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