ASNMTAP
view release on metacpan or search on metacpan
applications/collector-test.pl view on Meta::CPAN
rename("$httpdumpFilenameTmp", "$debugFilename");
}
} else {
unlink ($httpdumpFilenameTmp) if (-e "$httpdumpFilenameTmp");
}
}
} else {
$action = 'Failed';
$dumphttpRename = 'UNKNOWN';
printDebugAll (" call_system --- : $system_action: <$exit_value><$signal_num><$dumped_core><$stderr>");
printDebugNOK (" call_system --- : $system_action: <$exit_value><$signal_num><$dumped_core><$stderr>");
if ( $exit_value == -1 ) {
$returnStatus = "$dumphttpRename - $title: PLUGIN '$msgCommand.pl' doesn't exist - contact administrators";
} elsif ( $boolean_signal_kill ) {
$returnStatus = "$dumphttpRename - $title: TIMING OUT SLOW PLUGIN";
my $httpdumpFilenameTmpKnownError = $httpdumpFilenameTmp .'-KnownError';
unlink ($httpdumpFilenameTmpKnownError) if (-e "$httpdumpFilenameTmpKnownError");
unlink ($httpdumpFilenameTmp) if (-e "$httpdumpFilenameTmp");
} else {
$returnStatus = "$dumphttpRename - $title: ERROR NOT DEFINED - contact server administrators";
}
}
$endDate = get_csvfiledate();
$endTime = get_csvfiletime();
unless ( $CAPTUREOUTPUT ) {
$loggedStatus = ( $dumphttp ne 'N' ) ? $httpdumpFilenameTmp : $logging;
$loggedStatus .= '-status.txt';
$returnStatus = "<NIHIL> - $title: $loggedStatus";
if (-e "$loggedStatus") {
unless ( $boolean_signal_kill ) {
$rvOpen = open(DEBUG, "$loggedStatus");
if ($rvOpen) {
while (<DEBUG>) {
chomp;
$returnStatus = $_;
}
close(DEBUG);
} else {
$dumphttpRename = 'UNKNOWN';
$returnStatus = "$dumphttpRename - $title: Cannot open $loggedStatus to retrieve debug information - contact server administrators";
}
}
unlink ($loggedStatus);
} else {
$dumphttpRename = 'UNKNOWN';
$returnStatus = "$dumphttpRename - $title: $loggedStatus doesn't exist - contact server administrators";
}
}
my ($duration) = $returnStatus =~ m/Trendline=([0-9.]+)s;[0-9.]+;;;$/i;
if (defined $duration) {
my ($thour, $tmin, $tsec);
$thour = int ($duration / 3600);
$tmin = int (int ($duration % 3600) / 60);
$tsec = int ($duration % 60);
$duration = sprintf("%02d:%02d:%02d", $thour, $tmin, $tsec);
} else {
my ($tyear, $tmonth, $tday, $thour, $tmin, $tsec, @startDateTime, @endDateTime, @diffDateTime);
($tyear, $tmonth, $tday) = split(/\//, $startDate);
($thour, $tmin, $tsec) = split(/\:/, $startTime);
@startDateTime = ($tyear, $tmonth, $tday, $thour, $tmin, $tsec);
($tyear, $tmonth, $tday) = split(/\//, $endDate);
($thour, $tmin, $tsec) = split(/\:/, $endTime);
@endDateTime = ($tyear, $tmonth, $tday, $thour, $tmin, $tsec);
@diffDateTime = Delta_DHMS(@startDateTime, @endDateTime);
$duration = sprintf("%02d:%02d:%02d", $diffDateTime[1], $diffDateTime[2], $diffDateTime[3]);
}
# my ($outputData, $performanceData) = split(/\|/, $returnStatus, 2);
my $_returnStatus = reverse $returnStatus;
my ($_outputData, $_performanceData) = reverse split(/\|/, $_returnStatus, 2);
my $outputData = reverse $_outputData;
my $performanceData = reverse $_performanceData;
$rvOpen = open(CSV,">>$logging-$msgCommand-$catalogID_uniqueKey-csv.txt");
if ($rvOpen) {
print CSV '"', $catalogID, '","","', $uniqueKey, '","I","', $system_action, '","', $title, '","', $dumphttpRename, '","', $startDate, '","', $startTime, '","', $endDate, '","', $endTime, '","', $duration, '","', $outputData, '","', $performanceDa...
close(CSV);
} else {
print "Cannot open $logging-$msgCommand-$catalogID_uniqueKey-csv.txt to print debug information\n";
}
if ( $boolean_perfParseInstalled ) {
if (defined $performanceData) {
my $perfParseTimeslot = get_timeslot ($currentDate);
my $perfParseCommand;
my $environment = (($system_action =~ /\-\-environment=([PASTDL])/) ? $1 : 'P');
my $eTitle = $title .' ('. $ENVIRONMENT{$environment} .')' if (defined $environment);
$eTitle .= ' from '. $catalogID;
if ( $perfParseMethode eq 'PULP' ) {
$perfParseCommand = "$APPLICATIONPATH/sbin/perfparse_asnmtap_pulp_command.pl $PREFIXPATH/log/perfdata-asnmtap.log \"$perfParseTimeslot\t$eTitle\t$catalogID_uniqueKey\t$outputData\t$dumphttpRename\t$performanceData\"";
} else {
$perfParseCommand = "printf \"%b\" \"$perfParseTimeslot\t$eTitle\t$catalogID_uniqueKey\t$outputData\t$dumphttpRename\t$performanceData\n\" | $PERFPARSEBIN/perfparse-log2mysql -c $PERFPARSEETC/$PERFPARSECONFIG";
}
if ($CAPTUREOUTPUT) {
use IO::CaptureOutput qw(capture_exec);
($stdout, $stderr) = capture_exec("$perfParseCommand");
} else {
system ("$perfParseCommand"); $stdout = $stderr = '';
}
$exit_value = $? >> 8;
$signal_num = $? & 127;
$dumped_core = $? & 128;
printDebugNOK (" perfParse ----- : $perfParseCommand: <$exit_value><$signal_num><$dumped_core><$stderr>") unless ( $exit_value == 0 && $signal_num == 0 && $dumped_core == 0 && $stderr eq '' );
}
}
insertEntryDBI ($currentDate, $catalogID_uniqueKey, $catalogID, $uniqueKey, $title, $dbiFilename.$msgCommand.'-'.$catalogID_uniqueKey.'-sql', $system_action, $interval, $dumphttpRename, $logging, $debug, $startDate, $startTime, $endDate, $endTime, ...
return $action;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub printDebugAll {
my ($l_text) = @_;
if ($boolean_screenDebug or $boolean_debug_all) {
chomp ($l_text);
applications/collector-test.pl view on Meta::CPAN
my $tDebug = ($debug eq 'T') ? 2 : 0;
my $subject = "$prgtext / Current status for $collectorlist: " . get_datetimeSignal();
my $message = get_datetimeSignal() . " $error_message\n--> ERROR: $DBI::err ($DBI::errstr)\n";
my $returnCode = sending_mail ( $SERVERLISTSMTP, $SENDEMAILTO, $SENDMAILFROM, $subject, $message, $tDebug );
print "Problem sending email to the '$APPLICATION' server administrators\n" unless ( $returnCode );
}
$rvOpen = open(DEBUG,">>$RESULTSPATH/$collectorlist-MySQL-sql-error.txt");
if ($rvOpen) {
print DEBUG get_datetimeSignal, " ", $error_message, "\n--> ERROR: $DBI::err ($DBI::errstr)\n";
close(DEBUG);
} else {
print "Cannot open $RESULTSPATH/$collectorlist-MySQL-sql-error.txt to print debug information\n";
}
return 0;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub errorTrapDBIdowntime {
my ($collectorlist, $error_message, $logger, $debug) = @_;
print $collectorlist, "\n", $error_message, "\nERROR: $DBI::err ($DBI::errstr)\n";
$$logger->error("$collectorlist:\n" .$error_message. "\nERROR: $DBI::err ($DBI::errstr)") if ( defined $$logger and $$logger->is_error() );
return 0;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub graphEntryDBI {
my ($catalogID, $uniqueKey, $title, $environment, $dbiFilename, $interval, $limitTest, $xLabelStep, $withBorder, $markOrZone, $yMarkValue, $xRealtime, $debug) = @_;
$title .= ' ('. $ENVIRONMENT{$environment} .')' if (defined $environment);
$title .= ' from '. $catalogID;
# $limitTest -> 241: (120*2.0)+1, x = 2.0 -> $xLabelStep = 6 * x -> 12
# 181: (120*1.5)+1, x = 1.5 -> $xLabelStep = 6 * x -> 9
# 121: (120*1.0)+1, x = 1.0 -> $xLabelStep = 6 * x -> 6
my $width = 893;
my $hight = 558;
my $xOffset = 74;
my $yOffset = 28;
my $yMarkColor = 0xFFFFDC;
my $background = 0xF7F7F7;
print "Generating RRD alike graph\n" if ($debug eq 'T');
my (@dataOK, @dataCritical, @dataWarning, @dataUnknown, @dataNoTest, @dataOffline, @RRDlabels);
my ($step, $lastTimeslot, $firstTimeslot, $duration, $startTime, $status, $timeslot, $findString);
$step = $interval * 60;
$lastTimeslot = timelocal (0, (localtime)[1,2,3,4,5]);
$firstTimeslot = $lastTimeslot - ($step * ($limitTest));
$findString = "select SQL_NO_CACHE duration, startTime, status, timeslot from $SERVERTABLEVENTS force index (uKey) where catalogID = '$catalogID' and uKey = '$uniqueKey' and step <> '0' and (timeslot between '$firstTimeslot' and '$lastTimeslot')...
print "$findString\n" if ($debug eq 'T');
# data en labels in array zetten
my ($counter, $seconden, $ttimeslot);
for ( $counter = 0; $counter < $limitTest; $counter++) {
push (@dataOK, "0");
push (@dataWarning, "0");
push (@dataCritical, "0");
push (@dataUnknown, "0");
push (@dataNoTest, "0");
push (@dataOffline, "0");
push (@RRDlabels, " ");
}
# db connect & sql query
my ($dbh, $rv, $alarmMessage) = DBI_connect ( $DATABASE, $serverName, $SERVERPORTREADWRITE, $SERVERUSERREADWRITE, $SERVERPASSREADWRITE, $alarm, \&errorTrapDBIgraphEntry, ["Cannot connect to the database"], \$logger, $debug, $boolean_debug_all );
if ($dbh and $rv) {
my $sth = $dbh->prepare( $findString ) or $rv = errorTrapDBIgraphEntry("Cannot dbh->prepare: $findString", \$logger, $debug);
($rv, $alarmMessage) = DBI_execute ($rv, \$sth, $alarm, \&errorTrapDBIgraphEntry, ["Cannot sth->execute: $findString"], \$logger, $debug);
unless ( $rv ) {
$title .= " - DBI_execute - alarm: $alarm - $alarmMessage";
} else {
$sth->bind_columns( \$duration, \$startTime, \$status, \$timeslot ) or $rv = errorTrapDBIgraphEntry("Cannot sth->bind_columns: $findString", \$logger, $debug);
unless ( $rv ) {
$title .= " - Cannot sth->bind_columns";
} else {
$counter = 0;
my $limitTrendline = ($yMarkValue) ? $yMarkValue * 2.5 : 9000;
while( $sth->fetch() ) {
$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
$ttimeslot = abs((($lastTimeslot - $timeslot) / $step) - $limitTest);
if ($ttimeslot >= 0) {
$status = 'UNKNOWN' if ($status eq '<NIHIL>');
if ($status eq 'OK') {
$dataOK[$ttimeslot] = ($seconden < $limitTrendline) ? $seconden : $limitTrendline;
} elsif ($status eq 'CRITICAL') {
$dataCritical[$ttimeslot] = '-5';
} elsif ($status eq 'WARNING'){
$dataWarning[$ttimeslot] = '-5';
} elsif ($status eq 'UNKNOWN'){
$dataUnknown[$ttimeslot] = '-5';
} elsif ($status eq 'NO TEST') {
$dataNoTest[$ttimeslot] = '-5';
} elsif ($status eq 'OFFLINE') {
$dataOffline[$ttimeslot] = '-5';
}
}
$RRDlabels[int($limitTest - $counter - 1)] = substr($startTime, 0, 5) unless ( $counter % $xLabelStep );
$counter++;
}
}
$sth->finish() or $rv = errorTrapDBIgraphEntry("Cannot sth->finish: $findString", \$logger, $debug);
}
$dbh->disconnect or $rv = errorTrapDBIgraphEntry("Sorry, the database was unable to add your entry.", \$logger, $debug);
} else {
$title .= " - DBI_connect - Cannot connect to the database - alarm: $alarm - alarmMessage: $alarmMessage";
$logger->info(" DBI_connect - Cannot connect to the database - alarm: $alarm - alarmMessage: $alarmMessage") if ( defined $logger and $logger->is_info() );
}
# Create a XYChart object of size $width x $hight pixels, using 0xf0e090 as background color, with a black border, and 0 pixel 3D border effect
my $c = new XYChart($width, $hight, $background, 0x0, 0);
# Set the plotarea at (xOffset, yOffset) and of size $width - 95 x $hight - 78 pixels, with white background. Set border and grid line colors.
$c->setPlotArea($xOffset, $yOffset, $width - 95, $hight - 78, 0xffffff, -1, 0xa08040, $c->dashLineColor(0x0, 0x0101), $c->dashLineColor(0x0, 0x0101))->setGridWidth(1);
# Add a title box to the chart using 10 pts Arial Bold Italic font. The text is white (0x000000)
$c->addText($width/2, 14, "$title", "arialbi.ttf", 10, 0x000000, 5, 0);
# Set labels on the x axis
unless ( $xRealtime ) {
for ($counter = 0; $counter < $limitTest; $counter += $xLabelStep) {
$RRDlabels[int($limitTest - $counter - 1)] = substr(scalar(localtime(($lastTimeslot - ($step * ($counter))))), 11, 5);
}
}
$c->xAxis()->setLabels(\@RRDlabels);
for ($counter = 0; $counter < $limitTest - $xLabelStep; $counter += $xLabelStep) {
my $labelStep = $xLabelStep / 3;
$c->xAxis()->addMark($counter + $labelStep, $c->dashLineColor(0x0, 0x103))->setDrawOnTop(0);
$c->xAxis()->addMark($counter + ($labelStep * 2), $c->dashLineColor(0x0, 0x103))->setDrawOnTop(0);
}
# Set labels on the y axis
$c->yAxis()->setLabelFormat("{value|2,.}");
# Add a stacked bar layer to the chart
my $layer = $c->addBarLayer2($perlchartdir::Stack);
# Set the axes width to 1 pixels
$c->yAxis()->setWidth(1);
$c->xAxis()->setWidth(1);
( run in 2.250 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )