redirect all the output into an array to support parallelizing in 'serv.pm'

This commit is contained in:
Jordi Sanfeliu 2017-08-29 11:05:37 +02:00
parent ad3664e39d
commit 6e01f6516f
1 changed files with 43 additions and 42 deletions

View File

@ -1,7 +1,7 @@
# #
# Monitorix - A lightweight system monitoring tool. # Monitorix - A lightweight system monitoring tool.
# #
# Copyright (C) 2005-2016 by Jordi Sanfeliu <jordi@fibranet.cat> # Copyright (C) 2005-2017 by Jordi Sanfeliu <jordi@fibranet.cat>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -629,6 +629,7 @@ sub serv_update {
sub serv_cgi { sub serv_cgi {
my ($package, $config, $cgi) = @_; my ($package, $config, $cgi) = @_;
my @output;
my $serv = $config->{serv}; my $serv = $config->{serv};
my @rigid = split(',', ($serv->{rigid} || "")); my @rigid = split(',', ($serv->{rigid} || ""));
@ -674,22 +675,22 @@ sub serv_cgi {
# #
if(lc($config->{iface_mode}) eq "text") { if(lc($config->{iface_mode}) eq "text") {
if($title) { if($title) {
main::graph_header($title, 2); push(@output, main::graph_header($title, 2));
print(" <tr>\n"); push(@output, " <tr>\n");
print(" <td bgcolor='$colors->{title_bg_color}'>\n"); push(@output, " <td bgcolor='$colors->{title_bg_color}'>\n");
} }
my (undef, undef, undef, $data) = RRDs::fetch("$rrd", my (undef, undef, undef, $data) = RRDs::fetch("$rrd",
"--start=-$tf->{nwhen}$tf->{twhen}", "--start=-$tf->{nwhen}$tf->{twhen}",
"AVERAGE", "AVERAGE",
"-r $tf->{res}"); "-r $tf->{res}");
$err = RRDs::error; $err = RRDs::error;
print("ERROR: while fetching $rrd: $err\n") if $err; push(@output, "ERROR: while fetching $rrd: $err\n") if $err;
print(" <pre style='font-size: 12px; color: $colors->{fg_color}';>\n"); push(@output, " <pre style='font-size: 12px; color: $colors->{fg_color}';>\n");
if(lc($serv->{mode}) eq "i") { if(lc($serv->{mode}) eq "i") {
print "Values expressed as incremental or cumulative hits.\n"; push(@output, "Values expressed as incremental or cumulative hits.\n");
} }
print("Time SSH FTP Telnet Samba Fax CUPS F2B IMAP POP3 SMTP Spam Virus\n"); push(@output, "Time SSH FTP Telnet Samba Fax CUPS F2B IMAP POP3 SMTP Spam Virus\n");
print("--------------------------------------------------------------------------------------------------- \n"); push(@output, "--------------------------------------------------------------------------------------------------- \n");
my $line; my $line;
my @row; my @row;
my $time; my $time;
@ -705,19 +706,19 @@ sub serv_cgi {
my ($ssh, $ftp, $telnet, $imap, $smb, $fax, $cups, $pop3, $smtp, $spam, $virus, $f2b) = @$line[$from..$to]; my ($ssh, $ftp, $telnet, $imap, $smb, $fax, $cups, $pop3, $smtp, $spam, $virus, $f2b) = @$line[$from..$to];
@row = ($ssh, $ftp, $telnet, $imap, $smb, $fax, $cups, $f2b, $pop3, $smtp, $spam, $virus); @row = ($ssh, $ftp, $telnet, $imap, $smb, $fax, $cups, $f2b, $pop3, $smtp, $spam, $virus);
if(lc($serv->{mode}) eq "i") { if(lc($serv->{mode}) eq "i") {
printf(" %2d$tf->{tc} %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d\n", $time, @row); push(@output, sprintf(" %2d$tf->{tc} %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d\n", $time, @row));
} elsif(lc($serv->{mode}) eq "l") { } elsif(lc($serv->{mode}) eq "l") {
printf(" %2d$tf->{tc} %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n", $time, @row); push(@output, sprintf(" %2d$tf->{tc} %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n", $time, @row));
} }
} }
print(" </pre>\n"); push(@output, " </pre>\n");
if($title) { if($title) {
print(" </td>\n"); push(@output, " </td>\n");
print(" </tr>\n"); push(@output, " </tr>\n");
main::graph_footer(); push(@output, main::graph_footer());
} }
print(" <br>\n"); push(@output, " <br>\n");
return; return @output;
} }
@ -748,7 +749,7 @@ sub serv_cgi {
} }
if($title) { if($title) {
main::graph_header($title, 2); push(@output, main::graph_header($title, 2));
} }
@riglim = @{setup_riglim($rigid[0], $limit[0])}; @riglim = @{setup_riglim($rigid[0], $limit[0])};
if(lc($serv->{mode}) eq "l") { if(lc($serv->{mode}) eq "l") {
@ -879,8 +880,8 @@ sub serv_cgi {
} }
if($title) { if($title) {
print(" <tr>\n"); push(@output, " <tr>\n");
print(" <td bgcolor='$colors->{title_bg_color}'>\n"); push(@output, " <td bgcolor='$colors->{title_bg_color}'>\n");
} }
($width, $height) = split('x', $config->{graph_size}->{main}); ($width, $height) = split('x', $config->{graph_size}->{main});
if($silent =~ /imagetag/) { if($silent =~ /imagetag/) {
@ -922,7 +923,7 @@ sub serv_cgi {
@CDEF, @CDEF,
@tmp); @tmp);
$err = RRDs::error; $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") { if(lc($config->{enable_zoom}) eq "y") {
($width, $height) = split('x', $config->{graph_size}->{zoom}); ($width, $height) = split('x', $config->{graph_size}->{zoom});
$picz = $rrd{$version}->("$IMG_DIR" . "$IMG1z", $picz = $rrd{$version}->("$IMG_DIR" . "$IMG1z",
@ -956,12 +957,12 @@ sub serv_cgi {
@CDEF, @CDEF,
@tmpz); @tmpz);
$err = RRDs::error; $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 =~ /serv1/)) { if($title || ($silent =~ /imagetag/ && $graph =~ /serv1/)) {
if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{enable_zoom}) eq "y") {
if(lc($config->{disable_javascript_void}) eq "y") { if(lc($config->{disable_javascript_void}) eq "y") {
print(" <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1z . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1 . "' border='0'></a>\n"); push(@output, " <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1z . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1 . "' border='0'></a>\n");
} else { } else {
if($version eq "new") { if($version eq "new") {
$picz_width = $picz->{image_width} * $config->{global_zoom}; $picz_width = $picz->{image_width} * $config->{global_zoom};
@ -970,16 +971,16 @@ sub serv_cgi {
$picz_width = $width + 115; $picz_width = $width + 115;
$picz_height = $height + 100; $picz_height = $height + 100;
} }
print(" <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1 . "' border='0'></a>\n"); push(@output, " <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1 . "' border='0'></a>\n");
} }
} else { } else {
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1 . "'>\n"); push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1 . "'>\n");
} }
} }
if($title) { if($title) {
print(" </td>\n"); push(@output, " </td>\n");
print(" <td valign='top' bgcolor='" . $colors->{title_bg_color} . "'>\n"); push(@output, " <td valign='top' bgcolor='" . $colors->{title_bg_color} . "'>\n");
} }
@riglim = @{setup_riglim($rigid[1], $limit[1])}; @riglim = @{setup_riglim($rigid[1], $limit[1])};
undef(@tmp); undef(@tmp);
@ -1044,7 +1045,7 @@ sub serv_cgi {
@CDEF, @CDEF,
@tmp); @tmp);
$err = RRDs::error; $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") { if(lc($config->{enable_zoom}) eq "y") {
($width, $height) = split('x', $config->{graph_size}->{zoom}); ($width, $height) = split('x', $config->{graph_size}->{zoom});
$picz = $rrd{$version}->("$IMG_DIR" . "$IMG2z", $picz = $rrd{$version}->("$IMG_DIR" . "$IMG2z",
@ -1067,12 +1068,12 @@ sub serv_cgi {
@CDEF, @CDEF,
@tmpz); @tmpz);
$err = RRDs::error; $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 =~ /serv2/)) { if($title || ($silent =~ /imagetag/ && $graph =~ /serv2/)) {
if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{enable_zoom}) eq "y") {
if(lc($config->{disable_javascript_void}) eq "y") { if(lc($config->{disable_javascript_void}) eq "y") {
print(" <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2z . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2 . "' border='0'></a>\n"); push(@output, " <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2z . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2 . "' border='0'></a>\n");
} else { } else {
if($version eq "new") { if($version eq "new") {
$picz_width = $picz->{image_width} * $config->{global_zoom}; $picz_width = $picz->{image_width} * $config->{global_zoom};
@ -1081,10 +1082,10 @@ sub serv_cgi {
$picz_width = $width + 115; $picz_width = $width + 115;
$picz_height = $height + 100; $picz_height = $height + 100;
} }
print(" <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2 . "' border='0'></a>\n"); push(@output, " <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2 . "' border='0'></a>\n");
} }
} else { } else {
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2 . "'>\n"); push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2 . "'>\n");
} }
} }
@ -1165,7 +1166,7 @@ sub serv_cgi {
@CDEF, @CDEF,
@tmp); @tmp);
$err = RRDs::error; $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") { if(lc($config->{enable_zoom}) eq "y") {
undef(@tmp); undef(@tmp);
($width, $height) = split('x', $config->{graph_size}->{zoom}); ($width, $height) = split('x', $config->{graph_size}->{zoom});
@ -1191,12 +1192,12 @@ sub serv_cgi {
@CDEF, @CDEF,
@tmpz); @tmpz);
$err = RRDs::error; $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 =~ /serv3/)) { if($title || ($silent =~ /imagetag/ && $graph =~ /serv3/)) {
if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{enable_zoom}) eq "y") {
if(lc($config->{disable_javascript_void}) eq "y") { if(lc($config->{disable_javascript_void}) eq "y") {
print(" <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3z . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3 . "' border='0'></a>\n"); push(@output, " <a href=\"" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3z . "\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3 . "' border='0'></a>\n");
} else { } else {
if($version eq "new") { if($version eq "new") {
$picz_width = $picz->{image_width} * $config->{global_zoom}; $picz_width = $picz->{image_width} * $config->{global_zoom};
@ -1205,20 +1206,20 @@ sub serv_cgi {
$picz_width = $width + 115; $picz_width = $width + 115;
$picz_height = $height + 100; $picz_height = $height + 100;
} }
print(" <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3 . "' border='0'></a>\n"); push(@output, " <a href=\"javascript:void(window.open('" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3z . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3 . "' border='0'></a>\n");
} }
} else { } else {
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3 . "'>\n"); push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3 . "'>\n");
} }
} }
if($title) { if($title) {
print(" </td>\n"); push(@output, " </td>\n");
print(" </tr>\n"); push(@output, " </tr>\n");
main::graph_footer(); push(@output, main::graph_footer());
} }
print(" <br>\n"); push(@output, " <br>\n");
return; return @output;
} }
1; 1;