Hi Jesse,
I checked my code and couldn't find anything wrong in it. I don't know why
the browser thinks it's and xml where as I am printing HTML all across the
script. I am attaching the script herewith as well. If you or anyone on this
list finds the bug, pls. let me know.
Thanks
Bal.
################# SCRIPT ##########################
package perfmonpvt;
use base 'CGI::Application';
use strict;
use Sybase::CTlib;
sub setup {
my $self = shift;
$self->start_mode('mode1');
$self->run_modes(
'mode1' => 'showsrvrs',
'mode2' => 'showdetails'
);
}
sub teardown {
my $self = shift;
}
sub showsrvrs {
my $self = shift;
# Get CGI query object
my $q = $self->query();
my $dbh = Sybase::CTlib->ct_connect('perfmon', 'perfmon_ps',
'SYB_NJ6'); ## Connect to the server.
$dbh->ct_sql('use perfmondb');
my $output = '';
if($dbh eq undef)
{
$output .= $q->start_html();
$output .= $q->blockquote("<h1>Connection to server failed. </h1>");
$output .= $q->blockquote("This could be due to an invalid Login
Name,Password,Server Name.");
$output .= $q->blockquote("If you feel all of these are correct, then
pls check of the server is running and your login is not locked.");
$output .= $q->blockquote("Still if you can't connect, Pls check you
interfaces of sql.ini files.");
$output .= $q->end_html();
return $output;
exit 0;
}
my @srvrs;
my $app= $dbh->ct_sql('select Name from Servers');
foreach my $row (@$app) {
foreach my $col (@$row) {
push(@srvrs,$col);
}
}
$output .= $q->start_html(-title => 'Sysmon Details');
$output .= $q->blockquote($q->strong("<h1>Check Sysmon
Details</h1>"));
$output .= $q->start_form();
{
local($") = '';
$output .= $q->blockquote("Select Server : ",
$q->popup_menu(-name=> 'srv', -values =>\@srvrs));
}
{
local($") = '';
$output .= $q->blockquote("Select Item(s) : ",
$q->checkbox_group(-name=> 'opt', -values =>['CPU
Busy','TPS','Deadlocks','IUD','Switches','Locks','Spinlock'],
-default => 'CPU Busy'
));
}
{
local($") = '';
$output .= $q->blockquote("Start Date : ",
$q->textfield(-name=> 'sdt')," Format: mmm dd yyyy or mm/dd/yyyy");
}
{
local($") = '';
$output .= $q->blockquote("End Date : ",
$q->textfield(-name=> 'edt')," Format: mmm dd yyyy or mm/dd/yyyy");
}
{
local($") = '';
$output .= $q->blockquote("Show Data Values : ",
$q->radio_group(-name=> 'gv', -values =>['Yes','No'],
-default => 'Yes'
));
}
{
local($") = '';
$output .= $q->hidden(-name => 'rm', -value => 'mode2', -override=>1
);
}
{
local($") = '';
$output .= $q->submit("View Report");
}
$output .= $q->end_form();
$output .= $q->end_html();
return $output;
}
sub showdetails {
my $self = shift;
#Get CGI query object
my $q = $self->query();
my $srv = $q->param("srv");
my @opt = $q->param("opt");
my $sdt = $q->param("sdt");
my $edt = $q->param("edt");
my $gv = $q->param("gv");
my $block = "";
my $output = '';
foreach my $o (@opt)
{
$block = "$block"." '$o',";
}
$block = substr($block, 0, length($block) - 1);
my $cmde = "exec perfmondb..proc_sysmon_crosstab
'$srv','$sdt','$edt', $block " ;
my $dbh = Sybase::CTlib->ct_connect('perfmon', 'perfmon_ps',
'SYB_NJ6'); ## Connect to the server.
$output .= $q->start_html(-title => 'Sysmon Details');
if($dbh eq undef)
{
$output .= $q->blockquote("<h1>Connection to server failed. </h1>");
$output .= $q->blockquote("This could be due to an invalid Login
Name,Password,Server Name.");
$output .= $q->blockquote("If you feel all of these are correct,
then pls check of the server is running and your login is not locked.");
$output .= $q->blockquote("Still if you can't connect, Pls check you
interfaces of sql.ini files.");
$output .= $q->end_html();
return $output;
exit 0;
}
$dbh->ct_sql("use perfmondb");
my (@dr,$ret);
$dbh->ct_execute($cmde);
$output .= $q->blockquote("<h1>Check Sysmon Details</h1>");
$output .= $q->blockquote("Selected Server : $srv");
$output .= $q->blockquote("Selected Report : $block");
$output .= $q->start_form();
$output .= $q->hidden(-name => 'rm', -value => 'mode1',
-override=>1);
$output .= $q->submit("Next Report");
$output .= $q->end_form();
my (@dt,@cpu,@tps);
$output .= "<TABLE cellSpacing=0 cellPadding=0 width='100%'
border=1> <TBODY> <TR>";
while($dbh->ct_results($ret) == CS_SUCCEED) {
next unless $dbh->ct_fetchable($ret);
my @cols=$dbh->ct_col_names();
foreach my $kv (@cols) {
$output .= "<TD> <P
align=center><STRONG>$kv</STRONG></P></TD>" unless($kv eq "COL\(1\)");
}
$output .= "</TR>";
while(@dr = $dbh->ct_fetch) {
push(@dt,@dr[1]);
push(@cpu,@dr[3]);
push(@tps,@dr[4]);
# push(@data,$dr) unless($dr eq "0" && $dr == 0);
foreach (@dr) {
$output .= "<TD> <P align=center> $_ </P></TD>";
}
$output .= "</TR>";
}
$output .= "</TR>";
}
$output .= "</TR> </TBODY></TABLE>";
####################### START GRAPH HERE
#################################################
use GD::Graph;
use CGI qw(:standard);
use GD::Graph::lines;
my @gdata = (
[ @dt ],
[ @cpu ],
[ @tps ]
);
my $graph = GD::Graph::lines->new(900, 500);
my @leg = split("\,",$block);
$graph->set_legend(@leg);
$graph->set_values_font('c:\winnt\fonts\arial.ttf',12);
$graph->set_x_label_font('c:\winnt\fonts\arial.ttf',12);
$graph->set_y_label_font('c:\winnt\fonts\arial.ttf',12);
$graph->set_x_axis_font('c:\winnt\fonts\arial.ttf',12);
$graph->set_y_axis_font('c:\winnt\fonts\arial.ttf',12);
$graph->set_legend_font('c:\winnt\fonts\arial.ttf',12);
$graph->set(show_values => @cpu) unless($gv eq "No");
$graph->set(show_values => @tps) unless($gv eq "No");
$graph->set(
x_label => 'Sample Time',
y_label => 'Values',
title => '' ,
x_label_position => '.5',
x_labels_vertical => '1',
values_vertical => '1'
);
my $gd = $graph->plot(\@gdata);
open(IMG, '>c:/progra~1/apache~1/apache/htdocs/pvtgraph.png') or die $!;
binmode IMG;
print IMG $gd->png;
close IMG;
#...
my $format = $graph->export_format;
$output .= $q->header_props(-type =>"image/$format");
$output .= $q->blockquote("");
$output .= $q->blockquote("<Center><h2>Graph</h2></Center>");
my ($usr, $stim, $cusr, $cstim) = times;
$output .= "<Center><IMG
SRC=\"http://dbainet/pvtgraph.png?$stim?$usr?cusr?cstim\"></Center>";
###################### GRAPH END HERE
################################################
$output .= $q->end_html();
return $output;
}
1;
######################## END OF SCRIPT ####################################
-----Original Message-----
From: Jesse Erlbaum [mailto:[EMAIL PROTECTED]]
Sent: Monday, May 13, 2002 10:50 AM
To: [EMAIL PROTECTED]
Subject: RE: [cgiapp] CGI Error [Solved!!]
Hi Bal --
> Commenting out the following lines in the CGI.PM resolved the
> error. I don't
> know if this is the correct way or not, if anyone has a
> different way to
> solve this, pls. let me know.
I would definitely NOT comment arbitrary lines from another module without
understanding WHY doing so changes the situation. I am 100% positive that
you have a bug in your code, and that there is no bug in CGI.pm which is
causing this to happen.
Before you go and comment out lines from CGI.pm, take a close look at the
situation and figure out why commenting those lines seem to fix your
problem. I am certain that you will discover a bug in your own code.
-Jesse-
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]