From 332bba813dd6fb6fd72a6aa7ee476a4a094a35d9 Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Thu, 3 Oct 2019 17:20:41 +0200 Subject: [PATCH] add abb cms700 plugin --- .../abb/cms700/snmp/mode/mainsmeasurements.pm | 242 ++++++++++++++++ .../cms700/snmp/mode/sensorsmeasurements.pm | 259 ++++++++++++++++++ hardware/devices/abb/cms700/snmp/plugin.pm | 49 ++++ 3 files changed, 550 insertions(+) create mode 100644 hardware/devices/abb/cms700/snmp/mode/mainsmeasurements.pm create mode 100644 hardware/devices/abb/cms700/snmp/mode/sensorsmeasurements.pm create mode 100644 hardware/devices/abb/cms700/snmp/plugin.pm diff --git a/hardware/devices/abb/cms700/snmp/mode/mainsmeasurements.pm b/hardware/devices/abb/cms700/snmp/mode/mainsmeasurements.pm new file mode 100644 index 000000000..27feee0b4 --- /dev/null +++ b/hardware/devices/abb/cms700/snmp/mode/mainsmeasurements.pm @@ -0,0 +1,242 @@ +# +# Copyright 2019 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::abb::cms700::snmp::mode::mainsmeasurements; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub prefix_output { + my ($self, %options) = @_; + + return "Phase '" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'phases', type => 1, cb_prefix_output => 'prefix_output', + message_multiple => 'All mains phases are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{phases} = [ + { label => 'voltage', label => 'phase.voltage.volt', set => { + key_values => [ { name => 'uL' }, { name => 'display' } ], + output_template => 'Voltage: %.2f V', + perfdatas => [ + { value => 'uL_absolute', template => '%.2f', unit => 'V', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'current', label => 'phase.current.ampere', set => { + key_values => [ { name => 'iL' }, { name => 'display' } ], + output_template => 'Current: %.2f A', + perfdatas => [ + { value => 'iL_absolute', template => '%.2f', unit => 'A', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'power-factor', label => 'phase.power.factor.ratio', set => { + key_values => [ { name => 'pfL' }, { name => 'display' } ], + output_template => 'Power Factor: %.2f', + perfdatas => [ + { value => 'pfL_absolute', template => '%.2f', min => 0, max => 1, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'cosphi', label => 'phase.cosphi.ratio', set => { + key_values => [ { name => 'cosP' }, { name => 'display' } ], + output_template => 'Cos Phi: %.2f', + perfdatas => [ + { value => 'cosP_absolute', template => '%.2f', min => 0, max => 1, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'power-apparent', label => 'phase.power.apparent.voltampere', set => { + key_values => [ { name => 'sL' }, { name => 'display' } ], + output_template => 'Apparent Power: %.2f VA', + perfdatas => [ + { value => 'sL_absolute', template => '%.2f', unit => 'VA', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'power-active', label => 'phase.power.active.watt', set => { + key_values => [ { name => 'pL' }, { name => 'display' } ], + output_template => 'Active Power: %.2f W', + perfdatas => [ + { value => 'pL_absolute', template => '%.2f', unit => 'W', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'power-reactive', label => 'phase.power.reactive.voltamperereactive', set => { + key_values => [ { name => 'qL' }, { name => 'display' } ], + output_template => 'Reactive Power: %.2f VAR', + perfdatas => [ + { value => 'qL_absolute', template => '%.2f', unit => 'VAR', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'energy-apparent', label => 'phase.energy.apparent.voltamperehours', set => { + key_values => [ { name => 'shL' }, { name => 'display' } ], + output_template => 'Apparent Energy: %.2f VAh', + perfdatas => [ + { value => 'shL_absolute', template => '%.2f', unit => 'VAh', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'energy-active', label => 'phase.energy.active.watthours', set => { + key_values => [ { name => 'whL' }, { name => 'display' } ], + output_template => 'Active Energy: %.2f Wh', + perfdatas => [ + { value => 'whL_absolute', template => '%.2f', unit => 'Wh', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'energy-reactive', label => 'phase.energy.reactive.voltamperereactivehours', set => { + key_values => [ { name => 'qhL' }, { name => 'display' } ], + output_template => 'Reactive Energy: %.2f VARh', + perfdatas => [ + { value => 'qhL_absolute', template => '%.2f', unit => 'VARh', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'voltage-thd', label => 'phase.voltage.thd.percentage', set => { + key_values => [ { name => 'thdUL' }, { name => 'display' } ], + output_template => 'Voltage THD: %.2f %%', + perfdatas => [ + { value => 'thdUL_absolute', template => '%.2f', unit => '%', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'current-thd', label => 'phase.current.thd.percentage', set => { + key_values => [ { name => 'thdIL' }, { name => 'display' } ], + output_template => 'Current THD: %.2f %%', + perfdatas => [ + { value => 'thdIL_absolute', template => '%.2f', unit => '%', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +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; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); +} + +my $mapping = { + uL => { oid => '.1.3.6.1.4.1.51055.1.24' }, # PHASE VOLTAGE (0.01V) + iL => { oid => '.1.3.6.1.4.1.51055.1.25' }, # LINE CURRENT (0.01A) + pfL => { oid => '.1.3.6.1.4.1.51055.1.26' }, # POWER FACTOR (0.01) + cosP => { oid => '.1.3.6.1.4.1.51055.1.27' }, # COSPHI + sL => { oid => '.1.3.6.1.4.1.51055.1.29' }, # APPARENT POWER (VA) + pL => { oid => '.1.3.6.1.4.1.51055.1.31' }, # ACTIVE POWER (W) + qL => { oid => '.1.3.6.1.4.1.51055.1.33' }, # REACTIVE POWER (VAr) + whL => { oid => '.1.3.6.1.4.1.51055.1.36' }, # ACTIVE ENERGY (0.01Wh) + qhL => { oid => '.1.3.6.1.4.1.51055.1.37' }, # REACTIVE ENERGY (0.01Varh) + thdUL => { oid => '.1.3.6.1.4.1.51055.1.38' }, # VOLTAGE THD (%) + thdIL => { oid => '.1.3.6.1.4.1.51055.1.39' }, # CURRENT THD (%) + shL => { oid => '.1.3.6.1.4.1.51055.1.41' }, # APPARENT ENERGY (0.01Vah) +}; +my $oid_main = '.1.3.6.1.4.1.51055.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_table( + oid => $oid_main, start => $mapping->{uL}->{oid}, end => $mapping->{shL}->{oid}, + ); + + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{uL}->{oid}\.(.*)/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + $self->{phases}->{$instance}->{display} = 'L' . $instance; + $self->{phases}->{$instance}->{uL} = $result->{uL} / 100; + $self->{phases}->{$instance}->{iL} = $result->{iL} / 100; + $self->{phases}->{$instance}->{pfL} = $result->{pfL} / 100; + $self->{phases}->{$instance}->{cosP} = $result->{cosP}; + $self->{phases}->{$instance}->{sL} = $result->{sL}; + $self->{phases}->{$instance}->{pL} = $result->{pL}; + $self->{phases}->{$instance}->{qL} = $result->{qL}; + $self->{phases}->{$instance}->{shL} = $result->{shL} / 100; + $self->{phases}->{$instance}->{whL} = $result->{whL} / 100; + $self->{phases}->{$instance}->{qhL} = $result->{qhL} / 100; + $self->{phases}->{$instance}->{thdUL} = $result->{thdUL} / 100; + $self->{phases}->{$instance}->{thdIL} = $result->{thdIL} / 100; + } + + if (scalar(keys %{$self->{phases}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No phases found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check mains phases measurements. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^power|energy$' + +=item B<--warning-*> B<--critical-*> + +Threshold warning. +Can be: 'voltage', 'current', 'power-factor', 'cosphi', 'power-apparent', +'power-active', 'power-reactive', 'energy-apparent', 'energy-active', +'energy-reactive', 'voltage-thd', 'current-thd'. + +=back + +=cut diff --git a/hardware/devices/abb/cms700/snmp/mode/sensorsmeasurements.pm b/hardware/devices/abb/cms700/snmp/mode/sensorsmeasurements.pm new file mode 100644 index 000000000..d3f5a2486 --- /dev/null +++ b/hardware/devices/abb/cms700/snmp/mode/sensorsmeasurements.pm @@ -0,0 +1,259 @@ +# +# Copyright 2019 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::abb::cms700::snmp::mode::sensorsmeasurements; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub prefix_output { + my ($self, %options) = @_; + + my $output = sprintf("Sensor '%s' [Group: %s] [Phase: %s] ", + $options{instance_value}->{display}, + $options{instance_value}->{Groupsens}, + $options{instance_value}->{Phasesens} + ); + + return $output; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'sensors', type => 1, cb_prefix_output => 'prefix_output', + message_multiple => 'All sensors are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{sensors} = [ + { label => 'current-mixte', label => 'sensor.current.mixte.ampere', set => { + key_values => [ { name => 'TRMSsens' }, { name => 'display' } ], + output_template => 'Mixte Current: %.2f A', + perfdatas => [ + { value => 'TRMSsens_absolute', template => '%.2f', unit => 'A', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'current-alternative', label => 'sensor.current.alternative.ampere', set => { + key_values => [ { name => 'ACsens' }, { name => 'display' } ], + output_template => 'Alternative Current: %.2f A', + perfdatas => [ + { value => 'ACsens_absolute', template => '%.2f', unit => 'A', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'current-direct', label => 'sensor.current.direct.ampere', set => { + key_values => [ { name => 'DCsens' }, { name => 'display' } ], + output_template => 'Direct Current: %.2f A', + perfdatas => [ + { value => 'DCsens_absolute', template => '%.2f', unit => 'A', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'power-active', label => 'sensor.power.active.watt', set => { + key_values => [ { name => 'Psens' }, { name => 'display' } ], + output_template => 'Active Power: %.2f', + perfdatas => [ + { value => 'Psens_absolute', template => '%.2f', unit => 'W', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'energy-active', label => 'sensor.energy.active.watthours', set => { + key_values => [ { name => 'Whsens' }, { name => 'display' } ], + output_template => 'Active Energy: %.2f', + perfdatas => [ + { value => 'Whsens_absolute', template => '%.2f', unit => 'Wh', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'power-factor', label => 'sensor.power.factor.ratio', set => { + key_values => [ { name => 'PowerFactorsens' }, { name => 'display' } ], + output_template => 'Power Factor: %.2f', + perfdatas => [ + { value => 'PowerFactorsens_absolute', template => '%.2f', min => 0, max => 1, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +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' }, + "filter-group:s" => { name => 'filter_group' }, + "filter-phase:s" => { name => 'filter_phase' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); +} + +my $oid_GroupName = '.1.3.6.1.4.1.51055.1.20'; +my $oid_BranchNamesens = '.1.3.6.1.4.1.51055.1.19'; + +my $mapping = { + TRMSsens => { oid => '.1.3.6.1.4.1.51055.1.1' }, + ACsens => { oid => '.1.3.6.1.4.1.51055.1.2' }, + DCsens => { oid => '.1.3.6.1.4.1.51055.1.3' }, + POLsens => { oid => '.1.3.6.1.4.1.51055.1.14' }, + Psens => { oid => '.1.3.6.1.4.1.51055.1.15' }, + Whsens => { oid => '.1.3.6.1.4.1.51055.1.16' }, + Phasesens => { oid => '.1.3.6.1.4.1.51055.1.21' }, + Groupsens => { oid => '.1.3.6.1.4.1.51055.1.22' }, + PowerFactorsens => { oid => '.1.3.6.1.4.1.51055.1.23' }, +}; +my $oid_main = '.1.3.6.1.4.1.51055.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my %groups; + my $snmp_result = $options{snmp}->get_table(oid => $oid_GroupName); + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$oid_GroupName\.(.*)/); + next if ($snmp_result->{$oid} eq ''); + $groups{$1} = $snmp_result->{$oid}; + } + + my %sensors; + $snmp_result = $options{snmp}->get_table(oid => $oid_BranchNamesens); + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$oid_BranchNamesens\.(.*)/); + next if ($snmp_result->{$oid} eq ''); + my $instance = $1; + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $snmp_result->{$oid} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping sensor '" . $snmp_result->{$oid} . "'.", debug => 1); + next; + } + + $sensors{$instance} = $snmp_result->{$oid}; + } + + $options{snmp}->load( + oids => [ + $mapping->{TRMSsens}->{oid}, + $mapping->{ACsens}->{oid}, + $mapping->{DCsens}->{oid}, + $mapping->{POLsens}->{oid}, + $mapping->{Psens}->{oid}, + $mapping->{Whsens}->{oid}, + $mapping->{Phasesens}->{oid}, + $mapping->{Groupsens}->{oid}, + $mapping->{PowerFactorsens}->{oid}, + ], + instances => [ keys %sensors ], + instance_regexp => '^(.*)$' + ); + my $snmp_result_data = $options{snmp}->get_leef(nothing_quit => 1); + + foreach my $oid (keys %$snmp_result_data) { + next if ($oid !~ /^$mapping->{TRMSsens}->{oid}\.(.*)/); + my $instance = $1; + my $result = $options{snmp}->map_instance( + mapping => $mapping, + results => $snmp_result_data, + instance => $instance + ); + + if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '' && + (!defined($groups{$result->{Groupsens}}) || ($groups{$result->{Groupsens}} !~ /$self->{option_results}->{filter_group}/))) { + $self->{output}->output_add(long_msg => "skipping sensor '" . $sensors{$instance} . "'.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_phase}) && $self->{option_results}->{filter_phase} ne '' && + $result->{Phasesens} !~ /$self->{option_results}->{filter_phase}/) { + $self->{output}->output_add(long_msg => "skipping sensor '" . $sensors{$instance} . "'.", debug => 1); + next; + } + + $self->{sensors}->{$instance}->{display} = $sensors{$instance}; + $self->{sensors}->{$instance}->{TRMSsens} = $result->{TRMSsens} / 100; + $self->{sensors}->{$instance}->{ACsens} = $result->{ACsens} / 100; + $self->{sensors}->{$instance}->{DCsens} = $result->{DCsens} / 100; + $self->{sensors}->{$instance}->{POLsens} = $result->{POLsens}; + $self->{sensors}->{$instance}->{Psens} = $result->{Psens}; + $self->{sensors}->{$instance}->{Whsens} = $result->{Whsens} / 10; + $self->{sensors}->{$instance}->{PowerFactorsens} = $result->{PowerFactorsens} / 100; + + $self->{sensors}->{$instance}->{Phasesens} = $result->{Phasesens}; + $self->{sensors}->{$instance}->{Groupsens} = (defined($groups{$result->{Groupsens}})) ? $groups{$result->{Groupsens}} : '-'; + } + + if (scalar(keys %{$self->{sensors}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No sensors found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check sensors measurements. + +=over 8 + +=item B<--filter-name> + +Filter by sensor name (can be a regexp). + +=item B<--filter-group> + +Filter by sensor group name (can be a regexp). + +=item B<--filter-phase> + +Filter by sensor phase (can be a regexp). + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^current$' + +=item B<--warning-*> B<--critical-*> + +Threshold warning. +Can be: 'current-mixte', 'current-alternative', 'current-direct', +'power-active', 'energy-active', 'power-factor'. + +=back + +=cut diff --git a/hardware/devices/abb/cms700/snmp/plugin.pm b/hardware/devices/abb/cms700/snmp/plugin.pm new file mode 100644 index 000000000..60c1b53fe --- /dev/null +++ b/hardware/devices/abb/cms700/snmp/plugin.pm @@ -0,0 +1,49 @@ +# +# Copyright 2019 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::abb::cms700::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}} = ( + 'mains-measurements' => 'hardware::devices::abb::cms700::snmp::mode::mainsmeasurements', + 'sensors-measurements' => 'hardware::devices::abb::cms700::snmp::mode::sensorsmeasurements', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check ABB CMS-700 measurements in SNMP. + +=cut