ASNMTAP
view release on metacpan or search on metacpan
lib/ASNMTAP/Asnmtap/Applications/CGI.pm view on Meta::CPAN
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub create_sql_query_events_from_range_year_month {
my ($inputType, $startDate, $endDate, $sqlSelect, $sqlForce, $sqlWhere, $sqlPeriode, $sqlQuery, $sqlGroup, $sqlOrder, $sqlOrderUnion, $sqlUnionKeyword) = @_;
$sqlUnionKeyword = 'ALL' if ($sqlUnionKeyword ne 'ALL' or $sqlUnionKeyword ne 'DISTINCT');
my ($yearFrom, $monthFrom, $dayFrom) = split (/-/, $startDate);
my ($yearTo, $monthTo, $dayTo) = split (/-/, $endDate);
use Date::Calc qw(Add_Delta_Days Delta_Days);
my $deltaDays = Delta_Days ($yearFrom, $monthFrom, $dayFrom, $yearTo, $monthTo, $dayTo);
my ($sql, $sqlUnion);
if ( $deltaDays >=0 ) {
my $sqlCommon = "$sqlSelect FROM `$SERVERTABLEVENTS` $sqlForce $sqlWhere $sqlPeriode $sqlQuery $sqlGroup $sqlOrder";
if ( $SERVERMYSQLMERGE eq '1' ) {
if ($inputType eq "year" and $yearFrom = $yearTo) {
$sqlUnion = "union $sqlUnionKeyword ($sqlSelect FROM `". $SERVERTABLEVENTS. "_". sprintf ("%04d", $yearFrom) ."` $sqlForce $sqlWhere $sqlPeriode $sqlQuery $sqlGroup $sqlOrder)";
} elsif ($inputType eq "quarter" and $monthFrom = $monthTo) {
$sqlUnion = "union $sqlUnionKeyword ($sqlSelect FROM `". $SERVERTABLEVENTS. "_". sprintf ("%04d", $yearFrom) ."_Q". (int(($monthFrom+2)/3)) ."` $sqlForce $sqlWhere $sqlPeriode $sqlQuery $sqlGroup $sqlOrder)";
}
}
unless (defined $sqlUnion) {
foreach my $year ($yearFrom..$yearTo) {
my $monthF = ($year == $yearFrom) ? $monthFrom : 1;
my $monthT = ($year == $yearTo or $yearFrom == $yearTo) ? $monthTo : 12;
foreach my $month ($monthF..$monthT) {
my $yearTable = sprintf ("%04d", $year);
my $monthTable = sprintf ("%02d", $month);
$sqlUnion .= " union $sqlUnionKeyword ($sqlSelect FROM `". $SERVERTABLEVENTS. "_". $yearTable ."_". $monthTable ."` $sqlForce $sqlWhere $sqlPeriode $sqlQuery $sqlGroup $sqlOrder)";
}
}
}
if (defined $sqlUnion) {
$sql = "($sqlCommon) $sqlUnion $sqlOrderUnion";
} else {
$sql = $sqlCommon;
}
}
return $sql;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub create_sql_query_from_range_SLA_window {
my (@days) = @_; # @_ => ($sunday, $monday, $tuesday, $wednesday, $thursday, $friday, $saturday)
my ($day, $windowSLA) = (0);
foreach my $periode (@days) {
$day++;
if ( defined $periode and $periode and $periode !~ /00:00-24:00/ ) {
my @range = split (/,/, $periode);
my $windowToday;
foreach my $range (@range) {
my ($from, $to) = split (/-/, $range);
if ( defined $from and defined $to ) {
$windowToday .= ' or ' if ( defined $windowToday );
$windowToday .= "startTime BETWEEN '$from:00' and '$to:00'";
}
}
if ( defined $windowToday ) {
$windowSLA .= ' or ' if ( defined $windowSLA );
$windowSLA .= '( DAYOFWEEK(startDate) = '. $day .' and ( '. $windowToday .' ) )'
}
}
}
return ( defined $windowSLA ? ' and ( '. $windowSLA .' )' : '' );
}
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
sub get_title {
my ($dbh, $rv, $catalogID, $uKey, $debug, $refresh, $sessionID) = @_;
my ($sql, $sth, $errorMessage, $dbiErrorCode, $dbiErrorString, $title, $environment, $trendline, $step, $applicationTitle, $trendValue, $stepValue);
$sql = "select concat( LTRIM(SUBSTRING_INDEX(title, ']', -1)), ' (', $SERVERTABLENVIRONMENT.label, ')' ), $SERVERTABLPLUGINS.environment, trendline, step from $SERVERTABLPLUGINS, $SERVERTABLENVIRONMENT WHERE catalogID = '$catalogID' and uKey = '$uK...
$sth = $dbh->prepare( $sql ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot dbh->prepare: $sql", $debug, '', "", '', "", $refresh, '', $sessionID);
$sth->execute() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->execute: $sql", $debug, '', "", '', "", $refresh, '', $sessionID) if $rv;
$sth->bind_columns( \$title, \$environment, \$trendline, \$step ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->bind_columns: $sql", $debug, '', "", '', "", $refresh, '', $sessionID) if $rv;
if ( $rv ) {
while( $sth->fetch() ) {
$title =~ s/^[\[[\S+|\s+]*\]\s+]{0,1}([\S+|\s+]*)/$1/g;
$applicationTitle = $title;
$trendValue = $trendline;
$stepValue = $step;
}
$sth->finish() or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot sth->finish", $debug, '', "", '', "", $refresh, '', $sessionID);
}
if ( $refresh == 0 ) {
return ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString, $applicationTitle, $trendValue, $stepValue);
} elsif ( $refresh == -1 ) {
return ($rv, $applicationTitle);
} else {
return ($rv, $applicationTitle, $trendValue);
}
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub get_sql_crontab_scheduling_report_data {
my ($dbh, $sql, $rv, $errorMessage, $dbiErrorCode, $dbiErrorString, $sessionID, $hight, $hightMin, $uKeys, $labels, $stepValue, $catalogID, $uKeysSqlWhere, $debug) = @_;
my ($collectorDaemon, $uKey, $lineNumber, $minute, $hour, $dayOfTheMonth, $monthOfTheYear, $dayOfTheWeek, $noOffline, $applicationTitle, $step);
my $sth = $dbh->prepare( $sql ) or ($rv, $errorMessage, $dbiErrorCode, $dbiErrorString) = error_trap_DBI("", "Cannot dbh->prepare: $sql", $debug, '', "", '', "", 0, '', $sessionID);
( run in 0.692 second using v1.01-cache-2.11-cpan-d8267643d1d )