diff --git a/lib/nfsc.pm b/lib/nfsc.pm index 4ffdd24..e02465e 100644 --- a/lib/nfsc.pm +++ b/lib/nfsc.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 @@ -217,6 +217,7 @@ sub nfsc_update { sub nfsc_cgi { my ($package, $config, $cgi) = @_; + my @output; my $nfsc = $config->{nfsc}; my @rigid = split(',', ($nfsc->{rigid} || "")); @@ -307,20 +308,20 @@ sub nfsc_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 $str; my $line1; my $line2; - print("
\n");
+		push(@output, "    
\n");
 		foreach my $t (@nfsv) {
 			$str = sprintf("%12s ", $t);
 			$line1 .= $str;
@@ -328,8 +329,8 @@ sub nfsc_cgi {
 		}
 		$line1 .= sprintf("%12s %12s %12s", "calls", "retrans", "authrefrsh");
 		$line2 .= "-------------" . "-------------" . "-------------";
-		print("Time $line1\n");
-		print("-----$line2\n");
+		push(@output, "Time $line1\n");
+		push(@output, "-----$line2\n");
 		my $line;
 		my @row;
 		my $time;
@@ -347,16 +348,16 @@ sub nfsc_cgi {
 			push(@row, @$line[50..52]);
 			$line1 .= "%12d %12d %12d ";
 			$time = $time - (1 / $tf->{ts});
-			printf(" %2d$tf->{tc} $line1\n", $time, @row);
+			push(@output, sprintf(" %2d$tf->{tc} $line1\n", $time, @row));
 		}
-		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; } @@ -398,12 +399,12 @@ sub nfsc_cgi { } 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"); } for($n = 0; $n < 10; $n++) { my $str = trim((split(',', $nfsc->{graph_0}))[$n]) || ""; @@ -453,7 +454,7 @@ sub nfsc_cgi { @tmp, "COMMENT: \\n"); $err = RRDs::error; - print("ERROR: while graphing $IMG_DIR" . "$IMG1: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG1: $err\n") if $err; if(lc($config->{enable_zoom}) eq "y") { ($width, $height) = split('x', $config->{graph_size}->{zoom}); $picz = $rrd{$version}->("$IMG_DIR" . "$IMG1z", @@ -471,12 +472,12 @@ sub nfsc_cgi { @CDEF, @tmpz); $err = RRDs::error; - print("ERROR: while graphing $IMG_DIR" . "$IMG1z: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG1z: $err\n") if $err; } if($title || ($silent =~ /imagetag/ && $graph =~ /nfsc1/)) { if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{disable_javascript_void}) eq "y") { - print(" {url} . "/" . $config->{imgs_dir} . $IMG1z . "\">\n"); + push(@output, " {url} . "/" . $config->{imgs_dir} . $IMG1z . "\">\n"); } else { if($version eq "new") { $picz_width = $picz->{image_width} * $config->{global_zoom}; @@ -485,10 +486,10 @@ sub nfsc_cgi { $picz_width = $width + 115; $picz_height = $height + 100; } - print(" {url} . "/" . $config->{imgs_dir} . $IMG1z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); + push(@output, " {url} . "/" . $config->{imgs_dir} . $IMG1z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); } } else { - print(" \n"); + push(@output, " \n"); } } @@ -546,7 +547,7 @@ sub nfsc_cgi { @CDEF, @tmp); $err = RRDs::error; - print("ERROR: while graphing $IMG_DIR" . "$IMG2: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG2: $err\n") if $err; if(lc($config->{enable_zoom}) eq "y") { ($width, $height) = split('x', $config->{graph_size}->{zoom}); $picz = $rrd{$version}->("$IMG_DIR" . "$IMG2z", @@ -564,12 +565,12 @@ sub nfsc_cgi { @CDEF, @tmpz); $err = RRDs::error; - print("ERROR: while graphing $IMG_DIR" . "$IMG2z: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG2z: $err\n") if $err; } if($title || ($silent =~ /imagetag/ && $graph =~ /nfsc2/)) { if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{disable_javascript_void}) eq "y") { - print(" {url} . "/" . $config->{imgs_dir} . $IMG2z . "\">\n"); + push(@output, " {url} . "/" . $config->{imgs_dir} . $IMG2z . "\">\n"); } else { if($version eq "new") { $picz_width = $picz->{image_width} * $config->{global_zoom}; @@ -578,16 +579,16 @@ sub nfsc_cgi { $picz_width = $width + 115; $picz_height = $height + 100; } - print(" {url} . "/" . $config->{imgs_dir} . $IMG2z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); + push(@output, " {url} . "/" . $config->{imgs_dir} . $IMG2z . "','','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[2], $limit[2])}; undef(@tmp); @@ -650,7 +651,7 @@ sub nfsc_cgi { @CDEF, @tmp); $err = RRDs::error; - print("ERROR: while graphing $IMG_DIR" . "$IMG3: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG3: $err\n") if $err; if(lc($config->{enable_zoom}) eq "y") { ($width, $height) = split('x', $config->{graph_size}->{zoom}); $picz = $rrd{$version}->("$IMG_DIR" . "$IMG3z", @@ -669,12 +670,12 @@ sub nfsc_cgi { @CDEF, @tmpz); $err = RRDs::error; - print("ERROR: while graphing $IMG_DIR" . "$IMG3z: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG3z: $err\n") if $err; } if($title || ($silent =~ /imagetag/ && $graph =~ /nfsc3/)) { if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{disable_javascript_void}) eq "y") { - print(" {url} . "/" . $config->{imgs_dir} . $IMG3z . "\">\n"); + push(@output, " {url} . "/" . $config->{imgs_dir} . $IMG3z . "\">\n"); } else { if($version eq "new") { $picz_width = $picz->{image_width} * $config->{global_zoom}; @@ -683,10 +684,10 @@ sub nfsc_cgi { $picz_width = $width + 115; $picz_height = $height + 100; } - print(" {url} . "/" . $config->{imgs_dir} . $IMG3z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); + push(@output, " {url} . "/" . $config->{imgs_dir} . $IMG3z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); } } else { - print(" \n"); + push(@output, " \n"); } } @@ -751,7 +752,7 @@ sub nfsc_cgi { @CDEF, @tmp); $err = RRDs::error; - print("ERROR: while graphing $IMG_DIR" . "$IMG4: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG4: $err\n") if $err; if(lc($config->{enable_zoom}) eq "y") { ($width, $height) = split('x', $config->{graph_size}->{zoom}); $picz = $rrd{$version}->("$IMG_DIR" . "$IMG4z", @@ -770,12 +771,12 @@ sub nfsc_cgi { @CDEF, @tmpz); $err = RRDs::error; - print("ERROR: while graphing $IMG_DIR" . "$IMG4z: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG4z: $err\n") if $err; } if($title || ($silent =~ /imagetag/ && $graph =~ /nfsc4/)) { if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{disable_javascript_void}) eq "y") { - print(" {url} . "/" . $config->{imgs_dir} . $IMG4z . "\">\n"); + push(@output, " {url} . "/" . $config->{imgs_dir} . $IMG4z . "\">\n"); } else { if($version eq "new") { $picz_width = $picz->{image_width} * $config->{global_zoom}; @@ -784,10 +785,10 @@ sub nfsc_cgi { $picz_width = $width + 115; $picz_height = $height + 100; } - print(" {url} . "/" . $config->{imgs_dir} . $IMG4z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); + push(@output, " {url} . "/" . $config->{imgs_dir} . $IMG4z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); } } else { - print(" \n"); + push(@output, " \n"); } } @@ -852,7 +853,7 @@ sub nfsc_cgi { @CDEF, @tmp); $err = RRDs::error; - print("ERROR: while graphing $IMG_DIR" . "$IMG5: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG5: $err\n") if $err; if(lc($config->{enable_zoom}) eq "y") { ($width, $height) = split('x', $config->{graph_size}->{zoom}); $picz = $rrd{$version}->("$IMG_DIR" . "$IMG5z", @@ -871,12 +872,12 @@ sub nfsc_cgi { @CDEF, @tmpz); $err = RRDs::error; - print("ERROR: while graphing $IMG_DIR" . "$IMG5z: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG5z: $err\n") if $err; } if($title || ($silent =~ /imagetag/ && $graph =~ /nfsc5/)) { if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{disable_javascript_void}) eq "y") { - print(" {url} . "/" . $config->{imgs_dir} . $IMG5z . "\">\n"); + push(@output, " {url} . "/" . $config->{imgs_dir} . $IMG5z . "\">\n"); } else { if($version eq "new") { $picz_width = $picz->{image_width} * $config->{global_zoom}; @@ -885,10 +886,10 @@ sub nfsc_cgi { $picz_width = $width + 115; $picz_height = $height + 100; } - print(" {url} . "/" . $config->{imgs_dir} . $IMG5z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); + push(@output, " {url} . "/" . $config->{imgs_dir} . $IMG5z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); } } else { - print(" \n"); + push(@output, " \n"); } } @@ -944,7 +945,7 @@ sub nfsc_cgi { @CDEF, @tmp); $err = RRDs::error; - print("ERROR: while graphing $IMG_DIR" . "$IMG6: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG6: $err\n") if $err; if(lc($config->{enable_zoom}) eq "y") { ($width, $height) = split('x', $config->{graph_size}->{zoom}); $picz = $rrd{$version}->("$IMG_DIR" . "$IMG6z", @@ -966,12 +967,12 @@ sub nfsc_cgi { @CDEF, @tmpz); $err = RRDs::error; - print("ERROR: while graphing $IMG_DIR" . "$IMG6z: $err\n") if $err; + push(@output, "ERROR: while graphing $IMG_DIR" . "$IMG6z: $err\n") if $err; } if($title || ($silent =~ /imagetag/ && $graph =~ /nfsc6/)) { if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{disable_javascript_void}) eq "y") { - print(" {url} . "/" . $config->{imgs_dir} . $IMG6z . "\">\n"); + push(@output, " {url} . "/" . $config->{imgs_dir} . $IMG6z . "\">\n"); } else { if($version eq "new") { $picz_width = $picz->{image_width} * $config->{global_zoom}; @@ -980,20 +981,20 @@ sub nfsc_cgi { $picz_width = $width + 115; $picz_height = $height + 100; } - print(" {url} . "/" . $config->{imgs_dir} . $IMG6z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); + push(@output, " {url} . "/" . $config->{imgs_dir} . $IMG6z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); } } else { - 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; } 1;