diff --git a/storage/lenovo/iomega/snmp/mode/components/disk.pm b/storage/lenovo/iomega/snmp/mode/components/disk.pm new file mode 100644 index 000000000..59455a96d --- /dev/null +++ b/storage/lenovo/iomega/snmp/mode/components/disk.pm @@ -0,0 +1,71 @@ +# +# Copyright 2020 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 storage::lenovo::iomega::snmp::mode::components::disk; + +use strict; +use warnings; + +my $mapping = { + diskID => { oid => '.1.3.6.1.4.1.11369.10.4.3.1.2' }, + diskStatus => { oid => '.1.3.6.1.4.1.11369.10.4.3.1.4' }, +}; +my $oid_diskEntry = '.1.3.6.1.4.1.11369.10.4.3.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_diskEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking disks'); + $self->{components}->{disk} = { name => 'disks', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'disk')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $oid_diskEntry }})) { + next if ($oid !~ /^$mapping->{diskID}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $oid_diskEntry }, instance => $instance); + + next if ($self->check_filter(section => 'disk', instance => $instance)); + + $self->{components}->{disk}->{total}++; + $self->{output}->output_add( + long_msg => sprintf( + "disk '%s' status is '%s' [instance = %s]", + $result->{diskID}, $result->{diskStatus}, $instance + ) + ); + my $exit = $self->get_severity(section => 'disk', value => $result->{diskStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Disk '%s' status is '%s'", $result->{diskID}, $result->{diskStatus} + ) + ); + } + } +} + +1; diff --git a/storage/lenovo/iomega/snmp/mode/components/fan.pm b/storage/lenovo/iomega/snmp/mode/components/fan.pm new file mode 100644 index 000000000..6775f811d --- /dev/null +++ b/storage/lenovo/iomega/snmp/mode/components/fan.pm @@ -0,0 +1,84 @@ +# +# Copyright 2020 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 storage::lenovo::iomega::snmp::mode::components::fan; + +use strict; +use warnings; + +my $mapping = { + fanName => { oid => '.1.3.6.1.4.1.11369.10.6.1.1.2' }, + fanValue => { oid => '.1.3.6.1.4.1.11369.10.6.1.1.3' } +}; +my $oid_fanEntry = '.1.3.6.1.4.1.11369.10.6.1.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { + oid => $oid_fanEntry, + start => $mapping->{fanName}->{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')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $oid_fanEntry }})) { + next if ($oid !~ /^$mapping->{fanValue}->{oid}\.(.*)$/); + my $instance = $1; + + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $oid_fanEntry }, instance => $instance); + + next if ($self->check_filter(section => 'fan', instance => $instance)); + + $self->{components}->{fan}->{total}++; + $self->{output}->output_add( + long_msg => sprintf( + "fan '%s' speed is '%s' rpm [instance = %s]", + $result->{fanName}, $result->{fanValue}, $instance + ) + ); + + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{fanValue}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "fan '%s' speed is '%s' rpm", $result->{fanName}, $result->{fanValue} + ) + ); + } + $self->{output}->perfdata_add( + nlabel => 'hardware.fan.speed.rpm', + unit => 'rpm', + instances => $result->{fanName}, + value => $result->{fanValue}, + warning => $warn, + critical => $crit, min => 0 + ); + } +} + +1; diff --git a/storage/lenovo/iomega/snmp/mode/components/raid.pm b/storage/lenovo/iomega/snmp/mode/components/raid.pm new file mode 100644 index 000000000..0b6031253 --- /dev/null +++ b/storage/lenovo/iomega/snmp/mode/components/raid.pm @@ -0,0 +1,67 @@ +# +# Copyright 2020 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 storage::lenovo::iomega::snmp::mode::components::raid; + +use strict; +use warnings; + +my $mapping = { + raidStatus => { oid => '.1.3.6.1.4.1.11369.10.4.1' } +}; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $mapping->{raidStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking raids'); + $self->{components}->{raid} = { name => 'raids', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'raid')); + + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $mapping->{raidStatus}->{oid} }, instance => '0'); + return if (!defined($result->{raidStatus})); + + my $instance = 1; + next if ($self->check_filter(section => 'raid', instance => $instance)); + $self->{components}->{raid}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "raid '%s' status is '%s' [instance = %s]", + $instance, $result->{raidStatus}, $instance + ) + ); + my $exit = $self->get_severity(section => 'raid', value => $result->{raidStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Raid '%s' status is '%s'", $instance, $result->{raidStatus} + ) + ); + } +} + +1; diff --git a/storage/lenovo/iomega/snmp/mode/components/temperature.pm b/storage/lenovo/iomega/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..84e2e93b2 --- /dev/null +++ b/storage/lenovo/iomega/snmp/mode/components/temperature.pm @@ -0,0 +1,84 @@ +# +# Copyright 2020 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 storage::lenovo::iomega::snmp::mode::components::temperature; + +use strict; +use warnings; + +my $mapping = { + tempName => { oid => '.1.3.6.1.4.1.11369.10.6.2.1.2' }, + tempValue => { oid => '.1.3.6.1.4.1.11369.10.6.2.1.3' } +}; +my $oid_tempEntry = '.1.3.6.1.4.1.11369.10.6.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { + oid => $oid_tempEntry, + start => $mapping->{tempName}->{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')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $oid_tempEntry }})) { + next if ($oid !~ /^$mapping->{tempValue}->{oid}\.(.*)$/); + my $instance = $1; + + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $oid_tempEntry }, instance => $instance); + + next if ($self->check_filter(section => 'temperature', instance => $instance)); + + $self->{components}->{temperature}->{total}++; + $self->{output}->output_add( + long_msg => sprintf( + "temperature '%s' is '%s' celsius [instance = %s]", + $result->{tempName}, $result->{tempValue}, $instance + ) + ); + + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{tempValue}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "temperature '%s' is '%s' celsius", $result->{tempName}, $result->{tempValue} + ) + ); + } + $self->{output}->perfdata_add( + nlabel => 'hardware.temperature.celsius', + unit => 'C', + instances => $result->{tempName}, + value => $result->{tempValue}, + warning => $warn, + critical => $crit, min => 0 + ); + } +} + +1; diff --git a/storage/lenovo/iomega/snmp/mode/components/voltage.pm b/storage/lenovo/iomega/snmp/mode/components/voltage.pm new file mode 100644 index 000000000..d0df804a3 --- /dev/null +++ b/storage/lenovo/iomega/snmp/mode/components/voltage.pm @@ -0,0 +1,84 @@ +# +# Copyright 2020 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 storage::lenovo::iomega::snmp::mode::components::voltage; + +use strict; +use warnings; + +my $mapping = { + voltName => { oid => '.1.3.6.1.4.1.11369.10.6.3.1.2' }, + voltValue => { oid => '.1.3.6.1.4.1.11369.10.6.3.1.3' } +}; +my $oid_voltEntry = '.1.3.6.1.4.1.11369.10.6.3.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { + oid => $oid_voltEntry, + start => $mapping->{voltName}->{oid} + }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking voltages'); + $self->{components}->{voltage} = { name => 'voltages', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'voltage')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $oid_voltEntry }})) { + next if ($oid !~ /^$mapping->{voltValue}->{oid}\.(.*)$/); + my $instance = $1; + + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $oid_voltEntry }, instance => $instance); + + next if ($self->check_filter(section => 'voltage', instance => $instance)); + + $self->{components}->{voltage}->{total}++; + $self->{output}->output_add( + long_msg => sprintf( + "voltage '%s' is '%s' mV [instance = %s]", + $result->{voltName}, $result->{voltValue}, $instance + ) + ); + + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, value => $result->{voltValue}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "voltage '%s' is '%s' mV", $result->{voltName}, $result->{voltValue} + ) + ); + } + $self->{output}->perfdata_add( + nlabel => 'hardware.voltage.millivolt', + unit => 'mV', + instances => $result->{voltName}, + value => $result->{voltValue}, + warning => $warn, + critical => $crit, min => 0 + ); + } +} + +1; diff --git a/storage/lenovo/iomega/snmp/mode/hardware.pm b/storage/lenovo/iomega/snmp/mode/hardware.pm new file mode 100644 index 000000000..08fbbe626 --- /dev/null +++ b/storage/lenovo/iomega/snmp/mode/hardware.pm @@ -0,0 +1,117 @@ +# +# Copyright 2020 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 storage::lenovo::iomega::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} = '^(?:raid|disk)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(?:temperature|temperature|voltage)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + raid => [ + ['normal', 'OK'], + ['rebuilding', 'OK'], + ['degraded', 'WARNING'], + ['rebuildfs', 'OK'], + ['faulted', 'CRITICAL'] + ], + disk => [ + ['normal', 'OK'], + ['foreign', 'WARNING'], + ['faulted', 'CRITICAL'], + ['missing', 'OK'] + ] + }; + + $self->{components_path} = 'storage::lenovo::iomega::snmp::mode::components'; + $self->{components_module} = ['raid', 'disk', 'voltage', 'temperature', 'fan']; +} + +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, no_absent => 1, force_new_perfdata => 1); + bless $self, $class; + + $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: 'raid', 'disk', 'voltage', 'temperature', 'fan'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=fan) +Can also exclude specific instance: --filter=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='disk,WARNING,missing' + +=item B<--warning> + +Set warning threshold for 'temperature', 'voltage', 'fan' (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,40' + +=item B<--critical> + +Set critical threshold for 'temperature', 'voltage', 'fan' (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,50' + +=back + +=cut diff --git a/storage/lenovo/iomega/snmp/mode/interfaces.pm b/storage/lenovo/iomega/snmp/mode/interfaces.pm new file mode 100644 index 000000000..f33bf5d60 --- /dev/null +++ b/storage/lenovo/iomega/snmp/mode/interfaces.pm @@ -0,0 +1,187 @@ +# +# Copyright 2020 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 storage::lenovo::iomega::snmp::mode::interfaces; + +use base qw(snmp_standard::mode::interfaces); + +use strict; +use warnings; + +sub default_oid_filter_name { + my ($self, %options) = @_; + + return 'ifdesc'; +} + +sub default_oid_display_name { + my ($self, %options) = @_; + + return 'ifdesc'; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + return $self; +} + + +1; + +__END__ + +=head1 MODE + +Check interfaces. + +=over 8 + +=item B<--add-global> + +Check global port statistics (By default if no --add-* option is set). + +=item B<--add-status> + +Check interface status. + +=item B<--add-duplex-status> + +Check duplex status (with --warning-status and --critical-status). + +=item B<--add-traffic> + +Check interface traffic. + +=item B<--add-errors> + +Check interface errors. + +=item B<--add-cast> + +Check interface cast. + +=item B<--add-speed> + +Check interface speed. + +=item B<--add-volume> + +Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{admstatus} eq "up" and %{opstatus} ne "up"'). +Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} + +=item B<--warning-*> + +Threshold warning. +Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', +'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', +'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%), +'speed' (b/s). + +=item B<--critical-*> + +Threshold critical. +Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', +'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', +'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%), +'speed' (b/s). + +=item B<--units-traffic> + +Units of thresholds for the traffic (Default: '%') ('%', 'b/s'). + +=item B<--units-errors> + +Units of thresholds for errors/discards (Default: '%') ('%', 'absolute'). + +=item B<--nagvis-perfdata> + +Display traffic perfdata to be compatible with nagvis widget. + +=item B<--interface> + +Set the interface (number expected) ex: 1,2,... (empty means 'check all interface'). + +=item B<--name> + +Allows to use interface name with option --interface instead of interface oid index (Can be a regexp) + +=item B<--speed> + +Set interface speed for incoming/outgoing traffic (in Mb). + +=item B<--speed-in> + +Set interface speed for incoming traffic (in Mb). + +=item B<--speed-out> + +Set interface speed for outgoing traffic (in Mb). + +=item B<--no-skipped-counters> + +Don't skip counters when no change. + +=item B<--force-counters32> + +Force to use 32 bits counters (even in snmp v2c and v3). Should be used when 64 bits counters are buggy. + +=item B<--reload-cache-time> + +Time in minutes before reloading cache file (default: 180). + +=item B<--oid-filter> + +Choose OID used to filter interface (default: ifDesc) (values: ifDesc, ifAlias, ifName, IpAddr). + +=item B<--oid-display> + +Choose OID used to display interface (default: ifDesc) (values: ifDesc, ifAlias, ifName, IpAddr). + +=item B<--oid-extra-display> + +Add an OID to display. + +=item B<--display-transform-src> + +Regexp src to transform display value. + +=item B<--display-transform-dst> + +Regexp dst to transform display value. + +=item B<--show-cache> + +Display cache interface datas. + +=back + +=cut diff --git a/storage/lenovo/iomega/snmp/mode/memory.pm b/storage/lenovo/iomega/snmp/mode/memory.pm new file mode 100644 index 000000000..41a997002 --- /dev/null +++ b/storage/lenovo/iomega/snmp/mode/memory.pm @@ -0,0 +1,184 @@ +# +# Copyright 2020 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 storage::lenovo::iomega::snmp::mode::memory; + +use base qw(snmp_standard::mode::storage); + +use strict; +use warnings; + +sub custom_usage_output { + my ($self, %options) = @_; + + return sprintf( + 'Ram Total: %s %s Used (-buffers/cache): %s %s (%.2f%%) Free: %s %s (%.2f%%)', + $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}), + $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}), + $self->{result_values}->{prct_used_absolute}, + $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}), + $self->{result_values}->{prct_free_absolute} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'ram', type => 0, skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{ram} = [ + { label => 'usage', nlabel => 'memory.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1 } + ] + } + }, + { label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1 } + ] + } + }, + { label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { + key_values => [ { name => 'prct_used' } ], + output_template => 'Ram Used : %.2f %%', + perfdatas => [ + { value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, + unit => '%' } + ] + } + }, + { label => 'buffer', nlabel => 'memory.buffer.bytes', set => { + key_values => [ { name => 'buffer' } ], + output_template => 'Buffer: %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'buffer_absolute', template => '%d', + min => 0, unit => 'B' } + ] + } + }, + { label => 'cached', nlabel => 'memory.cached.bytes', set => { + key_values => [ { name => 'cached' } ], + output_template => 'Cached: %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'cached_absolute', template => '%d', + min => 0, unit => 'B' } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + return $self; +} + +my $mapping = { + hrStorageDescr => { oid => '.1.3.6.1.2.1.25.2.3.1.3' }, + hrStorageAllocationUnits => { oid => '.1.3.6.1.2.1.25.2.3.1.4' }, + hrStorageSize => { oid => '.1.3.6.1.2.1.25.2.3.1.5' }, + hrStorageUsed => { oid => '.1.3.6.1.2.1.25.2.3.1.6' } +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_hrstoragetype = '.1.3.6.1.2.1.25.2.3.1.2'; + + my $snmp_result = $options{snmp}->get_table(oid => $oid_hrstoragetype, nothing_quit => 1); + my $storages = []; + foreach (keys %$snmp_result) { + next if ($snmp_result->{$_} !~ /(?:\.1|\.2)$/); + /^$oid_hrstoragetype\.(.*)$/; + push @$storages, $1; + } + + $options{snmp}->load( + oids => [map($_->{oid}, values(%$mapping))], + instances => $storages, + nothing_quit => 1 + ); + $snmp_result = $options{snmp}->get_leef(); + + my ($total, $used, $cached, $buffer); + #.1.3.6.1.2.1.25.2.3.1.3.1 = STRING: Physical memory + #.1.3.6.1.2.1.25.2.3.1.3.2 = STRING: Memory buffers + #.1.3.6.1.2.1.25.2.3.1.3.3 = STRING: Cached memory + foreach (@$storages) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + next if (!defined($result->{hrStorageUsed})); + my $current = $result->{hrStorageUsed} * $result->{hrStorageAllocationUnits}; + next if ($current < 0); + + if ($result->{hrStorageDescr} =~ /Cached\s+memory/i) { + $cached = $current; + } elsif ($result->{hrStorageDescr} =~ /Memory\s+buffers/i) { + $buffer = $current; + } elsif ($result->{hrStorageDescr} =~ /Physical\s+memory/i) { + $used = $current; + $total = $result->{hrStorageSize} * $result->{hrStorageAllocationUnits}; + } + } + + $used -= (defined($cached) ? $cached : 0) - (defined($buffer) ? $buffer : 0); + $self->{ram} = { + total => $total, + cached => $cached, + buffer => $buffer, + used => $used, + free => $total - $used, + prct_used => $used * 100 / $total, + prct_free => 100 - ($used * 100 / $total) + }; +} + +1; + +__END__ + +=head1 MODE + +Check memory. + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%), +'buffer' (B), 'cached' (B). + +=back + +=cut diff --git a/storage/lenovo/iomega/snmp/plugin.pm b/storage/lenovo/iomega/snmp/plugin.pm new file mode 100644 index 000000000..428dac58c --- /dev/null +++ b/storage/lenovo/iomega/snmp/plugin.pm @@ -0,0 +1,53 @@ +# +# Copyright 2020 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 storage::lenovo::iomega::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' => 'snmp_standard::mode::cpu', + 'hardware' => 'storage::lenovo::iomega::snmp::mode::hardware', + 'interfaces' => 'storage::lenovo::iomega::snmp::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'storage::lenovo::iomega::snmp::mode::memory', + 'storage' => 'snmp_standard::mode::storage' + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Lenovo Nas Iomega (ix2) in SNMP. + +=cut