deruytja has asked for the wisdom of the Perl Monks concerning the following question:
Hello folks, at the moment I'm encountering a problem which I don't understand fully. I've written a web based ping script as a project, now i want to integrate a Graph (Via GD::Graph::bars) trough a second script (as I don't want a stored image on the server). The problem is now, I'll always get the error "multipinggraph.pl: Can't use an undefined value as a symbol reference at multiping.pl line 138." from the second script. I think it has something to do with the variable declaration but I've got no idea how to solve the problem.
The first script, which gets called from the html-page is this: multiping.plthe second script, which gets called in the cgi print piece of the code, multipinggraph.pl:#! /usr/bin/perl use strict; use warnings; use FindBin qw ($Bin); use Net::Ping; use CGI; use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use Time::HiRes; use Time::Piece; our $date = Time::Piece->new->strftime('%Y-%d-%m_%H-%M-%S'); #Aktue +lles Datum open (STDERR, '>/home/deruytja/webserver/rifucgi/logs/'.$date.'multipi +ng_error.log'); #Redirecting Standart Error to file my $cgi = new CGI; my $dateiname = $cgi->param('dateiname'); my ($data, $file, $out_file, $wfname, $wfile, $i, $dur,$age, $key, $typ, $val, $p1, $p2, $p3, $ip, $out, $anzahl, $start, $ende, @label, @dauer, %devices, @check); our (@graphdata); if (!length($dateiname) == 0) { $out_file = ("$dateiname\_$date.csv") or die 'Error processing + file: ',$!; } else { $out_file = ("ping_$date.csv") or die 'Error processing file: +',$!; } my $ping1 = Net::Ping->new("tcp", 1); my $ping2 = Net::Ping->new("tcp", 1); my $ping3 = Net::Ping->new("tcp", 1); $ping1->port_number("80"); $ping2->port_number("5432"); $ping3->port_number("301"); $ping1->hires(); $ping2->hires(); $ping3->hires(); my $outpath = '/home/deruytja/webserver/output/multiping/'; open ($out, '>', $outpath.$out_file) or die 'Error processing file: ', +$!; $out->autoflush(1); &UPLOAD; open (INPUT,"</home/deruytja/webserver/rifucgi/temp_ul/$wfname"); &READIN; close INPUT; $anzahl = keys %devices; $i=0; $start = Time::HiRes::time(); foreach (keys %devices) { ($p1, $dur, $ip) = $ping1->ping($devices{$_}); $typ='SIAE'; if (!$p1 == 1) { ($p2, $dur, $ip) = $ping2->ping($devices{$_}); $typ='Huawei'; if (!$p2 == 1) { ($p3, $dur, $ip) = $ping3->ping($devices{$_}); $typ='Siemens'; } if (!$p3 == 1){$typ='Unknown'} } if ($p1 == 1 or $p2 == 1 or $p3 == 1) { $dur = sprintf("%.2f", 1000 * $dur); push (@label,$_); #LinkID ins erste Array push (@dauer,$dur); #duration ins 2te Array $check[$i] = 'ACTIVE;'.$_.';'.$typ.';'.$devices{$_}.';'.$d +ur.'ms'."\n"; } else { push (@label,$_); #LinkID ins erste Array push (@dauer,'0'); #duration ins 2te Array $check[$i] = 'OFFLINE;'.$_.';'.$typ.';'.$devices{$_}."\n"; }; $ping1->close(); $ping2->close(); $ping3->close(); $i++; } $ende = Time::HiRes::time(); push @check, 'Ausführdauer: '.sprintf("%.2f",($ende-$start)).'s'; print $out 'Ping_result;Link_ID;Device_Type;IP;Ping_time'."\n"; foreach (@check) { print $out "$_"; }; close $out; @graphdata = ([@label],[@dauer]); ########################OUTPUT print $cgi->header, $cgi->start_html('Pingergebnis'), $cgi->h1('Ergebnis des Pings'), $cgi->br(); print "<tr>\n"; print $check[-1]; print "</tr>\n"; print $cgi->br(); print "<img src=/rifucgi/multipinggraph.pl>"; print $cgi->br(), $cgi->br(), $cgi->a({-href => "/output/multiping/$out_file"},'Auswertung') +, $cgi->br(), $cgi->a({-href => '../ping.html'},'Back to Paradise'), $cgi->end_html; ########################/OUTPUT sub READIN { while (<INPUT>) #Schleifenstart zum Einlesen der Werte { for ( "\r\n") {$/="\r\n"} chomp; #Abschneiden des INPUT_RECORD_SEPARATORS ($val, $key) = split /;/; #Teilen der Werte nach $val(ue) und $ +key (BGTR ID) if (exists $devices{$key}) {next;} else {$devices{$key} = $val;} } } sub UPLOAD { $wfile = $cgi->param("toping"); $wfname = 'toping'; open (DAT,">/home/deruytja/webserver/rifucgi/temp_ul/$wfname") or die +'Error processing file INPUT: ',$!; binmode $wfile; + binmode DAT; + while (read $wfile, $data, 1024) + { + print DAT $data + } #Upload Teil des Scripts close DAT; }
I (think) I know the code isn't perfect, but works well (It's only for a small amount of users). Thanks for the help!#! /usr/bin/perl #use strict; use warnings; use GD::Graph::bars; require "multiping.pl"; our (@graphdata, $date); my ($mygraph,$graphimage); open (STDERR, '>/home/deruytja/webserver/rifucgi/logs/'.$date.'multipi +nggraph_error.log'); #Redirecting Standart Error to file $mygraph = GD::Graph::bars->new(500, 300); $mygraph->set( x_label => 'Link', y_label => 'Antwortzeit', title => 'Antwortzeiten der Links', ) or warn $mygraph->error; $graphimage = $mygraph->plot(\@graphdata); print "Content-type: image/png\n\n"; binmode STDOUT; print $graphimage->png;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problems calling a second perl script from the first
by kennethk (Abbot) on Apr 13, 2015 at 15:02 UTC | |
by deruytja (Novice) on Apr 13, 2015 at 15:30 UTC | |
by kennethk (Abbot) on Apr 13, 2015 at 16:07 UTC | |
by deruytja (Novice) on Apr 13, 2015 at 16:40 UTC | |
by soonix (Chancellor) on Apr 14, 2015 at 10:37 UTC | |
|
Re: Problems calling a second perl script from the first
by flexvault (Monsignor) on Apr 13, 2015 at 15:01 UTC | |
|
Re: Problems calling a second perl script from the first
by deruytja (Novice) on Apr 14, 2015 at 13:43 UTC |