centreon / centreon-plugins

Collection of standard plugins to discover and gather cloud-to-edge metrics and status across your whole IT infrastructure.
https://www.centreon.com
Apache License 2.0
310 stars 275 forks source link

Illegal division by zero in checkpoint memory plugin #1589

Closed thezipman closed 5 years ago

thezipman commented 5 years ago

Hello, when checking memory on checkpoint devices, if the firewall don't have a swap the plugin fails with a division by zero errror.

Following you find a working patch. As usual feel free to keep, modify or discard at your opinion :)

Thanks for your work

diff --git a/network/checkpoint/snmp/mode/memory.pm b/network/checkpoint/snmp/mode/memory.pm
index 52f8134..4374e02 100644
--- a/network/checkpoint/snmp/mode/memory.pm
+++ b/network/checkpoint/snmp/mode/memory.pm
@@ -139,20 +139,11 @@ sub manage_selection {
         total => $results->{$oid_memTotalReal64},
     };

-    if ($results->{$oid_memTotalVirtual64} != $results->{$oid_memTotalReal64}) {
-        $self->{swap} = {
-            prct_used => ($results->{$oid_memActiveVirtual64} - $results->{$oid_memActiveReal64}) * 100 / ($results->{$oid_memTotalVirtual64} - $results->{$oid_memTotalReal64}),
-            used => $results->{$oid_memActiveVirtual64} - $results->{$oid_memActiveReal64},
-            free => $results->{$oid_memTotalVirtual64} - $results->{$oid_memTotalReal64} - ($results->{$oid_memActiveVirtual64} - $results->{$oid_memActiveReal64}),
-            total => $results->{$oid_memTotalVirtual64} - $results->{$oid_memTotalReal64}
-        };
-    } else {
-        $self->{swap} = {
-            prct_used => 0,
-            used => 0,
-            free => 0,
-            total => 0
-        };
+    $self->{swap} = {
+        prct_used => ($results->{$oid_memActiveVirtual64} - $results->{$oid_memActiveReal64}) * 100 / ($results->{$oid_memTotalVirtual64} - $results->{$oid_memTotalReal64}),
+        used => $results->{$oid_memActiveVirtual64} - $results->{$oid_memActiveReal64},
+        free => $results->{$oid_memTotalVirtual64} - $results->{$oid_memTotalReal64} - ($results->{$oid_memActiveVirtual64} - $results->{$oid_memActiveReal64}),
+        total => $results->{$oid_memTotalVirtual64} - $results->{$oid_memTotalReal64}
     };

     $self->{malloc} = { failed_mallocs => $results->{$oid_fwKmemFailedAlloc} };
garnier-quentin commented 5 years ago

Could you test it ?

lkco commented 5 years ago

Hi Quentin, I meet same issue. I test the patch and it's work ! Could you provide a new rpm for centreon-plugin-Network-Firewalls-Checkpoint-Snmp in repo 19.04 ? Thx

garnier-quentin commented 5 years ago

You have the last rpm in the unstable repository

cmeschin commented 5 years ago

Hi Quentin, Did you know when it's released in stable version in Centreon-EPP? Thanks,

garnier-quentin commented 5 years ago

Maybe September.