mirror of https://github.com/mikaku/Monitorix.git
redirect all the output into an array to support parallelizing in 'user.pm'
This commit is contained in:
parent
b3a8f1c446
commit
bfb3b1787f
81
lib/user.pm
81
lib/user.pm
|
@ -1,7 +1,7 @@
|
|||
#
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -161,6 +161,7 @@ sub user_update {
|
|||
|
||||
sub user_cgi {
|
||||
my ($package, $config, $cgi) = @_;
|
||||
my @output;
|
||||
|
||||
my $user = $config->{user};
|
||||
my @rigid = split(',', ($user->{rigid} || ""));
|
||||
|
@ -204,19 +205,19 @@ sub user_cgi {
|
|||
#
|
||||
if(lc($config->{iface_mode}) eq "text") {
|
||||
if($title) {
|
||||
main::graph_header($title, 2);
|
||||
print(" <tr>\n");
|
||||
print(" <td bgcolor='$colors->{title_bg_color}'>\n");
|
||||
push(@output, main::graph_header($title, 2));
|
||||
push(@output, " <tr>\n");
|
||||
push(@output, " <td bgcolor='$colors->{title_bg_color}'>\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;
|
||||
print(" <pre style='font-size: 12px; color: $colors->{fg_color}';>\n");
|
||||
print("Time Logged In Samba Netatalk\n");
|
||||
print("------------------------------------- \n");
|
||||
push(@output, "ERROR: while fetching $rrd: $err\n") if $err;
|
||||
push(@output, " <pre style='font-size: 12px; color: $colors->{fg_color}';>\n");
|
||||
push(@output, "Time Logged In Samba Netatalk\n");
|
||||
push(@output, "------------------------------------- \n");
|
||||
my $line;
|
||||
my @row;
|
||||
my $time;
|
||||
|
@ -225,16 +226,16 @@ sub user_cgi {
|
|||
my ($sys, $smb, $mac) = @$line;
|
||||
@row = ($sys, $smb, $mac);
|
||||
$time = $time - (1 / $tf->{ts});
|
||||
printf(" %2d$tf->{tc} %6d %6d %6d\n", $time, @row);
|
||||
push(@output, sprintf(" %2d$tf->{tc} %6d %6d %6d\n", $time, @row));
|
||||
}
|
||||
print(" </pre>\n");
|
||||
push(@output, " </pre>\n");
|
||||
if($title) {
|
||||
print(" </td>\n");
|
||||
print(" </tr>\n");
|
||||
main::graph_footer();
|
||||
push(@output, " </td>\n");
|
||||
push(@output, " </tr>\n");
|
||||
push(@output, main::graph_footer());
|
||||
}
|
||||
print(" <br>\n");
|
||||
return;
|
||||
push(@output, " <br>\n");
|
||||
return @output;
|
||||
}
|
||||
|
||||
|
||||
|
@ -265,12 +266,12 @@ sub user_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(" <tr>\n");
|
||||
print(" <td bgcolor='$colors->{title_bg_color}'>\n");
|
||||
push(@output, " <tr>\n");
|
||||
push(@output, " <td bgcolor='$colors->{title_bg_color}'>\n");
|
||||
}
|
||||
push(@tmp, "AREA:sys#44EE44:Logged In");
|
||||
push(@tmp, "GPRINT:sys:LAST: Current\\: %3.0lf");
|
||||
|
@ -311,7 +312,7 @@ sub user_cgi {
|
|||
"COMMENT: \\n",
|
||||
"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",
|
||||
|
@ -330,12 +331,12 @@ sub user_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 =~ /user1/)) {
|
||||
if(lc($config->{enable_zoom}) 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 {
|
||||
if($version eq "new") {
|
||||
$picz_width = $picz->{image_width} * $config->{global_zoom};
|
||||
|
@ -344,16 +345,16 @@ sub user_cgi {
|
|||
$picz_width = $width + 115;
|
||||
$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 {
|
||||
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1 . "'>\n");
|
||||
push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG1 . "'>\n");
|
||||
}
|
||||
}
|
||||
|
||||
if($title) {
|
||||
print(" </td>\n");
|
||||
print(" <td valign='top' bgcolor='" . $colors->{title_bg_color} . "'>\n");
|
||||
push(@output, " </td>\n");
|
||||
push(@output, " <td valign='top' bgcolor='" . $colors->{title_bg_color} . "'>\n");
|
||||
}
|
||||
@riglim = @{setup_riglim($rigid[1], $limit[1])};
|
||||
undef(@tmp);
|
||||
|
@ -395,7 +396,7 @@ sub user_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",
|
||||
|
@ -415,12 +416,12 @@ sub user_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 =~ /user2/)) {
|
||||
if(lc($config->{enable_zoom}) 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 {
|
||||
if($version eq "new") {
|
||||
$picz_width = $picz->{image_width} * $config->{global_zoom};
|
||||
|
@ -429,10 +430,10 @@ sub user_cgi {
|
|||
$picz_width = $width + 115;
|
||||
$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 {
|
||||
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2 . "'>\n");
|
||||
push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG2 . "'>\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -476,7 +477,7 @@ sub user_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",
|
||||
|
@ -496,12 +497,12 @@ sub user_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 =~ /user3/)) {
|
||||
if(lc($config->{enable_zoom}) 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 {
|
||||
if($version eq "new") {
|
||||
$picz_width = $picz->{image_width} * $config->{global_zoom};
|
||||
|
@ -510,20 +511,20 @@ sub user_cgi {
|
|||
$picz_width = $width + 115;
|
||||
$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 {
|
||||
print(" <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3 . "'>\n");
|
||||
push(@output, " <img src='" . $config->{url} . "/" . $config->{imgs_dir} . $IMG3 . "'>\n");
|
||||
}
|
||||
}
|
||||
|
||||
if($title) {
|
||||
print(" </td>\n");
|
||||
print(" </tr>\n");
|
||||
main::graph_footer();
|
||||
push(@output, " </td>\n");
|
||||
push(@output, " </tr>\n");
|
||||
push(@output, main::graph_footer());
|
||||
}
|
||||
print(" <br>\n");
|
||||
return;
|
||||
push(@output, " <br>\n");
|
||||
return @output;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
Loading…
Reference in New Issue