From 8b289d879f459479d65423df286d3de2e15317d8 Mon Sep 17 00:00:00 2001 From: Jordi Sanfeliu Date: Sat, 9 Mar 2019 20:28:32 +0100 Subject: [PATCH] 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 --- man/man5/monitorix.conf.5 | 11 +++++++++++ monitorix | 41 +++++++++++++++++++++++++++++++++++++-- monitorix.conf | 1 + 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/man/man5/monitorix.conf.5 b/man/man5/monitorix.conf.5 index f9388bc..48d49a6 100644 --- a/man/man5/monitorix.conf.5 +++ b/man/man5/monitorix.conf.5 @@ -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\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. diff --git a/monitorix b/monitorix index 78cbbb8..d6d81d4 100755 --- a/monitorix +++ b/monitorix @@ -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"; + + + +EOF + # Piwik tracking code if(lc($config{piwik_tracking}->{enabled} || "") eq "y") { $piwik_url = $config{piwik_tracking}->{url} || ""; @@ -192,6 +224,7 @@ EOF $piwik_code + $when_all_code


@@ -227,7 +260,7 @@ EOF EOF print(OUT " \n"); - print(OUT " \n"); print(OUT " \n"); print(OUT " \n"); print(OUT " \n"); @@ -265,7 +298,7 @@ EOF print(OUT " \n"); - print(OUT " \n"); print(OUT " \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}); diff --git a/monitorix.conf b/monitorix.conf index 8c894e1..05b60dc 100644 --- a/monitorix.conf +++ b/monitorix.conf @@ -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 0 = http://www.example.com,/monitorix,/monitorix-cgi