diff --git a/src/hardware/pdu/sentry/snmp/mode/components/humidity.pm b/src/hardware/pdu/sentry/snmp/mode/components/humidity.pm new file mode 100644 index 0000000000..96fc6850e1 --- /dev/null +++ b/src/hardware/pdu/sentry/snmp/mode/components/humidity.pm @@ -0,0 +1,107 @@ +# +# Copyright 2026-Present 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 hardware::pdu::sentry::snmp::mode::components::humidity; + +use strict; +use warnings; + +my %map_temp_status = ( + 0 => 'normal', + 1 => 'notFound', + 2 => 'reading', + 3 => 'humidLow', + 4 => 'humidHigh', + 5 => 'readError', + 6 => 'lost', + 7 => 'noComm' +); + +my $mapping = { + tempHumidSensorID => { oid => '.1.3.6.1.4.1.1718.3.2.5.1.2' }, + tempHumidSensorName => { oid => '.1.3.6.1.4.1.1718.3.2.5.1.3' }, + tempHumidSensorHumidValue => { oid => '.1.3.6.1.4.1.1718.3.2.5.1.10' }, + tempHumidSensorHumidStatus => { oid => '.1.3.6.1.4.1.1718.3.2.5.1.9', map => \%map_temp_status }, +}; +my $oid_tempHumidSensorEntry = '.1.3.6.1.4.1.1718.3.2.5.1'; + +sub load { + my ($self) = @_; + + foreach (@{$self->{request}}) { + return if ($_->{oid} eq $oid_tempHumidSensorEntry); + } + push @{$self->{request}}, { oid => $oid_tempHumidSensorEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking humidities"); + $self->{components}->{humidity} = {name => 'humidities', total => 0, skip => 0}; + return if ($self->check_filter(section => 'humidity')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_tempHumidSensorEntry}})) { + next if ($oid !~ /^$mapping->{tempHumidSensorHumidStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_tempHumidSensorEntry}, instance => $instance); + + next if ($self->check_filter(section => 'humidity', instance => $result->{tempHumidSensorID})); + + if ($result->{tempHumidSensorHumidStatus} =~ /notFound/i) { + $self->{output}->output_add(long_msg => "skipping not present humidity sensor for '" . $result->{tempHumidSensorName}, debug => 1); + next; + } + + $self->{components}->{humidity}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Humidity '%s' status is '%s' [instance: %s, value: %s]", + $result->{tempHumidSensorName}, $result->{tempHumidSensorHumidStatus}, + $result->{tempHumidSensorID}, $result->{tempHumidSensorHumidValue})); + my $exit = $self->get_severity(section => 'humidity', instance => $result->{tempHumidSensorID}, value => $result->{tempHumidSensorHumidStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Humidity '%s' status is %s", + $result->{tempHumidSensorName}, $result->{tempHumidSensorHumidStatus})); + } + + if (defined($result->{tempHumidSensorHumidValue}) && $result->{tempHumidSensorHumidValue} =~ /[0-9]/) { + my $value = $result->{tempHumidSensorHumidValue}; + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'humidity', instance => $result->{tempHumidSensorID}, value => $value); + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Humidity '%s' value is %s %%", $result->{tempHumidSensorName}, $value)); + } + $self->{output}->perfdata_add( + label => 'humidity', + unit => '%', + nlabel => 'hardware.sensor.humidity.percentage', + instances => $result->{tempHumidSensorName}, + value => $value, + warning => $warn, + critical => $crit, + min => 0, + max => 100 + ); + } + } +} + +1; diff --git a/src/hardware/pdu/sentry/snmp/mode/components/temperature.pm b/src/hardware/pdu/sentry/snmp/mode/components/temperature.pm new file mode 100644 index 0000000000..6bcac927d5 --- /dev/null +++ b/src/hardware/pdu/sentry/snmp/mode/components/temperature.pm @@ -0,0 +1,104 @@ +# +# Copyright 2026-Present 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 hardware::pdu::sentry::snmp::mode::components::temperature; + +use strict; +use warnings; + +my %map_temp_status = ( + 0 => 'normal', + 1 => 'notFound', + 2 => 'reading', + 3 => 'tempLow', + 4 => 'tempHigh', + 5 => 'readError', + 6 => 'lost', + 7 => 'noComm' +); + +my $mapping = { + tempHumidSensorID => { oid => '.1.3.6.1.4.1.1718.3.2.5.1.2' }, + tempHumidSensorName => { oid => '.1.3.6.1.4.1.1718.3.2.5.1.3' }, + tempHumidSensorTempValue => { oid => '.1.3.6.1.4.1.1718.3.2.5.1.6' }, + tempHumidSensorTempStatus => { oid => '.1.3.6.1.4.1.1718.3.2.5.1.5', map => \%map_temp_status }, +}; +my $oid_tempHumidSensorEntry = '.1.3.6.1.4.1.1718.3.2.5.1'; + +sub load { + my ($self) = @_; + + foreach (@{$self->{request}}) { + return if ($_->{oid} eq $oid_tempHumidSensorEntry); + } + push @{$self->{request}}, { oid => $oid_tempHumidSensorEntry }; +} + +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_tempHumidSensorEntry}})) { + next if ($oid !~ /^$mapping->{tempHumidSensorTempStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_tempHumidSensorEntry}, instance => $instance); + + next if ($self->check_filter(section => 'temperature', instance => $result->{tempHumidSensorID})); + + if ($result->{tempHumidSensorTempStatus} =~ /notFound/i) { + $self->{output}->output_add(long_msg => "skipping not present temperature sensor for '" . $result->{tempHumidSensorName}, debug => 1); + next; + } + + $self->{components}->{temperature}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Temperature '%s' status is '%s' [instance: %s, value: %s]", + $result->{tempHumidSensorName}, $result->{tempHumidSensorTempStatus}, + $result->{tempHumidSensorID}, $result->{tempHumidSensorTempValue} / 10)); + my $exit = $self->get_severity(section => 'temperature', instance => $result->{tempHumidSensorID}, value => $result->{tempHumidSensorTempStatus}); + 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", + $result->{tempHumidSensorName}, $result->{tempHumidSensorTempStatus})); + } + + if (defined($result->{tempHumidSensorTempValue}) && $result->{tempHumidSensorTempValue} =~ /[0-9]/) { + my $value = $result->{tempHumidSensorTempValue} / 10; + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $result->{tempHumidSensorID}, value => $value); + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Temperature '%s' value is %s C", $result->{tempHumidSensorName}, $value)); + } + $self->{output}->perfdata_add( + label => 'temp', unit => 'C', + nlabel => 'hardware.sensor.temperature.celsius', + instances => $result->{tempHumidSensorName}, + value => $value, + warning => $warn, + critical => $crit + ); + } + } +} + +1; diff --git a/src/hardware/pdu/sentry/snmp/mode/infeeds.pm b/src/hardware/pdu/sentry/snmp/mode/infeeds.pm new file mode 100644 index 0000000000..1b45381209 --- /dev/null +++ b/src/hardware/pdu/sentry/snmp/mode/infeeds.pm @@ -0,0 +1,300 @@ +# +# Copyright 2026-Present 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 hardware::pdu::sentry::snmp::mode::infeeds; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); +use centreon::plugins::constants qw(:counters :values); +use centreon::plugins::misc qw/is_excluded/; + +sub custom_overall_status_output { + my ($self, %options) = @_; + + return sprintf( + "status: %s - load status: %s", + $self->{result_values}->{status}, + $self->{result_values}->{load_status} + ); +} + +sub prefix_infeed_output { + my ($self, %options) = @_; + + return sprintf("Infeed '%s' ", $options{instance_value}->{display}); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { + name => 'infeed', + type => COUNTER_TYPE_INSTANCE, + cb_prefix_output => 'prefix_infeed_output', + message_multiple => 'All current infeeds are ok', + skipped_code => { NO_VALUE() => 1 } + } + ]; + + $self->{maps_counters}->{infeed} = [ + { + label => 'status', + type => COUNTER_KIND_TEXT, + unknown_default => '%{status} =~ /noComm/i || %{load_status} =~ /noComm|readError/i', + warning_default => '%{load_status} =~ /loadLow/i', + critical_default => '%{status} =~ /error/i || %{load_status} =~ /loadHigh|overLoad/i', + set => + { + key_values => [ + { name => 'status' }, + { name => 'load_status' }, + { name => 'display' } + ], + closure_custom_output => $self->can('custom_overall_status_output'), + closure_custom_perfdata => sub {return 0;}, + closure_custom_threshold_check => \&catalog_status_threshold_ng + } + }, + { label => 'voltage', nlabel => 'infeed.voltage.volt', display_ok => 0, set => { + key_values => [ { name => 'voltage' }, { name => 'display' } ], + output_template => 'Voltage : %.2f V', + perfdatas => [ + { + template => '%s', + unit => 'V', + label_extra_instance => 1, + instance_use => 'display' + } + ], + } + }, + { label => 'load', nlabel => 'infeed.load.ampere', display_ok => 0, set => { + key_values => [ { name => 'load' }, { name => 'display' } ], + output_template => 'Load : %.2f A', + perfdatas => [ + { + template => '%s', + unit => 'A', + min => 0, + max => 'capacity', + label_extra_instance => 1, + instance_use => 'display' + } + ], + } + }, + { label => 'load-prct', nlabel => 'infeed.load.percentage', display_ok => 1, set => { + key_values => [ { name => 'load_prct' }, { name => 'display' } ], + output_template => 'Load : %.2f %%', + perfdatas => [ + { + template => '%.2f', + unit => '%', + min => 0, + max => 100, + label_extra_instance => 1, + instance_use => 'display' + } + ], + } + }, + { label => 'power', nlabel => 'infeed.power.watt', display_ok => 0, set => { + key_values => [ { name => 'power' }, { name => 'display' } ], + output_template => 'power: %s W', + perfdatas => [ + { + template => '%d', + unit => 'W', + min => 0, + label_extra_instance => 1, + instance_use => 'display' + } + ] + } + } + ]; +} + +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 => + { + 'include-infeed:s' => { name => 'include_infeed' }, + 'exclude-infeed:s' => { name => 'exclude_infeed' } + }); + + return $self; +} + +my $infeed_status = { + 0 => 'off', + 1 => 'on', + 2 => 'offWait', + 3 => 'onWait', + 4 => 'offError', + 5 => 'onError', + 6 => 'noComm', + 7 => 'reading', + 8 => 'offFuse', + 9 => 'onFuse' +}; + +my $infeed_load_status = { + 0 => 'normal', + 1 => 'notOn', + 2 => 'reading', + 3 => 'loadLow', + 4 => 'loadHigh', + 5 => 'overLoad', + 6 => 'readError', + 7 => 'noComm' +}; + +my $mapping = { + infeedID => { oid => '.1.3.6.1.4.1.1718.3.2.2.1.2' }, + infeedName => { oid => '.1.3.6.1.4.1.1718.3.2.2.1.3' }, + infeedStatus => { oid => '.1.3.6.1.4.1.1718.3.2.2.1.5', map => $infeed_status }, + infeedLoadStatus => { oid => '.1.3.6.1.4.1.1718.3.2.2.1.6', map => $infeed_load_status }, + infeedLoadValue => { oid => '.1.3.6.1.4.1.1718.3.2.2.1.7' }, + infeedCapacity => { oid => '.1.3.6.1.4.1.1718.3.2.2.1.10' }, + infeedVoltage => { oid => '.1.3.6.1.4.1.1718.3.2.2.1.11' }, + infeedPower => { oid => '.1.3.6.1.4.1.1718.3.2.2.1.12' } +}; + +my $oid_infeedEntry = '.1.3.6.1.4.1.1718.3.2.2.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_table(oid => $oid_infeedEntry, nothing_quit => 1); + + foreach my $oid (sort keys %$snmp_result) { + next if ($oid !~ /^$mapping->{infeedID}->{oid}\.(.*)$/); + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $1); + + next if is_excluded( + $result->{infeedID}, + $self->{option_results}->{include_infeed}, + $self->{option_results}->{exclude_infeed} + ); + + $self->{infeed}->{$result->{infeedID}} = + { + display => $result->{infeedName}, + voltage => $result->{infeedVoltage} * 0.1, + load => $result->{infeedLoadValue} * 0.01, + load_prct => defined($result->{infeedCapacity}) && $result->{infeedCapacity} > 0 ? + $result->{infeedLoadValue} * 0.01 / $result->{infeedCapacity} * 100 : undef, + capacity => $result->{infeedCapacity}, + power => $result->{infeedPower}, + status => $result->{infeedStatus}, + load_status => $result->{infeedLoadStatus}, + }; + + } + + if (scalar(keys %{$self->{infeed}}) <= 0) { + $self->{output}->option_exit(short_msg => "No infeeds matching with filter found."); + } +} + +1; + +__END__ + +=head1 MODE + +Check C current. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: C<--filter-counters='active-power'> + +=item B<--include-infeed> + +Filter C by number (can be a regexp). +Example: C<--include-infeed='Master_A'> + +=item B<--exclude-infeed> + +Exclude C by number (can be a regexp). +Example: C<--exclude-infeed='Master_B'> + +=item B<--unknown-status> + +Define the conditions to match for the status to be UNKNOWN. (default: '%{status} =~ /noComm/i || %{load_status} =~ /noComm|readError/i'). +You can use the following variables: C<%{status}>, C<%{load_status}>, C<%{display}> + +=item B<--warning-status> + +Define the conditions to match for the status to be WARNING. (default: '%{load_status} =~ /loadLow/i'). +You can use the following variables: C<%{status}>, C<%{load_status}>, C<%{display}> + +=item B<--critical-status> + +Define the conditions to match for the status to be CRITICAL. (default: '%{status} =~ /error/i || %{load_status} =~ /loadHigh|overLoad/i'). +You can use the following variables: C<%{status}>, C<%{display}> + +=item B<--warning-voltage> + +Warning threshold. (V) + +=item B<--critical-voltage> + +Critical threshold. (V) + +=item B<--warning-load> + +Warning threshold. (A) + +=item B<--critical-load> + +Critical threshold. (A) + +=item B<--warning-load-prct> + +Warning threshold. (%) + +=item B<--critical-load-prct> + +Critical threshold. (%) + +=item B<--warning-power> + +Warning threshold. (W) + +=item B<--critical-power> + +Critical threshold. (W) + +=back + +=cut diff --git a/src/hardware/pdu/sentry/snmp/mode/sensors.pm b/src/hardware/pdu/sentry/snmp/mode/sensors.pm new file mode 100644 index 0000000000..7e81d5a7a9 --- /dev/null +++ b/src/hardware/pdu/sentry/snmp/mode/sensors.pm @@ -0,0 +1,118 @@ +# +# Copyright 2026-Present 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 hardware::pdu::sentry::snmp::mode::sensors; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_numeric_check_section_option} = '^humidity|temperature$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + humidity => [ + ['notPresent', 'OK'], + ['belowMin', 'CRITICAL'], + ['belowLow', 'WARNING'], + ['normal', 'OK'], + ['aboveHigh', 'WARNING'], + ['aboveMax', 'CRITICAL'] + ], + temperature => [ + ['normal', 'OK'], + ['notFound', 'OK'], + ['reading', 'OK'], + ['tempHigh', 'CRITICAL'], + ['tempLow', 'WARNING'], + ['readError', 'UNKNOWN'], + ['lost', 'UNKNOWN'], + ['noComm', 'UNKNOWN'] + ], + }; + + $self->{components_path} = 'hardware::pdu::sentry::snmp::mode::components'; + $self->{components_module} = [ 'humidity', '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, force_new_perfdata => 1, no_absent => 1); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check components (humidity, temperature). + +=over 8 + +=item B<--component> + +Which component to check (default: '.*'). +Can be: 'humidity', 'temperature'. + +=item B<--filter> + +Exclude the items given as a comma-separated list (example: --filter=temperature --filter=humidity). +You can also exclude items from specific instances: --filter=temperature,1 + +=item B<--no-component> + +Define the expected status if no components are found (default: critical). + +=item B<--threshold-overload> + +Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,[instance,]status,regexp). +Example: --threshold-overload='temperature,CRITICAL,^(?!(normal)$)' + +=item B<--warning> + +Set warning threshold for temperatures (syntax: type,instance,threshold) +Example: --warning='temperature,.*,30' + +=item B<--critical> + +Set critical threshold for temperatures (syntax: type,instance,threshold) +Example: --critical='temperature,.*,40' + +=back + +=cut diff --git a/src/hardware/pdu/sentry/snmp/mode/systempower.pm b/src/hardware/pdu/sentry/snmp/mode/systempower.pm new file mode 100644 index 0000000000..b1d08ae96a --- /dev/null +++ b/src/hardware/pdu/sentry/snmp/mode/systempower.pm @@ -0,0 +1,128 @@ +# +# Copyright 2026-Present 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 hardware::pdu::sentry::snmp::mode::systempower; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); +use centreon::plugins::constants qw(:counters :values); + + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => COUNTER_TYPE_GLOBAL, skipped_code => { NO_VALUE() => 1 } } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total-power', nlabel => 'pdu.power.total.watt', display_ok => 1, set => { + key_values => [ { name => 'total_power' } ], + output_template => 'total power: %s W', + perfdatas => [ + { + template => '%d', + unit => 'W', + min => 0 + } + ] + } + }, + { label => 'power-factor', nlabel => 'pdu.power.factor.percent', display_ok => 1, set => { + key_values => [ { name => 'power_factor' } ], + output_template => 'power factor : %.2f %%', + perfdatas => [ + { + template => '%s', + unit => '%', + min => 0, + max => 100 + } + ], + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + return $self; +} + +my $oid_system_total_power = '.1.3.6.1.4.1.1718.3.1.6.0'; +my $oid_system_power_factor = '.1.3.6.1.4.1.1718.3.1.10.0'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_leef( + oids => [ + $oid_system_total_power, + $oid_system_power_factor + ], + nothing_quit => 1 + ); + + $self->{global} = { + total_power => $snmp_result->{$oid_system_total_power}, + power_factor => $snmp_result->{$oid_system_power_factor} + }; +} + +1; + +__END__ + +=head1 MODE + +Check Sentry PDU performance. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: C<--filter-counters='total-power'> + +=item B<--warning-total-power> + +Warning threshold. (W) + +=item B<--critical-total-power> + +Critical threshold. (W) + +=item B<--warning-power-factor> + +Warning threshold. (%) + +=item B<--critical-power-factor> + +Critical threshold. (%) + +=back + +=cut \ No newline at end of file diff --git a/src/hardware/pdu/sentry/snmp/mode/towerstatus.pm b/src/hardware/pdu/sentry/snmp/mode/towerstatus.pm new file mode 100644 index 0000000000..bfa29eb757 --- /dev/null +++ b/src/hardware/pdu/sentry/snmp/mode/towerstatus.pm @@ -0,0 +1,182 @@ +# +# Copyright 2026-Present 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 hardware::pdu::sentry::snmp::mode::towerstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); +use centreon::plugins::constants qw(:counters :values); +use centreon::plugins::misc qw/is_excluded/; + +sub prefix_tower_output { + my ($self, %options) = @_; + + return "Tower '" . $options{instance_value}->{display} . "' "; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("status : '%s'", $self->{result_values}->{status}); + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { + name => 'tower', + type => COUNTER_TYPE_INSTANCE, + cb_prefix_output => 'prefix_tower_output', + message_multiple => 'All towers are ok', + skipped_code => { NO_VALUE() => 1 } + } + ]; + + $self->{maps_counters}->{tower} = [ + { + label => 'status', + type => COUNTER_KIND_TEXT, + critical_default => '%{status} =~ /off/i', + set => + { + key_values => [ + { name => 'status' }, + { name => 'display' } + ], + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub {return 0;}, + closure_custom_threshold_check => \&catalog_status_threshold_ng + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); + bless $self, $class; + + $options{options}->add_options(arguments => + { + 'include-tower:s' => { name => 'include_tower' }, + 'exclude-tower:s' => { name => 'exclude_tower' } + }); + + return $self; +} + +my $tower_status = { + 0 => 'normal', + 1 => 'noComm', + 2 => 'fanFail', + 3 => 'overTemp', + 4 => 'nvmFail', + 5 => 'outOfBalance', +}; + +my $mapping = { + towerID => { oid => '.1.3.6.1.4.1.1718.3.2.1.1.2' }, + towerName => { oid => '.1.3.6.1.4.1.1718.3.2.1.1.3' }, + towerStatus => { oid => '.1.3.6.1.4.1.1718.3.2.1.1.4', map => $tower_status }, +}; + +my $oid_tower_entry = '.1.3.6.1.4.1.1718.3.2.1.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_table(oid => $oid_tower_entry, nothing_quit => 1); + + foreach my $oid (sort keys %$snmp_result) { + next if ($oid !~ /^$mapping->{towerID}->{oid}\.(.*)$/); + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $1); + + next if is_excluded( + $result->{towerName}, + $self->{option_results}->{include_tower}, + $self->{option_results}->{exclude_tower} + ); + + $self->{tower}->{$result->{towerID}} = + { + display => $result->{towerName}, + status => $result->{towerStatus}, + }; + }; + + if (scalar(keys %{$self->{tower}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No tower found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check tower. + +=over 8 + +=item B<--include-tower> + +Filter C by number (can be a regexp). +Example: C<--include-tower='Master'> + +=item B<--exclude-tower> + +Exclude C by number (can be a regexp). +Example: C<--exclude-tower='Master'> + +=item B<--unknown-status> + +Define the conditions to match for the status to be UNKNOWN. +You can use the following variables: C<%{status}>, C<%{display}> + +=item B<--warning-status> + +Define the conditions to match for the status to be WARNING (default: ''). +You can use the following variables: C<%{status}>, C<%{display}> + +=item B<--critical-status> + +Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /normal/'). +You can use the following variables: C<%{status}>, C<%{display}> + +=back + +=cut diff --git a/src/hardware/pdu/sentry/snmp/mode/uptime.pm b/src/hardware/pdu/sentry/snmp/mode/uptime.pm new file mode 100644 index 0000000000..e138e39d89 --- /dev/null +++ b/src/hardware/pdu/sentry/snmp/mode/uptime.pm @@ -0,0 +1,115 @@ +# +# Copyright 2026-Present 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 hardware::pdu::sentry::snmp::mode::uptime; + +use base qw(snmp_standard::mode::uptime); + +use strict; +use warnings; +use centreon::plugins::misc qw(is_not_empty); + +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 => { + 'check-overload' => { name => 'check_overload' }, + 'reboot-window:s' => { name => 'reboot_window', default => 5000 }, + 'unit:s' => { name => 'unit', default => 's' }, + 'add-sysdesc' => { name => 'add_sysdesc' } + }); + + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->SUPER::manage_selection(%options); + + my $oid_system_version = '.1.3.6.1.4.1.1718.3.1.1.0'; + my $oid_system_serial_number = '.1.3.6.1.4.1.1718.3.1.2.0'; + my $oid_systemlocation = '.1.3.6.1.4.1.1718.3.1.3.0'; + + my $result = $options{snmp}->get_leef( + oids => + [ + $oid_system_version, + $oid_system_serial_number, + $oid_systemlocation + ], + nothing_quit => 1 + ); + + my $info = ""; + + $info .= $result->{$oid_system_version} + if is_not_empty($result->{$oid_system_version}); + $info .= " [" . $result->{$oid_system_serial_number} . "]" + if is_not_empty($result->{$oid_system_serial_number}) && $info ne ""; + $info .= " - " . $result->{$oid_systemlocation} + if is_not_empty($result->{$oid_systemlocation}) && $info ne ""; + + $self->{global}->{sysdesc} = $info; + +} + +1; + +__END__ + +=head1 MODE + +Check system uptime. + +=over 8 + +=item B<--warning-uptime> + +Warning threshold. + +=item B<--critical-uptime> + +Critical threshold. + +=item B<--add-sysdesc> + +Display system description. + +=item B<--check-overload> + +Uptime counter limit is 4294967296 and overflow. +With that option, we manage the counter going back. But there is a few chance we can miss a reboot. + +=item B<--reboot-window> + +To be used with check-overload option. Time in milliseconds (default: 5000) +You increase the chance of not missing a reboot if you decrease that value. + +=item B<--unit> + +Select the time unit for thresholds. May be 's' for seconds, 'm' for minutes, 'h' for hours, 'd' for days, 'w' for weeks. Default is seconds. + +=back + +=cut diff --git a/src/hardware/pdu/sentry/snmp/plugin.pm b/src/hardware/pdu/sentry/snmp/plugin.pm new file mode 100644 index 0000000000..abf365a325 --- /dev/null +++ b/src/hardware/pdu/sentry/snmp/plugin.pm @@ -0,0 +1,52 @@ +# +# Copyright 2026-Present 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 hardware::pdu::sentry::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} = '0.1'; + $self->{modes} = { + 'infeeds' => 'hardware::pdu::sentry::snmp::mode::infeeds', + 'sensors' => 'hardware::pdu::sentry::snmp::mode::sensors', + 'system-power' => 'hardware::pdu::sentry::snmp::mode::systempower', + 'tower-status' => 'hardware::pdu::sentry::snmp::mode::towerstatus', + 'uptime' => 'hardware::pdu::sentry::snmp::mode::uptime', + }; + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Sentry PDU in SNMP. + +=cut