New option 'default_option_when_all' for Multihost mode

Now that in Multihost mode anyone can select the option "All" in the Hostname list and "All graphs" in the Graph list, this may, accidentally, hang the browser for a while due to the huge amount of images to download remotely from different servers.

In order to prevent precisely that, this new option defines which option in the Graph list will be selected ("System load" by default) automatically when the user selects 'All' in the Hostname list.

Of course, the user is still able to change it to "All graphs" at any moment, and at his own risk :-). #216
This commit is contained in:
Jordi Sanfeliu 2019-03-09 20:28:32 +01:00
parent b290ffd417
commit 8b289d879f
3 changed files with 51 additions and 2 deletions

View File

@ -2862,6 +2862,17 @@ If your horizontal screen resolution is pretty wide, you may want to increase th
Default value: \fI2\fP
.RE
.P
.BI default_option_when_all
.RS
If the user has defined a considerable amount of remote servers and it selects the option "\fIAll\fP" in the \fIHostname\fP list and "\fIAll graphs\fP" in the \fIGraph\fP list, the browser may hang for a while due to the huge amount of images to download remotely from different servers.
.P
This option prevents precisely that this happens accidentally by setting a default value in the \fIGraph\fP list. Of course, the user is able to change it to "\fIAll graphs\fP" at any moment.
.P
The value of this option may be any of the ones that appear in the \fI<graphs>\fP section (near the end) of the \fImonitorix.conf\fP file.
.P
Default value: "\fISystem load\fP"
.RE
.P
.BI remotehost_list
.RS
This is a comma-separated list with descriptive names of remote servers with Monitorix already installed and working that you plan to monitor from here.

View File

@ -122,6 +122,9 @@ sub create_index {
my $title_fore_color;
my $piwik_code = "";
my ($piwik_url, $piwik_sid, $piwik_img);
my $text_when_all;
my $value_when_all;
my $when_all_code = "";
# keep backwards compatibility for v3.2.1 and less
if(ref($config{theme}) ne "HASH") {
@ -148,6 +151,35 @@ sub create_index {
$title_fore_color = $config{theme}->{$theme}->{title_fg};
}
# Default option in 'Graph' list when 'All' is selected in 'Hostname' list.
#
# The following small JavaScript function is intended to avoid to select to view
# accidentally (unless explicitly selected by the user) a huge amount of remote
# images that will hang the browser for a while.
$text_when_all = $config{multihost}->{default_option_when_all};
my @match = grep { $config{graphs}{$_} eq $text_when_all } keys %{$config{graphs}};
$value_when_all = $match[0] || "";
if(!$value_when_all) {
logger("$myself: ERROR: invalid value in 'default_option_when_all' option ('$text_when_all').");
$value_when_all = "_system1";
}
$when_all_code = <<"EOF";
<!-- Default option code when 'All' is selected in 'Hostname' list -->
<script type="text/javascript">
function auto_select() {
var host = document.getElementById("hostname");
var h = host.options[host.selectedIndex].text;
var graph = document.getElementById("graph");
var g = graph.options[graph.selectedIndex].text;
if(h == "All" && g == "All graphs") {
document.getElementById("graph").value = "$value_when_all";
}
return true;
}
</script>
<!-- End Default option code when 'All' is selected in 'Hostname' list -->
EOF
# Piwik tracking code
if(lc($config{piwik_tracking}->{enabled} || "") eq "y") {
$piwik_url = $config{piwik_tracking}->{url} || "";
@ -192,6 +224,7 @@ EOF
</head>
<body bgcolor="$bgcolor" text="#888888" vlink="#888888" link="#888888">
$piwik_code
$when_all_code
<center>
<p>
<br>
@ -227,7 +260,7 @@ EOF
EOF
print(OUT " <td bgcolor='$bgcolor'>\n");
print(OUT " <select name='mode' size='1'>\n");
print(OUT " <select name='mode' size='1' id='hostname' onchange='auto_select()'>\n");
print(OUT " <optgroup label='Local Host'>\n");
print(OUT " <option value='localhost'>localhost</option>\n");
print(OUT " </optgroup>\n");
@ -265,7 +298,7 @@ EOF
print(OUT " <td bgcolor='$bgcolor'>\n");
print(OUT " <select name='graph' size='1'>\n");
print(OUT " <select name='graph' size='1' id='graph'>\n");
print(OUT " <option value='all'>All graphs</option>\n");
foreach (split(',', $config{graph_name})) {
my $g = trim($_);
@ -626,6 +659,10 @@ if(!$config{httpd_builtin}->{autocheck_responsiveness}) {
logger("WARNING: the 'autocheck_responsiveness' option is not valid or doesn't exist. Please consider upgrading your configuration file.");
$config{httpd_builtin}->{autocheck_responsiveness} = "y";
}
if(!$config{multihost}->{default_option_when_all}) {
logger("WARNING: the 'default_option_when_all' option is not valid or doesn't exist. Please consider upgrading your configuration file.");
$config{multihost}->{default_option_when_all} = "System load";
}
# make sure that there aren't residual Monitorix iptables rules
flush_accounting_rules(\%config, $options{d});

View File

@ -796,6 +796,7 @@ secure_log_date_format = %b %e
enabled = n
footer_url = y
graphs_per_row = 2
default_option_when_all = "System load"
remotehost_list = server 1, server 2, server 3
<remotehost_desc>
0 = http://www.example.com,/monitorix,/monitorix-cgi