diff --git a/network/fiberstore/snmp/mode/components/fan.pm b/network/fiberstore/snmp/mode/components/fan.pm new file mode 100644 index 000000000..656d5edb5 --- /dev/null +++ b/network/fiberstore/snmp/mode/components/fan.pm @@ -0,0 +1,106 @@ +# +# 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 network::fiberstore::snmp::mode::components::fan; + +use strict; +use warnings; +use centreon::plugins::misc; + +my $map_status = { + 1 => 'active', 2 => 'deactive', 3 => 'notInstall', 4 => 'unsupport' +}; +my $map_position = { + 1 => 'default', 2 => 'left', 3 => 'right' +}; + +sub load { + my ($self) = @_; + + $self->{mapping_fan} = { + status => { oid => $self->{branch} . '.37.1.1.1.1.4', map => $map_status }, # devMFanStatus + speed => { oid => $self->{branch} . '.37.1.1.1.1.5' } # devMFanSpeed + }; + $self->{table_fan} = $self->{branch} . '.37.1.1.1'; + + push @{$self->{request}}, { + oid => $self->{table_fan}, + start => $self->{mapping_fan}->{status}->{oid}, + end => $self->{mapping_fan}->{speed}->{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}->{ $self->{table_fan} }})) { + next if ($oid !~ /^$self->{mapping_fan}->{status}->{oid}\.(\d+)\.(\d+)\.(\d+)$/); + my ($position, $instance) = ($1, $1 . '.' . $2 . '.' . $3); + my $description = $map_position->{$position} . ':' . $2 . ':' . $3; + my $result = $self->{snmp}->map_instance(mapping => $self->{mapping_fan}, results => $self->{results}->{ $self->{table_fan} }, instance => $instance); + + next if ($self->check_filter(section => 'fan', instance => $instance)); + + $self->{components}->{fan}->{total}++; + $self->{output}->output_add( + long_msg => sprintf( + "fan '%s' status is '%s' [instance: %s, speed: %s]", + $description, $result->{status}, $instance, centreon::plugins::misc::trim($result->{speed}) + ) + ); + + my $exit = $self->get_severity(section => 'fan', instance => $instance, value => $result->{status}); + 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", $description, $result->{status} + ) + ); + } + + next if ($result->{speed} !~ /([0-9]+)\s*%/i); + + my $fan_speed_value = $1; + my ($exit2, $warn, $crit) = $self->get_severity_numeric(section => 'fan.speed', instance => $instance, value => $fan_speed_value); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit2, + short_msg => sprintf( + "Fan '%s' speed is %s %%", $description, $fan_speed_value + ) + ); + } + $self->{output}->perfdata_add( + nlabel => 'hardware.fan.speed.percentage', + unit => '%', + instances => $description, + value => $fan_speed_value, + min => 0, + max => 100 + ); + } +} + +1; diff --git a/network/fiberstore/snmp/mode/components/power.pm b/network/fiberstore/snmp/mode/components/power.pm new file mode 100644 index 000000000..393cdadd7 --- /dev/null +++ b/network/fiberstore/snmp/mode/components/power.pm @@ -0,0 +1,79 @@ +# +# 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 network::fiberstore::snmp::mode::components::power; + +use strict; +use warnings; + +my $map_status = { + 1 => 'noAlert', 2 => 'alert', 3 => 'unsupported' +}; + +sub load { + my ($self) = @_; + + $self->{mapping_power} = { + status => { oid => $self->{branch} . '.37.1.2.1.7', map => $map_status } # devMPowerAlertStatus + }; + $self->{table_power} = $self->{branch} . '.37.1.2'; + + push @{$self->{request}}, { + oid => $self->{table_power}, + start => $self->{mapping_power}->{status}->{oid}, + end => $self->{mapping_power}->{status}->{oid} + }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'Checking powers'); + $self->{components}->{power} = { name => 'powers', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'power')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $self->{table_power} }})) { + next if ($oid !~ /^$self->{mapping_power}->{status}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $self->{mapping_power}, results => $self->{results}->{ $self->{table_power} }, instance => $instance); + + next if ($self->check_filter(section => 'power', instance => $instance)); + + $self->{components}->{power}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "power '%s' status is '%s' [instance: %s]", + $instance, $result->{status}, $instance + ) + ); + my $exit = $self->get_severity(section => 'power', instance => $instance, value => $result->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Power '%s' status is '%s'", $instance, $result->{status} + ) + ); + } + } +} + +1; diff --git a/network/fiberstore/snmp/mode/components/slot.pm b/network/fiberstore/snmp/mode/components/slot.pm new file mode 100644 index 000000000..7c2486449 --- /dev/null +++ b/network/fiberstore/snmp/mode/components/slot.pm @@ -0,0 +1,68 @@ +# +# 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 network::fiberstore::snmp::mode::components::slot; + +use strict; +use warnings; + +my $oid_lswSlotStatus = '.37.1.5.1.5'; # lswSlotStatus + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $self->{branch} . $oid_lswSlotStatus }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'Checking slots'); + $self->{components}->{slot} = {name => 'slots', total => 0, skip => 0}; + return if ($self->check_filter(section => 'slot')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $self->{branch} . $oid_lswSlotStatus }})) { + $oid =~ /\.(\d+\.\d+)$/; + my $instance = $1; + + next if ($self->check_filter(section => 'slot', instance => $instance)); + + my $status = $self->{results}->{ $self->{branch} . $oid_lswSlotStatus }->{$oid}; + $self->{components}->{slot}->{total}++; + $self->{output}->output_add( + long_msg => sprintf( + "slot '%s' status is %s [instance: %s]", + $instance, $status, $instance + ) + ); + + my $exit = $self->get_severity(section => 'slot', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Slot '%s' status is %s", $instance, $status + ) + ); + } + } +} + +1; diff --git a/network/fiberstore/snmp/mode/cpu.pm b/network/fiberstore/snmp/mode/cpu.pm new file mode 100644 index 000000000..1f6725e14 --- /dev/null +++ b/network/fiberstore/snmp/mode/cpu.pm @@ -0,0 +1,93 @@ +# +# 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 network::fiberstore::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, skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'cpu-utilization', nlabel => 'cpu.utilization.percentage', set => { + key_values => [ { name => 'cpu_util' } ], + output_template => 'Cpu utilization: %.2f%%', + perfdatas => [ + { template => '%s', min => 0, max => 100, unit => '%' } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + return $self; +} + +my $mapping = { + idle_legacy => { oid => '.1.3.6.1.4.1.27975.1.2.11' }, # ssCpuIdle + idle => { oid => '.1.3.6.1.4.1.52642.1.1.2.11' } # ssCpuIdle +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_leef( + oids => [ map($_->{oid} . '.0', values(%$mapping)) ], + nothing_quit => 1 + ); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => 0); + my $idle = 'idle'; + $idle = 'idle_legacy' if (!defined($result->{idle})); + + $self->{global} = { + cpu_util => 100 - $result->{$idle} + }; +} + +1; + +__END__ + +=head1 MODE + +Check memory. + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'cpu-utilization' (%). + +=back + +=cut diff --git a/network/fiberstore/snmp/mode/hardware.pm b/network/fiberstore/snmp/mode/hardware.pm new file mode 100644 index 000000000..23276f082 --- /dev/null +++ b/network/fiberstore/snmp/mode/hardware.pm @@ -0,0 +1,143 @@ +# +# 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 network::fiberstore::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_numeric_check_section_option} = + '^(?:fan\.speed)$'; + + $self->{cb_hook1} = 'check_version'; + $self->{cb_hook2} = 'get_informations'; + + $self->{thresholds} = { + fan => [ + ['active', 'OK'], + ['deactive', 'OK'], + ['notInstall', 'OK'], + ['unsupport', 'UNKNOWN'] + ], + power => [ + ['noAlert', 'OK'], + ['alert', 'CRITICAL'], + ['unsupported', 'OK'] + ], + slot => [ + ['absent', 'OK'], + ['creating', 'OK'], + ['initing', 'OK'], + ['syncing', 'OK'], + ['fail', 'CRITICAL'], + ['ready', 'OK'], + ['uninit', 'WARNING'], + ['conflict', 'CRITICAL'] + ], + }; + + $self->{components_path} = 'network::fiberstore::snmp::mode::components'; + $self->{components_module} = ['fan', 'power', 'slot']; +} + +sub check_version { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + + my $oid_version_legacy = '.1.3.6.1.4.1.27975.1.3.5.0'; + my $oid_version_current = '.1.3.6.1.4.1.52642.1.1.3.5.0'; + my $snmp_result = $self->{snmp}->get_leef( + oids => [$oid_version_legacy, $oid_version_current], + nothing_quit => 1 + ); + $self->{branch} = '.1.3.6.1.4.1.52642.1'; + if (!defined($snmp_result->{$oid_version_current})) { + $self->{branch} = '.1.3.6.1.4.1.27975'; + } + + $self->{output}->output_add(long_msg => 'version: ' . $snmp_result->{ $self->{branch} . '.1.3.5.0' }); +} + +sub get_informations { + my ($self, %options) = @_; + + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, 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: 'fan', 'power', 'slot'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=power) +Can also exclude specific instance: --filter=power,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,status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='fan,CRITICAL,notInstall' + +=item B<--warning> + +Set warning threshold for 'fan.speed' (syntax: type,regexp,threshold) +Example: --warning='fan.speed,.*,90' + +=item B<--critical> + +Set critical threshold for 'fan.speed' (syntax: type,regexp,threshold) +Example: --critical='fan.speed,.*,95' + +=back + +=cut diff --git a/network/fiberstore/snmp/mode/memory.pm b/network/fiberstore/snmp/mode/memory.pm new file mode 100644 index 000000000..b02a4bbc9 --- /dev/null +++ b/network/fiberstore/snmp/mode/memory.pm @@ -0,0 +1,132 @@ +# +# 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 network::fiberstore::snmp::mode::memory; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub custom_usage_output { + my ($self, %options) = @_; + + return sprintf( + 'Memory total: %s %s used: %s %s (%.2f%%) free: %s %s (%.2f%%)', + $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}), + $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}), + $self->{result_values}->{prct_used}, + $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}), + $self->{result_values}->{prct_free} + ); +} + +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 => [ + { template => '%d', min => 0, max => 'total', 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 => [ + { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1 } + ] + } + }, + { label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { + key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { template => '%.2f', min => 0, max => 100, unit => '%' } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + return $self; +} + +my $mapping = { + total_legacy => { oid => '.1.3.6.1.4.1.27975.1.1.5' }, # memTotalReal (kB) + free_legacy => { oid => '.1.3.6.1.4.1.27975.1.1.11' }, # memTotalFree (kB) + total => { oid => '.1.3.6.1.4.1.52642.1.1.1.5' }, # memTotalReal (kB) + free => { oid => '.1.3.6.1.4.1.52642.1.1.1.11' } # memTotalFree (kB) +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_leef( + oids => [ map($_->{oid} . '.0', values(%$mapping)) ], + nothing_quit => 1 + ); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => 0); + my ($total, $free) = ('total', 'free'); + if (!defined($result->{total})) { + ($total, $free) = ('total_legacy', 'free_legacy'); + } + + $result->{$total} *= 1024; + $result->{$free} *= 1024; + $self->{ram} = { + total => $result->{$total}, + used => $result->{$total} - $result->{$free}, + free => $result->{$free}, + prct_used => 100 - ($result->{$free} * 100 / $result->{$total}), + prct_free => $result->{$free} * 100 / $result->{$total} + }; +} + +1; + +__END__ + +=head1 MODE + +Check memory. + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%). + +=back + +=cut diff --git a/network/fiberstore/snmp/plugin.pm b/network/fiberstore/snmp/plugin.pm new file mode 100644 index 000000000..e8ab434b5 --- /dev/null +++ b/network/fiberstore/snmp/plugin.pm @@ -0,0 +1,52 @@ +# +# 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 network::fiberstore::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::fiberstore::snmp::mode::cpu', + 'hardware' => 'network::fiberstore::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::fiberstore::snmp::mode::memory' + }; + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check FiberStore in SNMP. + +=cut