From bb1f67c960e1fc4472fe13b398527f60d5efd64e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Su=C3=A1rez?= Date: Fri, 26 May 2023 15:18:21 -0600 Subject: [PATCH 1/5] Add "defined" validations to get_module_status if --- pandora_server/lib/PandoraFMS/Core.pm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index ea9fb091b1..630b8ea0ce 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -5199,7 +5199,7 @@ sub get_module_status ($$$$) { $warning_str = (defined ($warning_str) && valid_regex ($warning_str) == 1) ? safe_output($warning_str) : ''; # Adjust percentage max/min values. - if ($module->{'percentage_critical'} == 1) { + if (defined($module->{'percentage_critical'}) && $module->{'percentage_critical'} == 1) { if ($critical_max != 0 && $critical_min != 0) { $critical_max = $last_data_value * (1 + $critical_max / 100.0); $critical_min = $last_data_value * (1 - $critical_min / 100.0); @@ -5216,7 +5216,7 @@ sub get_module_status ($$$$) { $module->{'critical_inverse'} = 0; } } - if ($module->{'percentage_warning'} == 1) { + if (defined($module->{'percentage_warning'}) && $module->{'percentage_warning'} == 1) { if ($warning_max != 0 && $warning_min != 0) { $warning_max = $last_data_value * (1 + $warning_max / 100.0); $warning_min = $last_data_value * (1 - $warning_min / 100.0); @@ -5255,7 +5255,7 @@ sub get_module_status ($$$$) { # Critical if ($critical_min ne $critical_max) { # [critical_min, critical_max) - if ($module->{'critical_inverse'} == 0) { + if (defined($module->{'critical_inverse'}) && $module->{'critical_inverse'} == 0) { return 1 if ($data >= $critical_min && $data < $critical_max); return 1 if ($data >= $critical_min && $critical_max < $critical_min); } @@ -5272,7 +5272,7 @@ sub get_module_status ($$$$) { # Warning if ($warning_min ne $warning_max) { # [warning_min, warning_max) - if ($module->{'warning_inverse'} == 0) { + if (defined($module->{'warning_inverse'}) && $module->{'warning_inverse'} == 0) { return 2 if ($data >= $warning_min && $data < $warning_max); return 2 if ($data >= $warning_min && $warning_max < $warning_min); } @@ -5291,7 +5291,7 @@ sub get_module_status ($$$$) { # Critical $eval_result = eval { - if ($module->{'critical_inverse'} == 0) { + if (defined($module->{'critical_inverse'}) && $module->{'critical_inverse'} == 0) { $critical_str ne '' && $data =~ /$critical_str/ ; } else { $critical_str ne '' && $data !~ /$critical_str/ ; @@ -5301,7 +5301,7 @@ sub get_module_status ($$$$) { # Warning $eval_result = eval { - if ($module->{'warning_inverse'} == 0) { + if (defined($module->{'warning_inverse'}) && $module->{'warning_inverse'} == 0) { $warning_str ne '' && $data =~ /$warning_str/ ; } else { $warning_str ne '' && $data !~ /$warning_str/ ; From 883351b68df13d9ecb11e308d1ab365ad7da09ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Su=C3=A1rez?= Date: Mon, 29 May 2023 10:02:19 -0600 Subject: [PATCH 2/5] Avoid unexpected else when variables are undefined --- pandora_server/lib/PandoraFMS/Core.pm | 50 ++++++++++++++++----------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 630b8ea0ce..df163ec28f 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -5253,9 +5253,10 @@ sub get_module_status ($$$$) { if ($module_type !~ m/_string/) { # Critical - if ($critical_min ne $critical_max) { + if ($critical_min ne $critical_max && defined($module->{'critical_inverse'})) { + # [critical_min, critical_max) - if (defined($module->{'critical_inverse'}) && $module->{'critical_inverse'} == 0) { + if ($module->{'critical_inverse'} == 0) { return 1 if ($data >= $critical_min && $data < $critical_max); return 1 if ($data >= $critical_min && $critical_max < $critical_min); } @@ -5270,9 +5271,10 @@ sub get_module_status ($$$$) { } # Warning - if ($warning_min ne $warning_max) { + if ($warning_min ne $warning_max && defined($module->{'warning_inverse'})) { + # [warning_min, warning_max) - if (defined($module->{'warning_inverse'}) && $module->{'warning_inverse'} == 0) { + if ($module->{'warning_inverse'} == 0) { return 2 if ($data >= $warning_min && $data < $warning_max); return 2 if ($data >= $warning_min && $warning_max < $warning_min); } @@ -5290,24 +5292,32 @@ sub get_module_status ($$$$) { else { # Critical - $eval_result = eval { - if (defined($module->{'critical_inverse'}) && $module->{'critical_inverse'} == 0) { - $critical_str ne '' && $data =~ /$critical_str/ ; - } else { - $critical_str ne '' && $data !~ /$critical_str/ ; - } - }; - return 1 if ($eval_result); + if(defined($module->{'critical_inverse'})){ + + $eval_result = eval { + if ($module->{'critical_inverse'} == 0) { + $critical_str ne '' && $data =~ /$critical_str/ ; + } else { + $critical_str ne '' && $data !~ /$critical_str/ ; + } + }; + + return 1 if ($eval_result); + } # Warning - $eval_result = eval { - if (defined($module->{'warning_inverse'}) && $module->{'warning_inverse'} == 0) { - $warning_str ne '' && $data =~ /$warning_str/ ; - } else { - $warning_str ne '' && $data !~ /$warning_str/ ; - } - }; - return 2 if ($eval_result); + if(defined($module->{'critical_inverse'})){ + + $eval_result = eval { + if ($module->{'warning_inverse'} == 0) { + $warning_str ne '' && $data =~ /$warning_str/ ; + } else { + $warning_str ne '' && $data !~ /$warning_str/ ; + } + }; + + return 2 if ($eval_result); + } } # Normal From 467796208bd99ce4a6bf7e956844f68fae144ebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Su=C3=A1rez?= Date: Mon, 29 May 2023 10:17:50 -0600 Subject: [PATCH 3/5] Small adjustment in warning_inverse --- pandora_server/lib/PandoraFMS/Core.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index df163ec28f..30a6f6c780 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -5272,7 +5272,7 @@ sub get_module_status ($$$$) { # Warning if ($warning_min ne $warning_max && defined($module->{'warning_inverse'})) { - + # [warning_min, warning_max) if ($module->{'warning_inverse'} == 0) { return 2 if ($data >= $warning_min && $data < $warning_max); @@ -5306,7 +5306,7 @@ sub get_module_status ($$$$) { } # Warning - if(defined($module->{'critical_inverse'})){ + if(defined($module->{'warning_inverse'})){ $eval_result = eval { if ($module->{'warning_inverse'} == 0) { From bf513a5c7a05c7d9d564d5da02d15fd6f09ed20e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Su=C3=A1rez?= Date: Tue, 30 May 2023 08:28:47 -0600 Subject: [PATCH 4/5] Evaluate as 0 undefined values --- pandora_server/lib/PandoraFMS/Core.pm | 69 ++++++++++++--------------- 1 file changed, 31 insertions(+), 38 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 30a6f6c780..8e407e9703 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -5253,71 +5253,64 @@ sub get_module_status ($$$$) { if ($module_type !~ m/_string/) { # Critical - if ($critical_min ne $critical_max && defined($module->{'critical_inverse'})) { + if ($critical_min ne $critical_max) { - # [critical_min, critical_max) - if ($module->{'critical_inverse'} == 0) { - return 1 if ($data >= $critical_min && $data < $critical_max); - return 1 if ($data >= $critical_min && $critical_max < $critical_min); - } # (-inf, critical_min), [critical_max, +inf) - else { + if (defined($module->{'critical_inverse'}) && $module->{'critical_inverse'} == 1) { if ($critical_max < $critical_min) { return 1 if ($data < $critical_min); } else { return 1 if ($data < $critical_min || $data >= $critical_max); } } + # [critical_min, critical_max) + else { + return 1 if ($data >= $critical_min && $data < $critical_max); + return 1 if ($data >= $critical_min && $critical_max < $critical_min); + } } # Warning - if ($warning_min ne $warning_max && defined($module->{'warning_inverse'})) { - - # [warning_min, warning_max) - if ($module->{'warning_inverse'} == 0) { - return 2 if ($data >= $warning_min && $data < $warning_max); - return 2 if ($data >= $warning_min && $warning_max < $warning_min); - } + if ($warning_min ne $warning_max) { # (-inf, warning_min), [warning_max, +inf) - else { + if (defined($module->{'warning_inverse'}) && $module->{'warning_inverse'} == 1) { if ($warning_max < $warning_min) { return 2 if ($data < $warning_min); } else { return 2 if ($data < $warning_min || $data >= $warning_max); } } + # [warning_min, warning_max) + else { + return 2 if ($data >= $warning_min && $data < $warning_max); + return 2 if ($data >= $warning_min && $warning_max < $warning_min); + } } } # String else { # Critical - if(defined($module->{'critical_inverse'})){ - - $eval_result = eval { - if ($module->{'critical_inverse'} == 0) { - $critical_str ne '' && $data =~ /$critical_str/ ; - } else { - $critical_str ne '' && $data !~ /$critical_str/ ; - } - }; + $eval_result = eval { + if (defined($module->{'critical_inverse'} && $module->{'critical_inverse'} == 1) { + $critical_str ne '' && $data !~ /$critical_str/ ; + } else { + $critical_str ne '' && $data =~ /$critical_str/ ; + } + }; - return 1 if ($eval_result); - } - + return 1 if ($eval_result); + # Warning - if(defined($module->{'warning_inverse'})){ - - $eval_result = eval { - if ($module->{'warning_inverse'} == 0) { - $warning_str ne '' && $data =~ /$warning_str/ ; - } else { - $warning_str ne '' && $data !~ /$warning_str/ ; - } - }; + $eval_result = eval { + if (defined($module->{'warning_inverse'} && $module->{'warning_inverse'} == 1) { + $warning_str ne '' && $data !~ /$warning_str/ ; + } else { + $warning_str ne '' && $data =~ /$warning_str/ ; + } + }; - return 2 if ($eval_result); - } + return 2 if ($eval_result); } # Normal From accb760cb76ab3ac00a19eb3bb5d9799f889d03f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Su=C3=A1rez?= Date: Tue, 30 May 2023 08:44:52 -0600 Subject: [PATCH 5/5] Small adjustments --- pandora_server/lib/PandoraFMS/Core.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 8e407e9703..384b2aa0d5 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -5292,7 +5292,7 @@ sub get_module_status ($$$$) { # Critical $eval_result = eval { - if (defined($module->{'critical_inverse'} && $module->{'critical_inverse'} == 1) { + if (defined($module->{'critical_inverse'}) && $module->{'critical_inverse'} == 1) { $critical_str ne '' && $data !~ /$critical_str/ ; } else { $critical_str ne '' && $data =~ /$critical_str/ ; @@ -5303,7 +5303,7 @@ sub get_module_status ($$$$) { # Warning $eval_result = eval { - if (defined($module->{'warning_inverse'} && $module->{'warning_inverse'} == 1) { + if (defined($module->{'warning_inverse'}) && $module->{'warning_inverse'} == 1) { $warning_str ne '' && $data !~ /$warning_str/ ; } else { $warning_str ne '' && $data =~ /$warning_str/ ;