diff --git a/centreon-plugins/network/nokia/timos/snmp/mode/cpu.pm b/centreon-plugins/network/nokia/timos/snmp/mode/cpu.pm new file mode 100644 index 000000000..cb642449b --- /dev/null +++ b/centreon-plugins/network/nokia/timos/snmp/mode/cpu.pm @@ -0,0 +1,96 @@ +# +# 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::nokia::timos::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 => 'usage', set => { + key_values => [ { name => 'cpu' } ], + output_template => 'Usage : %.2f %%', + perfdatas => [ + { label => 'cpu', value => 'cpu_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + ]; +} + +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) = @_; + + my $oid_sgiCpuUsage = '.1.3.6.1.4.1.6527.3.1.2.1.1.1.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [$oid_sgiCpuUsage], nothing_quit => 1); + + $self->{global} = { cpu => $snmp_result->{$oid_sgiCpuUsage} }; +} + +1; + +__END__ + +=head1 MODE + +Check CPU usage. + +=over 8 + +=item B<--warning-usage> + +Threshold warning. + +=item B<--critical-usage> + +Threshold critical. + +=back + +=cut diff --git a/centreon-plugins/network/nokia/timos/snmp/mode/hardware.pm b/centreon-plugins/network/nokia/timos/snmp/mode/hardware.pm new file mode 100644 index 000000000..5721aec2b --- /dev/null +++ b/centreon-plugins/network/nokia/timos/snmp/mode/hardware.pm @@ -0,0 +1,212 @@ +# +# 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::nokia::timos::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} = '^(entity)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^temperature$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + default => [ + ['unknown', 'UNKNOWN'], + ['inService', 'OK'], + ['outOfService', 'OK'], + ['diagnosing', 'OK'], + ['failed', 'CRITICAL'], + ['booting', 'OK'], + ['empty', 'OK'], + ['unprovisioned', 'OK'], + ['provisioned', 'OK'], + ['upgrade', 'OK'], + ['downgrade', 'OK'], + ['resetPending', 'OK'], + ['softReset', 'OK'], + ['preExtension', 'OK'], + ], + }; + + $self->{components_path} = 'network::nokia::timos::snmp::mode::components'; + $self->{components_module} = ['entity']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}, return_type => 1); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_load_components => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +1; + +=head1 MODE + +Check Hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'entity'. + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter=entity,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='entity,fan..*,CRITICAL,booting' + +=item B<--warning> + +Set warning threshold (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,20' + +=item B<--critical> + +Set critical threshold (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,30' + +=back + +=cut + +package network::nokia::timos::snmp::mode::components::entity; + +use strict; +use warnings; + +my %map_class = ( + 1 => 'other', 2 => 'unknown', 3 => 'physChassis', + 4 => 'container', 5 => 'powerSupply', 6 => 'fan', + 7 => 'sensor', 8 => 'ioModule', 9 => 'cpmModule', + 10 => 'fabricModule', 11 => 'mdaModule', + 12 => 'flashDiskModule', 13 => 'port', 14 => 'mcm', + 15 => 'ccm', 16 => 'oesCard', 17 => 'oesControlCard', + 18 => 'oesUserPanel', 19 => 'alarmInputModule', +); +my %map_truth = (1 => 'true', 2 => 'false'); +my %map_oper_state = ( + 1 => 'unknown', 2 => 'inService', 3 => 'outOfService', + 4 => 'diagnosing', 5 => 'failed', 6 => 'booting', + 7 => 'empty', 8 => 'provisioned', 9 => 'unprovisioned', + 10 => 'upgrade', 11 => 'downgrade', 12 => 'inServiceUpgrade', + 13 => 'inServiceDowngrade', 14 => 'resetPending', + 15 => 'softReset', 16 => 'preExtension', +); + +my $mapping = { + tmnxHwClass => { oid => '.1.3.6.1.4.1.6527.3.1.2.2.1.8.1.7', map => \%map_class }, + tmnxHwName => { oid => '.1.3.6.1.4.1.6527.3.1.2.2.1.8.1.8' }, + tmnxHwOperState => { oid => '.1.3.6.1.4.1.6527.3.1.2.2.1.8.1.16', map => \%map_oper_state }, + tmnxHwTempSensor => { oid => '.1.3.6.1.4.1.6527.3.1.2.2.1.8.1.17', map => \%map_truth }, + tmnxHwTemperature => { oid => '.1.3.6.1.4.1.6527.3.1.2.2.1.8.1.18' }, + tmnxHwTempThreshold => { oid => '.1.3.6.1.4.1.6527.3.1.2.2.1.8.1.19' }, +}; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $mapping->{tmnxHwClass}->{oid} }, { oid => $mapping->{tmnxHwName}->{oid} }, + { oid => $mapping->{tmnxHwTempSensor}->{oid} }, { oid => $mapping->{tmnxHwOperState}->{oid} }, + { oid => $mapping->{tmnxHwTemperature}->{oid} }, { oid => $mapping->{tmnxHwTempThreshold}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking entities"); + $self->{components}->{entity} = {name => 'entity', total => 0, skip => 0}; + return if ($self->check_filter(section => 'entity')); + + my ($exit, $warn, $crit, $checked); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}})) { + next if ($oid !~ /^$mapping->{tmnxHwName}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + + next if ($self->check_filter(section => 'entity', instance => $result->{tmnxHwClass} . '.' . $instance)); + + $self->{components}->{entity}->{total}++; + $self->{output}->output_add(long_msg => sprintf("%s '%s' status is '%s' [instance = %s, temperature = %s]", + $result->{tmnxHwClass}, $result->{tmnxHwName}, + $result->{tmnxHwOperState}, $result->{tmnxHwClass} . '.' . $instance, + $result->{tmnxHwTempSensor} eq 'true' ? $result->{tmnxHwTemperature} : '-')); + $exit = $self->get_severity(label => 'default', section => 'entity', instance => $result->{tmnxHwClass} . '.' . $instance, value => $result->{tmnxHwOperState}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("%s '%s' status is '%s'", $result->{tmnxHwClass}, $result->{tmnxHwName}, $result->{tmnxHwOperState})); + } + + next if ($result->{tmnxHwTempSensor} eq 'false'); + ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $result->{tmnxHwClass} . '.' . $instance,, value => $result->{tmnxHwTemperature}); + if ($checked == 0 && $result->{tmnxHwTempThreshold} != -1 ) { + $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $result->{tmnxHwClass} . '.' . $instance, value => $result->{tmnxHwTempThreshold}); + + $exit = $self->{perfdata}->threshold_check(value => $result->{slHdwTempSensorCurrentTemp}, threshold => [ { label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' }]); + $warn = undef; + $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $result->{tmnxHwClass} . '.' . $instance); + } + + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("%s '%s' temperature is '%s' C", $result->{tmnxHwClass}, + $result->{tmnxHwName}, $result->{tmnxHwTemperature})); + } + $self->{output}->perfdata_add(label => 'temperature_' . $result->{tmnxHwName}, unit => 'C', + value => $result->{tmnxHwTemperature}, + warning => $warn, + critical => $crit + ); + } +} + +1; diff --git a/centreon-plugins/network/nokia/timos/snmp/mode/memory.pm b/centreon-plugins/network/nokia/timos/snmp/mode/memory.pm new file mode 100644 index 000000000..9b59ba400 --- /dev/null +++ b/centreon-plugins/network/nokia/timos/snmp/mode/memory.pm @@ -0,0 +1,141 @@ +# +# 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::nokia::timos::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}->{free} = $options{new_datas}->{$self->{instance} . '_free'}; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; + $self->{result_values}->{total} = $self->{result_values}->{free} + $self->{result_values}->{used}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{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 => 'used' }, { name => 'free' } ], + 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_sgiKbMemoryUsed = '.1.3.6.1.4.1.6527.3.1.2.1.1.9.0'; # in KB + my $oid_sgiKbMemoryAvailable = '.1.3.6.1.4.1.6527.3.1.2.1.1.10.0'; # in KB + my $oid_sgiMemoryUsed = '.1.3.6.1.4.1.6527.3.1.2.1.1.2.0'; # in B + my $oid_sgiMemoryAvailable = '.1.3.6.1.4.1.6527.3.1.2.1.1.3.0'; # in B + my $snmp_result = $options{snmp}->get_leef(oids => [$oid_sgiKbMemoryUsed, $oid_sgiKbMemoryAvailable, $oid_sgiMemoryUsed, $oid_sgiMemoryAvailable], + nothing_quit => 1); + + $self->{memory} = { + used => defined($snmp_result->{$oid_sgiKbMemoryUsed}) ? $snmp_result->{$oid_sgiKbMemoryUsed} * 1024 : $snmp_result->{$oid_sgiMemoryUsed}, + free => defined($snmp_result->{$oid_sgiKbMemoryAvailable}) ? $snmp_result->{$oid_sgiKbMemoryAvailable} * 1024 : $snmp_result->{$oid_sgiMemoryAvailable}, + }; + +} + +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/nokia/timos/snmp/plugin.pm b/centreon-plugins/network/nokia/timos/snmp/plugin.pm new file mode 100644 index 000000000..41a839324 --- /dev/null +++ b/centreon-plugins/network/nokia/timos/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::nokia::timos::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::nokia::timos::snmp::mode::cpu', + 'hardware' => 'network::nokia::timos::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::nokia::timos::snmp::mode::memory', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Nokia TiMOS (SR OS) equipments (7750SR, 7210SAS) in SNMP. + +=cut