diff --git a/lib/phpapc.pm b/lib/phpapc.pm index 3dd7a1b..956028a 100644 --- a/lib/phpapc.pm +++ b/lib/phpapc.pm @@ -1,7 +1,7 @@ # # Monitorix - A lightweight system monitoring tool. # -# Copyright (C) 2005-2016 by Jordi Sanfeliu +# Copyright (C) 2005-2017 by Jordi Sanfeliu # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -196,6 +196,7 @@ sub phpapc_update { sub phpapc_cgi { my $myself = (caller(0))[3]; my ($package, $config, $cgi) = @_; + my @output; my $phpapc = $config->{phpapc}; my @rigid = split(',', ($phpapc->{rigid} || "")); @@ -245,33 +246,33 @@ sub phpapc_cgi { # if(lc($config->{iface_mode}) eq "text") { if($title) { - main::graph_header($title, 2); - print(" \n"); - print(" \n"); + push(@output, main::graph_header($title, 2)); + push(@output, " \n"); + push(@output, " \n"); } my (undef, undef, undef, $data) = RRDs::fetch("$rrd", "--start=-$tf->{nwhen}$tf->{twhen}", "AVERAGE", "-r $tf->{res}"); $err = RRDs::error; - print("ERROR: while fetching $rrd: $err\n") if $err; + push(@output, "ERROR: while fetching $rrd: $err\n") if $err; my $line1; my $line2; my $line3; - print("
\n");
-		print("    ");
+		push(@output, "    
\n");
+		push(@output, "    ");
 		for($n = 0; $n < scalar(my @pl = split(',', $phpapc->{list})); $n++) {
 			$line1 = "                                           ";
 			$line2 .= "    Free   Used  Frag.   Hits  Miss. CacheF";
 			$line3 .= "-------------------------------------------";
 			if($line1) {
 				my $i = length($line1);
-				printf(sprintf("%${i}s", sprintf("%s", trim($pl[$n]))));
+				push(@output, sprintf(sprintf("%${i}s", sprintf("%s", trim($pl[$n])))));
 			}
 		}
-		print("\n");
-		print("Time$line2\n");
-		print("----$line3 \n");
+		push(@output, "\n");
+		push(@output, "Time$line2\n");
+		push(@output, "----$line3 \n");
 		my $line;
 		my @row;
 		my $time;
@@ -281,24 +282,24 @@ sub phpapc_cgi {
 		for($n = 0, $time = $tf->{tb}; $n < ($tf->{tb} * $tf->{ts}); $n++) {
 			$line = @$data[$n];
 			$time = $time - (1 / $tf->{ts});
-			printf(" %2d$tf->{tc}", $time);
+			push(@output, sprintf(" %2d$tf->{tc}", $time));
 			for($n2 = 0; $n2 < scalar(my @pl = split(',', $phpapc->{list})); $n2++) {
 				undef(@row);
 				$from = $n2 * 14;
 				$to = $from + 14;
 				my (undef, $free, $used, $hits, $miss, $cachf, undef, undef, $frag) = @$line[$from..$to];
-				printf("  %5.1f%% %5.1f%% %5.1f%% %5.1f%% %5.1f%% %6d", $free || 0, $used || 0, $frag || 0, $hits || 0, $miss || 0, $cachf || 0);
+				push(@output, sprintf("  %5.1f%% %5.1f%% %5.1f%% %5.1f%% %5.1f%% %6d", $free || 0, $used || 0, $frag || 0, $hits || 0, $miss || 0, $cachf || 0));
 			}
-			print("\n");
+			push(@output, "\n");
 		}
-		print("    
\n"); + push(@output, "
\n"); if($title) { - print(" \n"); - print(" \n"); - main::graph_footer(); + push(@output, " \n"); + push(@output, " \n"); + push(@output, main::graph_footer()); } - print("
\n"); - return; + push(@output, "
\n"); + return @output; } @@ -350,15 +351,15 @@ sub phpapc_cgi { } if($e) { - print("
\n"); + push(@output, "
\n"); } if($title) { - main::graph_header($title, 2); + push(@output, main::graph_header($title, 2)); } @riglim = @{setup_riglim($rigid[0], $limit[0])}; if($title) { - print(" \n"); - print(" \n"); + push(@output, " \n"); + push(@output, " \n"); } undef(@tmp); undef(@tmpz); @@ -422,7 +423,7 @@ sub phpapc_cgi { "COMMENT: \\n", $uptimeline); $err = RRDs::error; - print("ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3]: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3]: $err\n") if $err; if(lc($config->{enable_zoom}) eq "y") { ($width, $height) = split('x', $config->{graph_size}->{zoom}); $picz = $rrd{$version}->("$IMG_DIR" . "$IMGz[$e * 3]", @@ -443,13 +444,13 @@ sub phpapc_cgi { @CDEF, @tmpz); $err = RRDs::error; - print("ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3]: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3]: $err\n") if $err; } $e2 = $e + 1; if($title || ($silent =~ /imagetag/ && $graph =~ /phpapc$e2/)) { if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{disable_javascript_void}) eq "y") { - print(" {url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3] . "\">\n"); + push(@output, " {url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3] . "\">\n"); } else { if($version eq "new") { $picz_width = $picz->{image_width} * $config->{global_zoom}; @@ -458,16 +459,16 @@ sub phpapc_cgi { $picz_width = $width + 115; $picz_height = $height + 100; } - print(" {url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); + push(@output, " {url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); } } else { - print(" \n"); + push(@output, " \n"); } } if($title) { - print(" \n"); - print(" \n"); + push(@output, " \n"); + push(@output, " \n"); } @riglim = @{setup_riglim($rigid[1], $limit[1])}; undef(@tmp); @@ -515,7 +516,7 @@ sub phpapc_cgi { @CDEF, @tmp); $err = RRDs::error; - print("ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3 + 1]: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3 + 1]: $err\n") if $err; if(lc($config->{enable_zoom}) eq "y") { ($width, $height) = split('x', $config->{graph_size}->{zoom}); $picz = $rrd{$version}->("$IMG_DIR" . "$IMGz[$e * 3 + 1]", @@ -536,13 +537,13 @@ sub phpapc_cgi { @CDEF, @tmpz); $err = RRDs::error; - print("ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3 + 1]: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3 + 1]: $err\n") if $err; } $e2 = $e + 2; if($title || ($silent =~ /imagetag/ && $graph =~ /phpapc$e2/)) { if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{disable_javascript_void}) eq "y") { - print(" {url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3 + 1] . "\">\n"); + push(@output, " {url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3 + 1] . "\">\n"); } else { if($version eq "new") { $picz_width = $picz->{image_width} * $config->{global_zoom}; @@ -551,10 +552,10 @@ sub phpapc_cgi { $picz_width = $width + 115; $picz_height = $height + 100; } - print(" {url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3 + 1] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); + push(@output, " {url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3 + 1] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); } } else { - print(" \n"); + push(@output, " \n"); } } @@ -600,7 +601,7 @@ sub phpapc_cgi { @CDEF, @tmp); $err = RRDs::error; - print("ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3 + 2]: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3 + 2]: $err\n") if $err; if(lc($config->{enable_zoom}) eq "y") { ($width, $height) = split('x', $config->{graph_size}->{zoom}); $picz = $rrd{$version}->("$IMG_DIR" . "$IMGz[$e * 3 + 2]", @@ -622,13 +623,13 @@ sub phpapc_cgi { @CDEF, @tmpz); $err = RRDs::error; - print("ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3 + 2]: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3 + 2]: $err\n") if $err; } $e2 = $e + 3; if($title || ($silent =~ /imagetag/ && $graph =~ /phpapc$e2/)) { if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{disable_javascript_void}) eq "y") { - print(" {url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3 + 2] . "\">\n"); + push(@output, " {url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3 + 2] . "\">\n"); } else { if($version eq "new") { $picz_width = $picz->{image_width} * $config->{global_zoom}; @@ -637,31 +638,31 @@ sub phpapc_cgi { $picz_width = $width + 115; $picz_height = $height + 100; } - print(" {url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3 + 2] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); + push(@output, " {url} . "/" . $config->{imgs_dir} . $IMGz[$e * 3 + 2] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); } } else { - print(" \n"); + push(@output, " \n"); } } if($title) { - print(" \n"); - print(" \n"); + push(@output, " \n"); + push(@output, " \n"); - print(" \n"); - print " \n"; - print " \n"; - print " \n"; - print "   " . trim($url) . "\n"; - print " \n"; - print " \n"; - print(" \n"); - main::graph_footer(); + push(@output, " \n"); + push(@output, " \n"); + push(@output, " \n"); + push(@output, " \n"); + push(@output, "   " . trim($url) . "\n"); + push(@output, " \n"); + push(@output, " \n"); + push(@output, " \n"); + push(@output, main::graph_footer()); } $e++; } - print("
\n"); - return; + push(@output, "
\n"); + return @output; } 1;