From fee47b36cba20401ea14eed42d50923d7f9b6fd4 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 25 Mar 2020 16:04:23 +0100 Subject: [PATCH] wip: eltek enexus snmp --- .../devices/eltek/enexus/snmp/mode/alarms.pm | 175 ++++++++++ .../devices/eltek/enexus/snmp/mode/battery.pm | 317 ++++++++++++++++++ .../devices/eltek/enexus/snmp/mode/outputs.pm | 198 +++++++++++ hardware/devices/eltek/enexus/snmp/plugin.pm | 50 +++ 4 files changed, 740 insertions(+) create mode 100644 hardware/devices/eltek/enexus/snmp/mode/alarms.pm create mode 100644 hardware/devices/eltek/enexus/snmp/mode/battery.pm create mode 100644 hardware/devices/eltek/enexus/snmp/mode/outputs.pm create mode 100644 hardware/devices/eltek/enexus/snmp/plugin.pm diff --git a/hardware/devices/eltek/enexus/snmp/mode/alarms.pm b/hardware/devices/eltek/enexus/snmp/mode/alarms.pm new file mode 100644 index 000000000..dcb1c84a2 --- /dev/null +++ b/hardware/devices/eltek/enexus/snmp/mode/alarms.pm @@ -0,0 +1,175 @@ +# +# 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 hardware::devices::eltek::enexus::snmp::mode::alarms; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use centreon::plugins::misc; + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf('status: %s', + $self->{result_values}->{status} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'alarm', type => 1, cb_prefix_output => 'prefix_alarm_output', message_multiple => 'All alarms are ok', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'alarms-active', nlabel => 'alarms.active.count', display_ok => 0, set => { + key_values => [ { name => 'active' }, { name => 'total' } ], + output_template => 'current active alarms: %d', + perfdatas => [ + { value => 'active_absolute', template => '%d', min => 0, max => 'total_absolute' } + ] + } + } + ]; + + $self->{maps_counters}->{alarm} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'name' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + } + ]; +} + +sub prefix_alarm_output { + my ($self, %options) = @_; + + return "Alarm '" . $options{instance_value}->{name} . "' "; +} + +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 => { + 'filter-name:s' => { name => 'filter_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} eq "alarm"' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +my $map_status = { 0 => 'normal', 1 => 'alarm' }; + +my $mapping = { + alarmGroupStatus => { oid => '.1.3.6.1.4.1.12148.10.14.1.1.2', map => $map_status }, + alarmGroupDescription => { oid => '.1.3.6.1.4.1.12148.10.14.1.1.3' } +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_alarmGroupEntry = '.1.3.6.1.4.1.12148.10.14.1.1'; + my $snmp_result = $options{snmp}->get_table( + oid => $oid_alarmGroupEntry, + start => $mapping->{alarmGroupStatus}->{oid}, + nothing_quit => 1 + ); + + $self->{global} = { total => 0, active => 0 }; + $self->{alarm} = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{alarmGroupStatus}->{oid}\.(.*)$/); + my $instance = $1; + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + $result->{alarmGroupDescription} = centreon::plugins::misc::trim($result->{alarmGroupDescription}); + $result->{alarmGroupDescription} = $instance if ($result->{alarmGroupDescription} eq ''); + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{alarmGroupDescription} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping alarm '" . $result->{alarmGroupDescription} . "'.", debug => 1); + next; + } + + $self->{alarm}->{$instance} = { + name => $result->{alarmGroupDescription}, + status => $result->{alarmGroupStatus} + }; + $self->{global}->{total}++; + $self->{global}->{active}++ if ($result->{alarmGroupStatus} eq 'alarm'); + } +} + +1; + +__END__ + +=head1 MODE + +Check alarms. + +=over 8 + +=item B<--filter-name> + +Filter name (can be a regexp). + +=item B<--unknown-status> + +Set unknown threshold for status (Default: ''). +Can used special variables like: %{state}, %{status}, %{lastOpError}, %{display} + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{name}, %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} eq "alarm"). +Can used special variables like: %{name}, %{status} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'alarms-active'. + +=back + +=cut diff --git a/hardware/devices/eltek/enexus/snmp/mode/battery.pm b/hardware/devices/eltek/enexus/snmp/mode/battery.pm new file mode 100644 index 000000000..29857b605 --- /dev/null +++ b/hardware/devices/eltek/enexus/snmp/mode/battery.pm @@ -0,0 +1,317 @@ +# +# 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 hardware::devices::eltek::enexus::snmp::mode::battery; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use centreon::plugins::misc; + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf('status: %s', + $self->{result_values}->{status} + ); +} + +sub custom_temperature_output { + my ($self, %options) = @_; + + return sprintf('temperature: %s %s', + $self->{result_values}->{temperature_absolute}, + $self->{result_values}->{temperature_unit_absolute} + ); +} + +sub custom_temperature_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + nlabel => 'battery.temperature.' . ($self->{result_values}->{temperature_unit_absolute} eq 'C' ? 'celsius' : 'fahrenheit'), + unit => $self->{result_values}->{temperature_unit_absolute}, + value => $self->{result_values}->{temperature_absolute}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + ); +} + +sub custom_charge_remaining_output { + my ($self, %options) = @_; + + return sprintf('remaining capacity: %s %s', + $self->{result_values}->{charge_remaining_absolute}, + $self->{result_values}->{charge_remaining_unit_absolute} + ); +} + +sub custom_charge_remaining_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + nlabel => 'battery.charge.remaining.' . ($self->{result_values}->{charge_remaining_unit_absolute} eq '%' ? '%' : 'amperehour'), + unit => $self->{result_values}->{charge_remaining_unit_absolute}, + value => $self->{result_values}->{charge_remaining_absolute}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + min => 0, + max => $self->{result_values}->{charge_remaining_unit_absolute} eq '%' ? 100 : undef + ); +} + +sub custom_charge_time_output { + my ($self, %options) = @_; + + return sprintf( + 'remaining time: %s', + centreon::plugins::misc::change_seconds(value => $self->{result_values}->{charge_remaining_time_absolute}) + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'battery', type => 0, cb_prefix_output => 'prefix_battery_output', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{battery} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'temperature', display_ok => 0, set => { + key_values => [ { name => 'temperature' }, { name => 'temperature_unit' } ], + closure_custom_output => $self->can('custom_temperature_output'), + closure_custom_perfdata => $self->can('custom_temperature_perfdata') + } + }, + { label => 'charge-remaining', set => { + key_values => [ { name => 'charge_remaining' }, { name => 'charge_remaining_unit' } ], + closure_custom_output => $self->can('custom_charge_remaining_output'), + closure_custom_perfdata => $self->can('custom_charge_remaining_perfdata') + } + }, + { label => 'charge-remaining-time', nlabel => 'battery.charge.remaining.time.seconds', set => { + key_values => [ { name => 'charge_remaining_time' } ], + closure_custom_output => $self->can('custom_charge_time_output'), + perfdatas => [ + { value => 'charge_remaining_time_absolute', template => '%s', min => 0, unit => 's' }, + ], + } + }, + { label => 'voltage', nlabel => 'battery.voltage.volt', display_ok => 0, set => { + key_values => [ { name => 'voltage' } ], + output_template => 'voltage: %.2f V', + perfdatas => [ + { value => 'voltage_absolute', template => '%.2f', unit => 'V' } + ] + } + }, + { label => 'current', nlabel => 'battery.current.ampere', display_ok => 0, set => { + key_values => [ { name => 'current' } ], + output_template => 'current: %.2f A', + perfdatas => [ + { value => 'current_absolute', template => '%.2f', min => 0, unit => 'A' } + ] + } + }, + ]; +} + +sub prefix_battery_output { + my ($self, %options) = @_; + + return "Battery "; +} + +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 => { + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /minor|warning/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /error|major|critical/i' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => [ + 'warning_status', 'critical_status', 'unknown_status', + ]); +} + +my $map_status = { + 0 => 'error', 1 => 'normal', 2 => 'minorAlarm', 3 => 'majorAlarm', + 4 => 'disabled', 5 => 'disconnected', 6 => 'notPresent', + 7 => 'minorAndMajor', 8 => 'majorLow', 9 => 'minorLow', + 10 => 'majorHigh', 11 => 'minorHigh', 12 => 'event', + 13 => 'valueVolt', 14 => 'valueAmp', 15 => 'valueTemp', + 16 => 'valueUnit', 17 => 'valuePerCent', 18 => 'critical', + 19 => 'warning' +}; +my $map_decimal_setting = { 0 => 'ampere', 1 => 'deciAmpere' }; +my $map_temp_setting = { 0 => 'celsius', 1 => 'fahrenheit' }; +my $map_capacity = { 0 => 'ah', 1 => 'percent' }; + +my $mapping = { + powerSystemCurrentDecimalSetting => { oid => '.1.3.6.1.4.1.12148.10.2.15', map => $map_decimal_setting }, + powerSystemTemperatureScale => { oid => '.1.3.6.1.4.1.12148.10.2.16', map => $map_temp_setting }, + powerSystemCapacityScale => { oid => '.1.3.6.1.4.1.12148.10.2.17', map => $map_capacity }, + batteryStatus => { oid => '.1.3.6.1.4.1.12148.10.10.1', map => $map_status }, + batteryVoltageValue => { oid => '.1.3.6.1.4.1.12148.10.10.5.5' }, + batteryVoltageMajorHighLevel => { oid => '.1.3.6.1.4.1.12148.10.10.5.6' }, + batteryVoltageMinorHighLevel => { oid => '.1.3.6.1.4.1.12148.10.10.5.7' }, # 0.01 for vdc + batteryVoltageMinorLowLevel => { oid => '.1.3.6.1.4.1.12148.10.10.5.8' }, + batteryVoltageMajorLowLevel => { oid => '.1.3.6.1.4.1.12148.10.10.5.9' }, + batteryCurrentsValue => { oid => '.1.3.6.1.4.1.12148.10.10.6.5' }, # A or dA + batteryCurrentsMajorHighLevel => { oid => '.1.3.6.1.4.1.12148.10.10.6.6' }, + batteryCurrentsMinorHighLevel => { oid => '.1.3.6.1.4.1.12148.10.10.6.7' }, + batteryCurrentsMinorLowLevel => { oid => '.1.3.6.1.4.1.12148.10.10.6.8' }, + batteryCurrentsMajorLowLevel => { oid => '.1.3.6.1.4.1.12148.10.10.6.9' }, + batteryTemperaturesValue => { oid => '.1.3.6.1.4.1.12148.10.10.7.5' }, # C or F + batteryTemperaturesMajorHighLevel => { oid => '.1.3.6.1.4.1.12148.10.10.7.6' }, + batteryTemperaturesMinorHighLevel => { oid => '.1.3.6.1.4.1.12148.10.10.7.7' }, + batteryTemperaturesMinorLowLevel => { oid => '.1.3.6.1.4.1.12148.10.10.7.8' }, + batteryTemperaturesMajorLowLevel => { oid => '.1.3.6.1.4.1.12148.10.10.7.9' }, + batteryRemainingCapacityValue => { oid => '.1.3.6.1.4.1.12148.10.10.9.5' }, # ah or % + batteryRemainingCapacityMinorLowLevel => { oid => '.1.3.6.1.4.1.12148.10.10.9.6' }, + batteryRemainingCapacityMajorLowLevel => { oid => '.1.3.6.1.4.1.12148.10.10.9.7' }, +}; + +sub threshold_eltek_configured { + my ($self, %options) = @_; + + if ((!defined($self->{option_results}->{'critical-' . $options{label}}) || $self->{option_results}->{'critical-' . $options{label}} eq '') && + (!defined($self->{option_results}->{'warning-' . $options{label}}) || $self->{option_results}->{'warning-' . $options{label}} eq '')) { + my ($crit, $warn) = ('', ''); + $crit = $options{low_crit} . ':' if (defined($options{low_crit}) && $options{low_crit} ne ''); + $crit .= $options{high_crit} if (defined($options{high_crit}) && $options{high_crit} ne ''); + $warn = $options{low_warn} . ':' if (defined($options{low_warn}) && $options{low_warn} ne ''); + $warn .= $options{high_warn} if (defined($options{high_warn}) && $options{high_warn} ne ''); + $self->{perfdata}->threshold_validate(label => 'critical-' . $options{label}, value => $crit); + $self->{perfdata}->threshold_validate(label => 'warning-' . $options{label}, value => $warn); + } +} + +sub manage_selection { + my ($self, %options) = @_; + + # we can calculate the time remaining if unit is ah (amperehour). + + my $oid_outputControlUnitOutputEntry = '.1.3.6.1.4.1.12148.10.12.2.1'; + 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 $scale_current = 1; + $scale_current = 0.1 if ($result->{powerSystemCurrentDecimalSetting} eq 'deciAmpere'); + $self->{battery} = { + status => $result->{batteryStatus}, + temperature => $result->{batteryTemperaturesValue}, + temperature_unit => $result->{powerSystemTemperatureScale} eq 'celsius' ? 'C' : 'F', + voltage => $result->{batteryVoltageValue} * 0.01, + current => $result->{batteryCurrentsValue} * $scale_current, + charge_remaining => $result->{batteryRemainingCapacityValue}, + charge_remaining_unit => $result->{powerSystemCapacityScale} + }; + if ($result->{powerSystemCapacityScale} eq 'ah' && $result->{batteryCurrentsValue} < 0) { + $self->{battery}->{charge_remaining_time} = + int($result->{batteryRemainingCapacityValue} * 3600 / $result->{batteryCurrentsValue} * $scale_current * -1); + } + + $self->threshold_eltek_configured( + label => 'temperature', + high_crit => $result->{batteryTemperaturesMajorHighLevel}, + low_crit => $result->{batteryTemperaturesMajorLowLevel}, + high_warn => $result->{batteryTemperaturesMinorHighLevel}, + low_warn => $result->{batteryTemperaturesMinorLowLevel} + ); + $self->threshold_eltek_configured( + label => 'battery-voltage-volt', + high_crit => $result->{batteryVoltageMajorHighLevel} * 0.01, + low_crit => $result->{batteryVoltageMajorLowLevel} * 0.01, + high_warn => $result->{batteryVoltageMinorHighLevel} * 0.01, + low_warn => $result->{batteryVoltageMinorLowLevel} * 0.01 + ); + $self->threshold_eltek_configured( + label => 'battery-current-ampere', + high_crit => $result->{batteryCurrentsMajorHighLevel} * $scale_current, + low_crit => $result->{batteryCurrentsMajorLowLevel} * $scale_current, + high_warn => $result->{batteryCurrentsMinorHighLevel} * $scale_current, + low_warn => $result->{batteryCurrentsMinorLowLevel} * $scale_current + ); + $self->threshold_eltek_configured( + label => 'charge-remaining', + low_crit => $result->{batteryRemainingCapacityMajorLowLevel}, + low_warn => $result->{batteryRemainingCapacityMinorLowLevel} + ); +} + +1; + +__END__ + +=head1 MODE + +Check battery. + +=over 8 + +=item B<--unknown-status> + +Set unknown threshold for status. +Can used special variables like: %{status} + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} =~ /minor|warning/i'). +Can used special variables like: %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /error|major|critical/i'). +Can used special variables like: %{status} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'temperature', 'voltage', 'current', +'charge-remaining', 'charge-remaining-time'. + +=back + +=cut diff --git a/hardware/devices/eltek/enexus/snmp/mode/outputs.pm b/hardware/devices/eltek/enexus/snmp/mode/outputs.pm new file mode 100644 index 000000000..2630eb63b --- /dev/null +++ b/hardware/devices/eltek/enexus/snmp/mode/outputs.pm @@ -0,0 +1,198 @@ +# +# 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 hardware::devices::eltek::enexus::snmp::mode::outputs; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use centreon::plugins::misc; + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf('status: %s', + $self->{result_values}->{status} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'cuo', type => 1, cb_prefix_output => 'prefix_cuo_output', message_multiple => 'All outputs for control units are ok', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'outputs-disconnected', nlabel => 'outputs.disconnected.count', display_ok => 0, set => { + key_values => [ { name => 'disconnected' }, { name => 'total_contactors' } ], + output_template => 'current disconnected outputs: %d', + perfdatas => [ + { value => 'disconnected_absolute', template => '%d', min => 0, max => 'total_contactors_absolute' } + ] + } + }, + { label => 'outputs-notenergized', nlabel => 'outputs.notenergized.count', display_ok => 0, set => { + key_values => [ { name => 'notenergized' }, { name => 'total_relay' } ], + output_template => 'current not energized outputs: %d', + perfdatas => [ + { value => 'notenergized_absolute', template => '%d', min => 0, max => 'total_relay_absolute' } + ] + } + } + ]; + + $self->{maps_counters}->{cuo} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'name' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + } + ]; +} + +sub prefix_cuo_output { + my ($self, %options) = @_; + + return "Control unit output '" . $options{instance_value}->{name} . "' "; +} + +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 => { + 'filter-name:s' => { name => 'filter_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /notenergized|disconnected/i' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => [ + 'warning_status', 'critical_status', 'unknown_status', + ]); +} + +my $map_status = { 0 => 'notenergized', 1 => 'energized', 2 => 'disconnected', 3 => 'connected' }; + +my $mapping = { + outputControlUnitOutputStatus => { oid => '.1.3.6.1.4.1.12148.10.12.2.1.2', map => $map_status }, + outputControlUnitOutputDescription => { oid => '.1.3.6.1.4.1.12148.10.12.2.1.3' } +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_outputControlUnitOutputEntry = '.1.3.6.1.4.1.12148.10.12.2.1'; + my $snmp_result = $options{snmp}->get_table( + oid => $oid_outputControlUnitOutputEntry, + start => $mapping->{outputControlUnitOutputStatus}->{oid}, + nothing_quit => 1 + ); + + $self->{global} = { total_relay => 0, total_contactors => 0, energized => 0, notenergized => 0, connected => 0, disconnected => 0 }; + $self->{cuo} = {}; + my $duplicated = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{outputControlUnitOutputStatus}->{oid}\.(.*)$/); + my $instance = $1; + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + my $name = centreon::plugins::misc::trim($result->{outputControlUnitOutputDescription}); + $name = $instance if ($name eq ''); + $name = $instance if (defined($duplicated->{$name})); + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping control unit output '" . $name . "'.", debug => 1); + next; + } + + if (defined($self->{cuo}->{$name})) { + $duplicated->{$name} = 1; + my $instance2 = $self->{cuo}->{$name}->{instance}; + $self->{cuo}->{$instance2} = $self->{cuo}->{$name}; + $self->{cuo}->{$instance2}->{name} = $instance2; + delete $self->{cuo}->{$name}; + $name = $instance; + } + + $self->{cuo}->{$name} = { + instance => $instance, + name => $name, + status => $result->{outputControlUnitOutputStatus} + }; + $self->{global}->{total_relay}++ if ($result->{outputControlUnitOutputStatus} =~ /energized/); + $self->{global}->{total_contactors}++ if ($result->{outputControlUnitOutputStatus} =~ /connected/); + $self->{global}->{$result->{outputControlUnitOutputStatus}}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check outputs for control units. + +=over 8 + +=item B<--filter-name> + +Filter name (can be a regexp). + +=item B<--unknown-status> + +Set unknown threshold for status. +Can used special variables like: %{status}, %{name} + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{status}, %{name} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /notenergized|disconnected/i'). +Can used special variables like: %{status}, %{name} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'current'. + +=back + +=cut diff --git a/hardware/devices/eltek/enexus/snmp/plugin.pm b/hardware/devices/eltek/enexus/snmp/plugin.pm new file mode 100644 index 000000000..297ae1605 --- /dev/null +++ b/hardware/devices/eltek/enexus/snmp/plugin.pm @@ -0,0 +1,50 @@ +# +# 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 hardware::devices::eltek::enexus::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}} = ( + 'alarms' => 'hardware::devices::eltek::enexus::snmp::mode::alarms', + 'battery' => 'hardware::devices::eltek::enexus::snmp::mode::battery', + 'outputs' => 'hardware::devices::eltek::enexus::snmp::mode::outputs' + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Eltek eNexus in SNMP (SmartPack2 V2.x, SmartPack S V2.x and Compack V2.x). + +=cut