dpprabhuindia has asked for the wisdom of the Perl Monks concerning the following question:
I am new to perl, I am facing issue with perl script which does job to get data from command 'rrdtool fetch' to html output with graphs. Now it gives error as Uninitialized value, but same perl script os working on other host which has old perl version. This working perl version on RHEL5 machine
and This perl version on RHEL6 which is not workingperl -v This is perl, v5.8.8 built for i386-linux-thread-multi
#!/usr/bin/perl if ($ENV{'REQUEST_METHOD'} eq "POST") read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } elsif ($ENV{'REQUEST_METHOD'} eq "GET") { $buffer = $ENV{'QUERY_STRING'}; } else { exit 1; } @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/^//g; $list{$name} = $value; } $url = "/aisin/cgi-bin/chkts.pl"; $end = time(); $begin = $end - ($list{period} ? $list{period} : 3456000); $dir = "/home/nagios/var/rrd/ts/$list{sid}"; $lin = $list{top}; opendir(DIR, $dir) || die("can't open directory $dir"); @files = grep(/.+\.rrd$/, readdir(DIR)); closedir(DIR); foreach $f (@files) { next if ( ($list{exceptundo} eq 'on' && $f =~ /UNDO/) || $f =~ /^dbd +ata/ ); next if ( ($list{excepttemp} eq 'on' && $f =~ /TEMP/) || $f =~ /^dbd +ata/ ); open(RRD, "rrdtool fetch $dir/$f AVERAGE -s $begin -e $end|") || next +; @f = (); $i = 0; while (<RRD>) { next if ((!/:/) || /nan +nan +nan/); @f = split; next if ($f[3] == 0); if ($i < 1) { $lsiz1 = $f[1]; $rfre1 = $f[2]; $rsiz1 = $f[3]; } else { $lsiz2 = $f[1]; $rfre2 = $f[2]; $rsiz2 = $f[3]; } $i++; } close(RRD); $count = @f; next if ($count == 0); $b = $f; $b =~ s/(.*)\.rrd/\1/; #printf "%s %.0f %.0f %.0f %.0f %.0f %.0f<br/>\n", $b, $lsiz1, $rfre1 +, $rsiz1, $lsiz2, $rfre2, $rsiz2; $amount{$b} = $lsiz2 - $lsiz1; $ratio{$b} = $amount{$b} / $rsiz2; } print "Content-type: text/html\n\n"; print "<html>\n"; print "<body>\n"; print "<center>\n"; print "<p>\n"; print "<H3>\n"; if ($list{period} <= 86400) { printf "last %d hours growth\n", $list{period} / 3600; } else { printf "last %d days growth\n", $list{period} / 86400; } print "</H3>\n"; print "<table border=1>\n"; printf "<tr><th>top %d amount<th>Mega<th>%%<th>top %d utilization<th>M +ega<th>%%\n", $lin, $lin; $i = 0; foreach $k (sort {$amount{$b}<=>$amount{$a}} (grep {$amount{$_}==$amou +nt{$_}} (keys %amount))) { #foreach $k (sort {$amount{$b}<=>$amount{$a}} (keys %amount)) { $k1[$i] = $k; $a1[$i] = $amount{$k}; $r1[$i] = $ratio{$k}; #printf "<tr><td>%s<td>%.2f\n", $k, $amount{$k} / 1024 / 1024 ; last if (++$i == $lin); } $i = 0; foreach $k (sort {$ratio{$b}<=>$ratio{$a}} (grep {$ratio{$_}==$ratio{$ +_}} (keys %ratio))) { #foreach $k (sort {$ratio{$b}<=>$ratio{$a}} (keys %ratio)) { $k2[$i] = $k; $a2[$i] = $amount{$k}; $r2[$i] = $ratio{$k}; #printf "<tr><td>%s<td>%.2f\n",$k, $ratio{$k} * 100; last if (++$i == $lin); } for ($i = 0; $i < $lin; $i++) { printf "<tr>\n"; printf "<td><a href=%s?sid=%s&period=%d&ts=%s>%s</a>", $url,$list{sid},$list{period},$k1[$i],$k1[$i]; printf "<td align=right>%.2f<td align=right>%.2f", $a1[$i] / 1024 / 1024, $r1[$i] * 100; printf "<td><a href=%s?sid=%s&period=%d&ts=%s>%s</a>", $url,$list{sid},$list{period},$k2[$i],$k2[$i]; printf "<td align=right>%.2f<td align=right>%.2f\n", $a2[$i] / 1024 / 1024, $r2[$i] * 100; } print "</table>\n"; print "</center>\n"; print "</body>\n"; print "</html>\n";
pls help me to fix this issue with latest perl version machine. Thanks in advance for your help. dpprabhuindia
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: perl code not working after moved new host with latest perl version
by Corion (Patriarch) on Mar 28, 2015 at 07:57 UTC | |
You can help us help you better by telling us how it "is not working". What is in the web server error log? What is the output you get? What is the output you expect? | [reply] [Watch: Dir/Any] |
by dpprabhuindia (Initiate) on Mar 28, 2015 at 08:43 UTC | |
sorry I forgot to specify what is error I am facing in RHEL6 with perl version Commands I ran before run from shell promp $ export REQUEST_METHOD=GET $ export QUERY_STRING="sid=xxxxdb&period=2592000&top=10" $ perl -W chktr.pl Here is the error when I run with warning
| [reply] [Watch: Dir/Any] [d/l] |
by Corion (Patriarch) on Mar 28, 2015 at 08:49 UTC | |
You will need to find out why %ratio does not contain the values you expect. Most likely this is because rrdtool outputs things in a different format than what the program expects. | [reply] [Watch: Dir/Any] [d/l] [select] |
by dpprabhuindia (Initiate) on Mar 28, 2015 at 08:59 UTC | |
by dpprabhuindia (Initiate) on Mar 28, 2015 at 10:37 UTC | |
by ww (Archbishop) on Mar 28, 2015 at 11:55 UTC | |
Re: perl code not working after moved new host with latest perl version
by frozenwithjoy (Priest) on Mar 28, 2015 at 08:00 UTC | |
Four things: 1. Are you sure the ENV variables are set properly on the new machine? What do you get when you run the following in terminal for both machines?
2, On which line is the uninitialized value reported? 3. Put the following at the top of your script below the shebang:
4. Now what warnings/errors do you see? (Be sure to declare your variables w/ my) | [reply] [Watch: Dir/Any] [d/l] [select] |
by dpprabhuindia (Initiate) on Mar 28, 2015 at 08:47 UTC | |
sorry I forgot to specify what is error I am facing in RHEL6 with perl version Commands I ran before run from shell promp Here is the error when I run with warning
| [reply] [Watch: Dir/Any] [d/l] [select] |
by dpprabhuindia (Initiate) on Mar 28, 2015 at 08:49 UTC | |
sorry I forgot to specify what is error I am facing in RHEL6 with perl version Commands I ran before run from shell promp $ export REQUEST_METHOD=GET $ export QUERY_STRING="sid=xxxxdb&period=2592000&top=10" $ perl -W chktr.pl Here is the error when I run with warning
| [reply] [Watch: Dir/Any] [d/l] |
by dpprabhuindia (Initiate) on Mar 29, 2015 at 11:27 UTC | |
Re: perl code not working after moved new host with latest perl version
by oiskuu (Hermit) on Mar 28, 2015 at 21:17 UTC | |
It should be noted that rrdtool comes with (optional) perl interface. If properly installed, you don't need external commands to access the data. For example (untested): The pipe and parsing are unnecessary and avoidable. | [reply] [Watch: Dir/Any] [d/l] |
Re: perl code not working after moved new host with latest perl version
by Anonymous Monk on Mar 28, 2015 at 08:33 UTC | |
Looks like its missing the following (needs read use CGI or die; Ovids CGI Course/Ovid's CGI Course )
Might also benefit from | [reply] [Watch: Dir/Any] [d/l] |
by dpprabhuindia (Initiate) on Mar 28, 2015 at 09:27 UTC | |
Now I got error after adding those lines mentioned above Status: 500 Content-type: text/html
Software error:Global symbol "$buffer" requires explicit package name at chktr.pl line 22. Global symbol "$buffer" requires explicit package name at chktr.pl line 25. Global symbol "@pairs" requires explicit package name at chktr.pl line 32. Global symbol "$buffer" requires explicit package name at chktr.pl line 32. Global symbol "$pair" requires explicit package name at chktr.pl line 33. Global symbol "@pairs" requires explicit package name at chktr.pl line 33. Global symbol "$name" requires explicit package name at chktr.pl line 34. Global symbol "$value" requires explicit package name at chktr.pl line 34. Global symbol "$pair" requires explicit package name at chktr.pl line 34. Global symbol "$value" requires explicit package name at chktr.pl line 35. Global symbol "$value" requires explicit package name at chktr.pl line 36. Global symbol "$value" requires explicit package name at chktr.pl line 37. Global symbol "$name" requires explicit package name at chktr.pl line 38. Global symbol "$value" requires explicit package name at chktr.pl line 38. Global symbol "$url" requires explicit package name at chktr.pl line 41. Global symbol "$end" requires explicit package name at chktr.pl line 42. Global symbol "$begin" requires explicit package name at chktr.pl line 43. Global symbol "$end" requires explicit package name at chktr.pl line 43. Global symbol "$dir" requires explicit package name at chktr.pl line 44. Global symbol "$lin" requires explicit package name at chktr.pl line 45. Global symbol "$dir" requires explicit package name at chktr.pl line 48. Global symbol "$dir" requires explicit package name at chktr.pl line 48. Global symbol "@files" requires explicit package name at chktr.pl line 49. Global symbol "$f" requires explicit package name at chktr.pl line 52. Global symbol "@files" requires explicit package name at chktr.pl line 52. Global symbol "$f" requires explicit package name at chktr.pl line 53. Global symbol "$f" requires explicit package name at chktr.pl line 53. Global symbol "$f" requires explicit package name at chktr.pl line 54. Global symbol "$f" requires explicit package name at chktr.pl line 54. Global symbol "$dir" requires explicit package name at chktr.pl line 55. Global symbol "$f" requires explicit package name at chktr.pl line 55. Global symbol "$begin" requires explicit package name at chktr.pl line 55. Global symbol "$end" requires explicit package name at chktr.pl line 55. Global symbol "@f" requires explicit package name at chktr.pl line 56. Global symbol "$i" requires explicit package name at chktr.pl line 57. Global symbol "@f" requires explicit package name at chktr.pl line 60. Global symbol "@f" requires explicit package name at chktr.pl line 61. Global symbol "$i" requires explicit package name at chktr.pl line 62. Global symbol "$lsiz1" requires explicit package name at chktr.pl line 63. | [reply] [Watch: Dir/Any] |
by Anonymous Monk on Mar 28, 2015 at 10:06 UTC | |
| [reply] [Watch: Dir/Any] |
by dpprabhuindia (Initiate) on Mar 28, 2015 at 10:11 UTC | |
by hippo (Bishop) on Mar 28, 2015 at 12:28 UTC | |
Re: perl code not working after moved new host with latest perl version
by Laurent_R (Canon) on Mar 28, 2015 at 10:12 UTC | |
Je suis Charlie.
| [reply] [Watch: Dir/Any] |
by dpprabhuindia (Initiate) on Mar 28, 2015 at 10:20 UTC | |
Sorry in the interest of getting solution for my issue/question I have posted on Perl Guru. I will delete from Perl Guru now. But I like Perl Monks response is best as I experienced today. | [reply] [Watch: Dir/Any] |
by Laurent_R (Canon) on Mar 28, 2015 at 10:54 UTC | |
Update: Fixed a typo.
Je suis Charlie.
| [reply] [Watch: Dir/Any] |