From 894d61df1c3dffd3a8c85b38752b6874366a4c46 Mon Sep 17 00:00:00 2001
From: qgarnier <qgarnier@centreon.com>
Date: Wed, 22 Nov 2017 16:18:44 +0100
Subject: [PATCH] add plugin netgear mseries snmp

---
 .../mseries/snmp/mode/components/fan.pm       |  86 +++++++++++
 .../mseries/snmp/mode/components/psu.pm       |  71 +++++++++
 .../snmp/mode/components/temperature.pm       |  86 +++++++++++
 .../network/netgear/mseries/snmp/mode/cpu.pm  | 123 ++++++++++++++++
 .../netgear/mseries/snmp/mode/hardware.pm     | 129 ++++++++++++++++
 .../netgear/mseries/snmp/mode/memory.pm       | 138 ++++++++++++++++++
 .../network/netgear/mseries/snmp/plugin.pm    |  52 +++++++
 7 files changed, 685 insertions(+)
 create mode 100644 centreon-plugins/network/netgear/mseries/snmp/mode/components/fan.pm
 create mode 100644 centreon-plugins/network/netgear/mseries/snmp/mode/components/psu.pm
 create mode 100644 centreon-plugins/network/netgear/mseries/snmp/mode/components/temperature.pm
 create mode 100644 centreon-plugins/network/netgear/mseries/snmp/mode/cpu.pm
 create mode 100644 centreon-plugins/network/netgear/mseries/snmp/mode/hardware.pm
 create mode 100644 centreon-plugins/network/netgear/mseries/snmp/mode/memory.pm
 create mode 100644 centreon-plugins/network/netgear/mseries/snmp/plugin.pm

diff --git a/centreon-plugins/network/netgear/mseries/snmp/mode/components/fan.pm b/centreon-plugins/network/netgear/mseries/snmp/mode/components/fan.pm
new file mode 100644
index 000000000..04ab649b7
--- /dev/null
+++ b/centreon-plugins/network/netgear/mseries/snmp/mode/components/fan.pm
@@ -0,0 +1,86 @@
+#
+# Copyright 2017 Centreon (http://www.centreon.com/)
+#
+# Centreon is a full-fledged industry-strength solution that meets
+# the needs in IT infrastructure and application monitoring for
+# service performance.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+package network::netgear::mseries::snmp::mode::components::fan;
+
+use strict;
+use warnings;
+
+my %map_fan_status = (
+    1 => 'notpresent', 2 => 'operational', 3 => 'failed', 4 => 'powering', 
+    5 => 'nopower', 6 => 'notpowering', 7 => 'incompatible'
+);
+
+my $mapping = {
+    boxServicesFanItemState => { oid => '.1.3.6.1.4.1.4526.10.43.1.6.1.3', map => \%map_fan_status },
+    boxServicesFanSpeed     => { oid => '.1.3.6.1.4.1.4526.10.43.1.6.1.4' },
+};
+my $oid_boxServicesFansEntry = '.1.3.6.1.4.1.4526.10.43.1.6.1';
+
+sub load {
+    my ($self) = @_;
+    
+    push @{$self->{request}}, { oid => $oid_boxServicesFansEntry, begin => $mapping->{boxServicesFanItemState}->{oid}, end => $mapping->{boxServicesFanSpeed}->{oid} };
+}
+
+sub check {
+    my ($self) = @_;
+
+    $self->{output}->output_add(long_msg => "Checking fans");
+    $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
+    return if ($self->check_filter(section => 'fan'));
+
+    my ($exit, $warn, $crit, $checked);
+    foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_boxServicesFansEntry}})) {
+        next if ($oid !~ /^$mapping->{boxServicesFanItemState}->{oid}\.(.*)$/);
+        my $instance = $1;
+        my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_boxServicesFansEntry}, instance => $instance);
+        
+        next if ($self->check_filter(section => 'fan', instance => $instance));
+        if ($result->{boxServicesFanItemState} =~ /notpresent/i) {
+            $self->absent_problem(section => 'fan', instance => $instance);
+            next;
+        }
+
+        $self->{components}->{fan}->{total}++;
+        $self->{output}->output_add(long_msg => sprintf("fan '%s' status is '%s' [instance = %s, speed = %s]",
+                                                        $instance, $result->{boxServicesFanItemState}, $instance, defined($result->{boxServicesFanSpeed}) ? $result->{boxServicesFanSpeed} : 'unknown'));
+        $exit = $self->get_severity(label => 'default', section => 'fan', value => $result->{boxServicesFanItemState});
+        if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
+            $self->{output}->output_add(severity => $exit,
+                                        short_msg => sprintf("Fan '%s' status is '%s'", $instance, $result->{boxServicesFanItemState}));
+        }
+        
+        next if (!defined($result->{boxServicesFanSpeed}) || $result->{boxServicesFanSpeed} !~ /[0-9]+/);
+        
+        ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{boxServicesFanSpeed});
+        if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
+            $self->{output}->output_add(severity => $exit,
+                                        short_msg => sprintf("Fan '%s' is '%s' rpm", $instance, $result->{boxServicesFanSpeed}));
+        }
+        $self->{output}->perfdata_add(label => 'fan_' . $instance, unit => 'rpm', 
+                                      value => $result->{boxServicesFanSpeed},
+                                      warning => $warn,
+                                      critical => $crit, min => 0
+                                      );
+    }
+}
+
+1;
diff --git a/centreon-plugins/network/netgear/mseries/snmp/mode/components/psu.pm b/centreon-plugins/network/netgear/mseries/snmp/mode/components/psu.pm
new file mode 100644
index 000000000..e7e0ef28a
--- /dev/null
+++ b/centreon-plugins/network/netgear/mseries/snmp/mode/components/psu.pm
@@ -0,0 +1,71 @@
+#
+# Copyright 2017 Centreon (http://www.centreon.com/)
+#
+# Centreon is a full-fledged industry-strength solution that meets
+# the needs in IT infrastructure and application monitoring for
+# service performance.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+package network::netgear::mseries::snmp::mode::components::psu;
+
+use strict;
+use warnings;
+
+my %map_psu_status = (
+    1 => 'notpresent', 2 => 'operational', 3 => 'failed', 4 => 'powering', 
+    5 => 'nopower', 6 => 'notpowering', 7 => 'incompatible'
+);
+
+my $mapping = {
+    boxServicesPowSupplyItemState   => { oid => '.1.3.6.1.4.1.4526.10.43.1.7.1.3', map => \%map_psu_status },
+};
+
+sub load {
+    my ($self) = @_;
+    
+    push @{$self->{request}}, { oid => $mapping->{boxServicesPowSupplyItemState}->{oid} };
+}
+
+sub check {
+    my ($self) = @_;
+
+    $self->{output}->output_add(long_msg => "Checking power supplies");
+    $self->{components}->{psu} = {name => 'psu', total => 0, skip => 0};
+    return if ($self->check_filter(section => 'psu'));
+
+    my ($exit, $warn, $crit, $checked);
+    foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{boxServicesPowSupplyItemState}->{oid}}})) {
+        next if ($oid !~ /^$mapping->{boxServicesPowSupplyItemState}->{oid}\.(.*)$/);
+        my $instance = $1;
+        my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{boxServicesPowSupplyItemState}->{oid}}, instance => $instance);
+        
+        next if ($self->check_filter(section => 'psu', instance => $instance));
+        if ($result->{boxServicesPowSupplyItemState} =~ /notpresent/i) {
+            $self->absent_problem(section => 'psu', instance => $instance);
+            next;
+        }
+
+        $self->{components}->{psu}->{total}++;
+        $self->{output}->output_add(long_msg => sprintf("power supply '%s' status is '%s' [instance = %s]",
+                                                        $instance, $result->{boxServicesPowSupplyItemState}, $instance));
+        $exit = $self->get_severity(label => 'default', section => 'psu', value => $result->{boxServicesPowSupplyItemState});
+        if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
+            $self->{output}->output_add(severity => $exit,
+                                        short_msg => sprintf("Power supply '%s' status is '%s'", $instance, $result->{boxServicesPowSupplyItemState}));
+        }
+    }
+}
+
+1;
diff --git a/centreon-plugins/network/netgear/mseries/snmp/mode/components/temperature.pm b/centreon-plugins/network/netgear/mseries/snmp/mode/components/temperature.pm
new file mode 100644
index 000000000..36a1a6603
--- /dev/null
+++ b/centreon-plugins/network/netgear/mseries/snmp/mode/components/temperature.pm
@@ -0,0 +1,86 @@
+#
+# Copyright 2017 Centreon (http://www.centreon.com/)
+#
+# Centreon is a full-fledged industry-strength solution that meets
+# the needs in IT infrastructure and application monitoring for
+# service performance.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+package network::netgear::mseries::snmp::mode::components::temperature;
+
+use strict;
+use warnings;
+
+my %map_temp_status = (
+    0 => 'low', 1 => 'normal', 2 => 'warning', 3 => 'critical',
+    4 => 'shutdown', 5 => 'notpresent', 6 => 'notoperational',
+);
+
+my $mapping = {
+    boxServicesTempSensorState          => { oid => '.1.3.6.1.4.1.4526.10.43.1.8.1.4', map => \%map_temp_status },
+    boxServicesTempSensorTemperature    => { oid => '.1.3.6.1.4.1.4526.10.43.1.8.1.5' },
+};
+my $oid_boxServicesTempSensorsEntry = '.1.3.6.1.4.1.4526.10.43.1.8.1';
+
+sub load {
+    my ($self) = @_;
+    
+    push @{$self->{request}}, { oid => $oid_boxServicesTempSensorsEntry, begin => $mapping->{boxServicesTempSensorState}->{oid}, end => $mapping->{boxServicesTempSensorTemperature}->{oid} };
+}
+
+sub check {
+    my ($self) = @_;
+
+    $self->{output}->output_add(long_msg => "Checking temperatures");
+    $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
+    return if ($self->check_filter(section => 'temperature'));
+
+    my ($exit, $warn, $crit, $checked);
+    foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_boxServicesTempSensorsEntry}})) {
+        next if ($oid !~ /^$mapping->{boxServicesTempSensorState}->{oid}\.(.*)$/);
+        my $instance = $1;
+        my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_boxServicesTempSensorsEntry}, instance => $instance);
+        
+        next if ($self->check_filter(section => 'temperature', instance => $instance));
+        if ($result->{boxServicesTempSensorState} =~ /notpresent/i) {
+            $self->absent_problem(section => 'temperature', instance => $instance);
+            next;
+        }
+
+        $self->{components}->{temperature}->{total}++;
+        $self->{output}->output_add(long_msg => sprintf("temperature '%s' status is '%s' [instance = %s, temperature = %s]",
+                                                        $instance, $result->{boxServicesTempSensorState}, $instance, defined($result->{boxServicesTempSensorTemperature}) ? $result->{boxServicesTempSensorTemperature} : 'unknown'));
+        $exit = $self->get_severity(section => 'temperature', value => $result->{boxServicesTempSensorState});
+        if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
+            $self->{output}->output_add(severity => $exit,
+                                        short_msg => sprintf("Temperature '%s' status is '%s'", $instance, $result->{boxServicesTempSensorState}));
+        }
+        
+        next if (!defined($result->{boxServicesTempSensorTemperature}) || $result->{boxServicesTempSensorTemperature} !~ /[0-9]+/);
+        
+        ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{boxServicesTempSensorTemperature});
+        if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
+            $self->{output}->output_add(severity => $exit,
+                                        short_msg => sprintf("Temperature '%s' is '%s' rpm", $instance, $result->{boxServicesTempSensorTemperature}));
+        }
+        $self->{output}->perfdata_add(label => 'temp_' . $instance, unit => 'C', 
+                                      value => $result->{boxServicesTempSensorTemperature},
+                                      warning => $warn,
+                                      critical => $crit,
+                                      );
+    }
+}
+
+1;
diff --git a/centreon-plugins/network/netgear/mseries/snmp/mode/cpu.pm b/centreon-plugins/network/netgear/mseries/snmp/mode/cpu.pm
new file mode 100644
index 000000000..4ad787a62
--- /dev/null
+++ b/centreon-plugins/network/netgear/mseries/snmp/mode/cpu.pm
@@ -0,0 +1,123 @@
+#
+# Copyright 2017 Centreon (http://www.centreon.com/)
+#
+# Centreon is a full-fledged industry-strength solution that meets
+# the needs in IT infrastructure and application monitoring for
+# service performance.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+package network::netgear::mseries::snmp::mode::cpu;
+
+use base qw(centreon::plugins::templates::counter);
+
+use strict;
+use warnings;
+
+sub set_counters {
+    my ($self, %options) = @_;
+    
+    $self->{maps_counters_type} = [
+        { name => 'global', type => 0, cb_prefix_output => 'prefix_cpu_output' }
+    ];
+    
+    $self->{maps_counters}->{global} = [
+        { label => '5s', set => {
+                key_values => [ { name => 'usage_5s' } ],
+                output_template => '%.2f %% (5sec)', output_error_template => "%s (5sec)",
+                perfdatas => [
+                    { label => 'cpu_5s', value => 'usage_5s_absolute', template => '%.2f',
+                      unit => '%', min => 0, max => 100 },
+                ],
+            }
+        },
+        { label => '1m', set => {
+                key_values => [ { name => 'usage_1m' } ],
+                output_template => '%.2f %% (1m)', output_error_template => "%s (1min)",
+                perfdatas => [
+                    { label => 'cpu_1m', value => 'usage_1m_absolute', template => '%.2f',
+                      unit => '%', min => 0, max => 100 },
+                ],
+            }
+        },
+        { label => '5m', set => {
+                key_values => [ { name => 'usage_5m' } ],
+                output_template => '%.2f %% (5min)', output_error_template => "%s (5min)",
+                perfdatas => [
+                    { label => 'cpu_5m', value => 'usage_5m_absolute', template => '%.2f',
+                      unit => '%', min => 0, max => 100 },
+                ],
+            }
+        },
+    ];
+}
+
+sub prefix_cpu_output {
+    my ($self, %options) = @_;
+    
+    return "CPU ";
+}
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                { 
+                                });
+    
+    return $self;
+}
+
+sub manage_selection {
+    my ($self, %options) = @_;
+
+    # STRING: "    5 Secs ( 43.2625%)   60 Secs ( 13.9157%)  300 Secs (  8.9274%)"
+    my $oid_agentSwitchCpuProcessTotalUtilization = '.1.3.6.1.4.1.4526.10.1.1.4.9.0';
+    my $snmp_result = $options{snmp}->get_leef(oids => [$oid_agentSwitchCpuProcessTotalUtilization], nothing_quit => 1);
+
+    $snmp_result->{$oid_agentSwitchCpuProcessTotalUtilization} =~ /\s*5\s*Secs\s*\(\s*(.*?)%\s*\)\s*60\s*Secs\s*\(\s*(.*?)%\s*\)\s*300\s*Secs\s*\(\s*(.*?)%\s*\)/i;
+    $self->{global} = { usage_5s => $1, usage_1m => $2, usage_5m => $3 };
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check CPU usage.
+
+=over 8
+
+=item B<--filter-counters>
+
+Only display some counters (regexp can be used).
+Example: --filter-counters='5m'
+
+=item B<--warning-*>
+
+Threshold warning.
+Can be: '5s', '1m', '5m'.
+
+=item B<--critical-*>
+
+Threshold critical.
+Can be: '5s', '1m', '5m'.
+
+=back
+
+=cut
diff --git a/centreon-plugins/network/netgear/mseries/snmp/mode/hardware.pm b/centreon-plugins/network/netgear/mseries/snmp/mode/hardware.pm
new file mode 100644
index 000000000..3f48cfb07
--- /dev/null
+++ b/centreon-plugins/network/netgear/mseries/snmp/mode/hardware.pm
@@ -0,0 +1,129 @@
+#
+# Copyright 2017 Centreon (http://www.centreon.com/)
+#
+# Centreon is a full-fledged industry-strength solution that meets
+# the needs in IT infrastructure and application monitoring for
+# service performance.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+package network::netgear::mseries::snmp::mode::hardware;
+
+use base qw(centreon::plugins::templates::hardware);
+
+use strict;
+use warnings;
+
+sub set_system {
+    my ($self, %options) = @_;
+    
+    $self->{regexp_threshold_overload_check_section_option} = '^(temperature|fan|psu)$';
+    $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|fan)$';
+    
+    $self->{cb_hook2} = 'snmp_execute';
+    
+    $self->{thresholds} = {        
+        default => [
+            ['notPresent', 'OK'],
+            ['operational', 'OK'],
+            ['failed', 'CRITICAL'],
+            ['notpowering', 'WARNING'],
+            ['powering', 'OK'],
+            ['nopower', 'OK'],
+            ['incompatible', 'WARNING'],
+        ],
+        temperature => [        
+            ['low', 'OK'],
+            ['normal', 'OK'],
+            ['warning', 'WARNING'],
+            ['critical', 'CRITICAL'],
+            ['notpresent', 'OK'],
+            ['shutdown', 'OK'],
+            ['notoperational', 'WARNING'],
+        ],
+    };
+    
+    $self->{components_path} = 'network::netgear::mseries::snmp::mode::components';
+    $self->{components_module} = ['fan', 'psu', 'temperature'];
+}
+
+sub snmp_execute {
+    my ($self, %options) = @_;
+    
+    $self->{snmp} = $options{snmp};
+    $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
+}
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                { 
+                                });
+    
+    return $self;
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check hardware.
+
+=over 8
+
+=item B<--component>
+
+Which component to check (Default: '.*').
+Can be: 'fan', 'psu', 'temperature'.
+
+=item B<--filter>
+
+Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu)
+Can also exclude specific instance: --filter=fan,1.1
+
+=item B<--absent-problem>
+
+Return an error if an entity is not 'present' (default is skipping) (comma seperated list)
+Can be specific or global: --absent-problem=fan,1
+
+=item B<--no-component>
+
+Return an error if no compenents are checked.
+If total (with skipped) is 0. (Default: 'critical' returns).
+
+=item B<--threshold-overload>
+
+Set to overload default threshold values (syntax: section,[instance,]status,regexp)
+It used before default thresholds (order stays).
+Example: --threshold-overload='psu,CRITICAL,^(?!(operational)$)'
+
+=item B<--warning>
+
+Set warning threshold for 'temperature', 'fan' (syntax: type,regexp,threshold)
+Example: --warning='temperature,.*,40'
+
+=item B<--critical>
+
+Set critical threshold for 'temperature', 'fan' (syntax: type,regexp,threshold)
+Example: --critical='temperature,.*,50'
+
+=back
+
+=cut
diff --git a/centreon-plugins/network/netgear/mseries/snmp/mode/memory.pm b/centreon-plugins/network/netgear/mseries/snmp/mode/memory.pm
new file mode 100644
index 000000000..d2e2e646e
--- /dev/null
+++ b/centreon-plugins/network/netgear/mseries/snmp/mode/memory.pm
@@ -0,0 +1,138 @@
+#
+# Copyright 2017 Centreon (http://www.centreon.com/)
+#
+# Centreon is a full-fledged industry-strength solution that meets
+# the needs in IT infrastructure and application monitoring for
+# service performance.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+package network::netgear::mseries::snmp::mode::memory;
+
+use base qw(centreon::plugins::templates::counter);
+
+use strict;
+use warnings;
+
+sub custom_usage_perfdata {
+    my ($self, %options) = @_;
+    
+    $self->{output}->perfdata_add(label => 'used', unit => 'B',
+                                  value => $self->{result_values}->{used},
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
+                                  min => 0, max => $self->{result_values}->{total});
+}
+
+sub custom_usage_threshold {
+    my ($self, %options) = @_;
+    
+    my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
+    return $exit;
+}
+
+sub custom_usage_output {
+    my ($self, %options) = @_;
+    
+    my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
+    my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
+    my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
+    
+    my $msg = sprintf("Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
+                      $total_size_value . " " . $total_size_unit,
+                      $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
+                      $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
+    return $msg;
+}
+
+sub custom_usage_calc {
+    my ($self, %options) = @_;
+
+    $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
+    $self->{result_values}->{prct_used} = $options{new_datas}->{$self->{instance} . '_prct_used'};
+
+    $self->{result_values}->{used} = int($self->{result_values}->{prct_used} * $self->{result_values}->{total} / 100);
+    $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
+    $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
+    
+    return 0;
+}
+
+sub set_counters {
+    my ($self, %options) = @_;
+    
+    $self->{maps_counters_type} = [
+        { name => 'memory', type => 0 }
+    ];
+    
+    $self->{maps_counters}->{memory} = [
+        { label => 'usage', set => {
+                key_values => [ { name => 'prct_used' }, { name => 'total' } ],
+                closure_custom_calc => $self->can('custom_usage_calc'),
+                closure_custom_output => $self->can('custom_usage_output'),
+                closure_custom_perfdata => $self->can('custom_usage_perfdata'),
+                closure_custom_threshold_check => $self->can('custom_usage_threshold'),
+            }
+        },
+    ];
+}
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                { 
+                                });
+    
+    return $self;
+}
+
+sub manage_selection {
+    my ($self, %options) = @_;
+
+    my $oid_agentSwitchCpuProcessMemFree = '.1.3.6.1.4.1.4526.10.1.1.4.1.0'; # KB
+    my $oid_agentSwitchCpuProcessMemAvailable = '.1.3.6.1.4.1.4526.10.1.1.4.2.0'; # KB
+    my $snmp_result = $options{snmp}->get_leef(oids => [$oid_agentSwitchCpuProcessMemFree, $oid_agentSwitchCpuProcessMemAvailable], nothing_quit => 1);
+
+    my $total = $snmp_result->{$oid_agentSwitchCpuProcessMemAvailable} * 1024;
+    $self->{memory} = {
+        prct_used => ($total - $snmp_result->{$oid_agentSwitchCpuProcessMemFree} * 1024) * 100 / $total, 
+        total => $total,
+    };
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check memory usage.
+
+=over 8
+
+=item B<--warning-usage>
+
+Threshold warning (in percent).
+
+=item B<--critical-usage>
+
+Threshold critical (in percent).
+
+=back
+
+=cut
diff --git a/centreon-plugins/network/netgear/mseries/snmp/plugin.pm b/centreon-plugins/network/netgear/mseries/snmp/plugin.pm
new file mode 100644
index 000000000..454375a16
--- /dev/null
+++ b/centreon-plugins/network/netgear/mseries/snmp/plugin.pm
@@ -0,0 +1,52 @@
+#
+# Copyright 2017 Centreon (http://www.centreon.com/)
+#
+# Centreon is a full-fledged industry-strength solution that meets
+# the needs in IT infrastructure and application monitoring for
+# service performance.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+package network::netgear::mseries::snmp::plugin;
+
+use strict;
+use warnings;
+use base qw(centreon::plugins::script_snmp);
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+
+    $self->{version} = '1.0';
+    %{$self->{modes}} = (
+                         'cpu'              => 'network::netgear::mseries::snmp::mode::cpu',
+                         'hardware'         => 'network::netgear::mseries::snmp::mode::hardware',
+                         'interfaces'       => 'snmp_standard::mode::interfaces',
+                         'list-interfaces'  => 'snmp_standard::mode::listinterfaces',
+                         'memory'           => 'network::netgear::mseries::snmp::mode::memory',
+                         );
+
+    return $self;
+}
+
+1;
+
+__END__
+
+=head1 PLUGIN DESCRIPTION
+
+Check Netgear Fully Managed Switches (M4200, M4300, M6100,...) in SNMP.
+
+=cut