From 86bcee0fc30082a9484bb146737c8027b4c5d5e6 Mon Sep 17 00:00:00 2001 From: Jordi Sanfeliu Date: Wed, 20 Nov 2019 17:13:57 +0100 Subject: [PATCH] make function 'flush_accounting_rules' aware of this new option --- lib/Monitorix.pm | 30 ++++++++++++++++++++++++++---- lib/port.pm | 5 ----- monitorix | 3 +++ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/lib/Monitorix.pm b/lib/Monitorix.pm index 3722bfa..149805b 100644 --- a/lib/Monitorix.pm +++ b/lib/Monitorix.pm @@ -334,7 +334,13 @@ sub flush_accounting_rules { my @rules; while() { my ($rule, undef, undef, $name) = split(' ', $_); - if($name =~ /monitorix_IN/ || /monitorix_OUT/ || /monitorix_nginx_IN/) { + if(lc($config->{port}->{use_external_firewall} || "") eq "n") { + if($name =~ /monitorix_IN/ || /monitorix_OUT/) { + push(@rules, $rule); + push(@names, $name); + } + } + if($name =~ /monitorix_nginx_IN/) { push(@rules, $rule); push(@names, $name); } @@ -350,7 +356,12 @@ sub flush_accounting_rules { my @rules; while() { my ($rule, undef, undef, $name) = split(' ', $_); - if($name =~ /monitorix_IN/ || /monitorix_OUT/ || /monitorix_nginx_IN/) { + if(lc($config->{port}->{use_external_firewall} || "") eq "n") { + if($name =~ /monitorix_IN/ || /monitorix_OUT/) { + push(@rules, $rule); + } + } + if($name =~ /monitorix_nginx_IN/) { push(@rules, $rule); } } @@ -372,7 +383,13 @@ sub flush_accounting_rules { my @rules; while() { my ($rule, undef, undef, $name) = split(' ', $_); - if($name =~ /monitorix_IN/ || /monitorix_OUT/ || /monitorix_nginx_IN/) { + if(lc($config->{port}->{use_external_firewall} || "") eq "n") { + if($name =~ /monitorix_IN/ || /monitorix_OUT/) { + push(@rules, $rule); + push(@names, $name); + } + } + if($name =~ /monitorix_nginx_IN/) { push(@rules, $rule); push(@names, $name); } @@ -388,7 +405,12 @@ sub flush_accounting_rules { my @rules; while() { my ($rule, undef, undef, $name) = split(' ', $_); - if($name =~ /monitorix_IN/ || /monitorix_OUT/ || /monitorix_nginx_IN/) { + if(lc($config->{port}->{use_external_firewall} || "") eq "n") { + if($name =~ /monitorix_IN/ || /monitorix_OUT/) { + push(@rules, $rule); + } + } + if($name =~ /monitorix_nginx_IN/) { push(@rules, $rule); } } diff --git a/lib/port.pm b/lib/port.pm index f54db32..6f545b3 100644 --- a/lib/port.pm +++ b/lib/port.pm @@ -129,11 +129,6 @@ sub port_init { logger("$myself: WARNING: 'max' option indicates less ports than really defined in 'list'."); } - # initialize to 'n' (default) the option 'use_external_firewall' - if(!$port->{use_external_firewall}) { - $port->{use_external_firewall} = "n"; - } - if(lc($port->{use_external_firewall} || "") eq "n") { if($config->{os} eq "Linux") { my $num; diff --git a/monitorix b/monitorix index 5179163..35e6edd 100755 --- a/monitorix +++ b/monitorix @@ -671,6 +671,9 @@ 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"; } +if(!$config{port}->{use_external_firewall}) { # initialize to 'n' by default + $config{port}->{use_external_firewall} = "n"; +} # make sure that there aren't residual Monitorix iptables rules flush_accounting_rules(\%config, $options{d});