From b379228183c100575753bf1ab0d71e818238be89 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 6 Aug 2020 14:13:27 +0200 Subject: [PATCH] add memory option for rhel --- snmp_standard/mode/memory.pm | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/snmp_standard/mode/memory.pm b/snmp_standard/mode/memory.pm index 73673785b..8e309e39d 100644 --- a/snmp_standard/mode/memory.pm +++ b/snmp_standard/mode/memory.pm @@ -147,11 +147,12 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'units:s' => { name => 'units', default => '%' }, - 'free' => { name => 'free' }, - 'swap' => { name => 'check_swap' }, - 'redhat' => { name => 'redhat' }, # for legacy (do nothing) - 'autodetect-redhat' => { name => 'autodetect_redhat' } # for legacy (do nothing) + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, + 'swap' => { name => 'check_swap' }, + 'patch-redhat' => { name => 'patch_redhat' }, + 'redhat' => { name => 'redhat' }, # for legacy (do nothing) + 'autodetect-redhat' => { name => 'autodetect_redhat' } # for legacy (do nothing) }); return $self; @@ -196,9 +197,12 @@ sub memory_calc { my $cached = ($options{result}->{memCached}) ? $options{result}->{memCached} * 1024 : 0; my ($used, $free, $prct_used, $prct_free) = (0, 0, 0, 0); + # rhel patch introduced: net-snmp-5.7.2-43.el7 (https://bugzilla.redhat.com/show_bug.cgi?id=1250060) + # rhel patch reverted: net-snmp-5.7.2-47.el7 (https://bugzilla.redhat.com/show_bug.cgi?id=1779609) + if ($total != 0) { - $used = $total - $available - $buffer - $cached; - $free = $total - $used; + $used = (defined($self->{option_results}->{patch_redhat})) ? $total - $available : $total - $available - $buffer - $cached; + $free = (defined($self->{option_results}->{patch_redhat})) ? $available : $total - $used; $prct_used = $used * 100 / $total; $prct_free = 100 - $prct_used; } @@ -281,6 +285,14 @@ Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%), 'swap' (B), 'swap-free' (B), 'swap-prct' (%), 'buffer' (B), 'cached' (B), 'shared' (B). +=item B<--patch-redhat> + +If using RedHat distribution with net-snmp >= 5.7.2-43 and net-snmp < 5.7.2-47. But you should update net-snmp!!!! + +This version: used = memTotalReal - memAvailReal // free = memAvailReal + +Others versions: used = memTotalReal - memAvailReal - memBuffer - memCached // free = total - used + =back =cut