| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package hardware::devices::abb::cms700::snmp::mode::sensorsmeasurements; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub prefix_output { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
my $output = sprintf("Sensor '%s' [Group: %s] [Phase: %s] ", |
| 32 |
$options{instance_value}->{display}, |
| 33 |
$options{instance_value}->{Groupsens}, |
| 34 |
$options{instance_value}->{Phasesens} |
| 35 |
); |
| 36 |
|
| 37 |
return $output; |
| 38 |
} |
| 39 |
|
| 40 |
sub set_counters { |
| 41 |
my ($self, %options) = @_; |
| 42 |
|
| 43 |
$self->{maps_counters_type} = [ |
| 44 |
{ name => 'sensors', type => 1, cb_prefix_output => 'prefix_output', |
| 45 |
message_multiple => 'All sensors are ok', skipped_code => { -10 => 1 } }, |
| 46 |
]; |
| 47 |
|
| 48 |
$self->{maps_counters}->{sensors} = [ |
| 49 |
{ label => 'current-mixte', nlabel => 'sensor.current.mixte.ampere', set => { |
| 50 |
key_values => [ { name => 'TRMSsens' }, { name => 'display' } ], |
| 51 |
output_template => 'Mixte Current: %.2f A', |
| 52 |
perfdatas => [ |
| 53 |
{ value => 'TRMSsens', template => '%.2f', unit => 'A', min => 0, |
| 54 |
label_extra_instance => 1, instance_use => 'display' }, |
| 55 |
], |
| 56 |
} |
| 57 |
}, |
| 58 |
{ label => 'current-alternative', nlabel => 'sensor.current.alternative.ampere', set => { |
| 59 |
key_values => [ { name => 'ACsens' }, { name => 'display' } ], |
| 60 |
output_template => 'Alternative Current: %.2f A', |
| 61 |
perfdatas => [ |
| 62 |
{ value => 'ACsens', template => '%.2f', unit => 'A', min => 0, |
| 63 |
label_extra_instance => 1, instance_use => 'display' }, |
| 64 |
], |
| 65 |
} |
| 66 |
}, |
| 67 |
{ label => 'current-direct', nlabel => 'sensor.current.direct.ampere', set => { |
| 68 |
key_values => [ { name => 'DCsens' }, { name => 'display' } ], |
| 69 |
output_template => 'Direct Current: %.2f A', |
| 70 |
perfdatas => [ |
| 71 |
{ value => 'DCsens', template => '%.2f', unit => 'A', min => 0, |
| 72 |
label_extra_instance => 1, instance_use => 'display' }, |
| 73 |
], |
| 74 |
} |
| 75 |
}, |
| 76 |
{ label => 'power-active', nlabel => 'sensor.power.active.watt', set => { |
| 77 |
key_values => [ { name => 'Psens' }, { name => 'display' } ], |
| 78 |
output_template => 'Active Power: %.2f W', |
| 79 |
perfdatas => [ |
| 80 |
{ value => 'Psens', template => '%.2f', unit => 'W', min => 0, |
| 81 |
label_extra_instance => 1, instance_use => 'display' }, |
| 82 |
], |
| 83 |
} |
| 84 |
}, |
| 85 |
{ label => 'energy-active', nlabel => 'sensor.energy.active.watthours', set => { |
| 86 |
key_values => [ { name => 'Whsens' }, { name => 'display' } ], |
| 87 |
output_template => 'Active Energy: %.2f Wh', |
| 88 |
perfdatas => [ |
| 89 |
{ value => 'Whsens', template => '%.2f', unit => 'Wh', min => 0, |
| 90 |
label_extra_instance => 1, instance_use => 'display' }, |
| 91 |
], |
| 92 |
} |
| 93 |
}, |
| 94 |
{ label => 'power-factor', nlabel => 'sensor.power.factor.ratio', set => { |
| 95 |
key_values => [ { name => 'PowerFactorsens' }, { name => 'display' } ], |
| 96 |
output_template => 'Power Factor: %.2f', |
| 97 |
perfdatas => [ |
| 98 |
{ value => 'PowerFactorsens', template => '%.2f', min => 0, max => 1, |
| 99 |
label_extra_instance => 1, instance_use => 'display' }, |
| 100 |
], |
| 101 |
} |
| 102 |
}, |
| 103 |
]; |
| 104 |
} |
| 105 |
|
| 106 |
sub new { |
| 107 |
my ($class, %options) = @_; |
| 108 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 109 |
bless $self, $class; |
| 110 |
|
| 111 |
$options{options}->add_options(arguments => { |
| 112 |
"filter-name:s" => { name => 'filter_name' }, |
| 113 |
"filter-group:s" => { name => 'filter_group' }, |
| 114 |
"filter-phase:s" => { name => 'filter_phase' }, |
| 115 |
}); |
| 116 |
|
| 117 |
return $self; |
| 118 |
} |
| 119 |
|
| 120 |
sub check_options { |
| 121 |
my ($self, %options) = @_; |
| 122 |
$self->SUPER::check_options(%options); |
| 123 |
} |
| 124 |
|
| 125 |
my $oid_GroupName = '.1.3.6.1.4.1.51055.1.20'; |
| 126 |
my $oid_BranchNamesens = '.1.3.6.1.4.1.51055.1.19'; |
| 127 |
|
| 128 |
my $mapping = { |
| 129 |
TRMSsens => { oid => '.1.3.6.1.4.1.51055.1.1' }, |
| 130 |
ACsens => { oid => '.1.3.6.1.4.1.51055.1.2' }, |
| 131 |
DCsens => { oid => '.1.3.6.1.4.1.51055.1.3' }, |
| 132 |
POLsens => { oid => '.1.3.6.1.4.1.51055.1.14' }, |
| 133 |
Psens => { oid => '.1.3.6.1.4.1.51055.1.15' }, |
| 134 |
Whsens => { oid => '.1.3.6.1.4.1.51055.1.16' }, |
| 135 |
Phasesens => { oid => '.1.3.6.1.4.1.51055.1.21' }, |
| 136 |
Groupsens => { oid => '.1.3.6.1.4.1.51055.1.22' }, |
| 137 |
PowerFactorsens => { oid => '.1.3.6.1.4.1.51055.1.23' }, |
| 138 |
}; |
| 139 |
|
| 140 |
sub manage_selection { |
| 141 |
my ($self, %options) = @_; |
| 142 |
|
| 143 |
my %groups; |
| 144 |
my $snmp_result = $options{snmp}->get_table(oid => $oid_GroupName); |
| 145 |
foreach my $oid (keys %$snmp_result) { |
| 146 |
next if ($oid !~ /^$oid_GroupName\.(.*)/); |
| 147 |
next if ($snmp_result->{$oid} eq ''); |
| 148 |
$groups{$1} = $snmp_result->{$oid}; |
| 149 |
} |
| 150 |
|
| 151 |
my %sensors; |
| 152 |
$snmp_result = $options{snmp}->get_table(oid => $oid_BranchNamesens); |
| 153 |
foreach my $oid (keys %$snmp_result) { |
| 154 |
next if ($oid !~ /^$oid_BranchNamesens\.(.*)/); |
| 155 |
next if ($snmp_result->{$oid} eq ''); |
| 156 |
my $instance = $1; |
| 157 |
|
| 158 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 159 |
$snmp_result->{$oid} !~ /$self->{option_results}->{filter_name}/) { |
| 160 |
$self->{output}->output_add(long_msg => "skipping sensor '" . $snmp_result->{$oid} . "'.", debug => 1); |
| 161 |
next; |
| 162 |
} |
| 163 |
|
| 164 |
$sensors{$instance} = $snmp_result->{$oid}; |
| 165 |
} |
| 166 |
|
| 167 |
$options{snmp}->load( |
| 168 |
oids => [ |
| 169 |
$mapping->{TRMSsens}->{oid}, |
| 170 |
$mapping->{ACsens}->{oid}, |
| 171 |
$mapping->{DCsens}->{oid}, |
| 172 |
$mapping->{POLsens}->{oid}, |
| 173 |
$mapping->{Psens}->{oid}, |
| 174 |
$mapping->{Whsens}->{oid}, |
| 175 |
$mapping->{Phasesens}->{oid}, |
| 176 |
$mapping->{Groupsens}->{oid}, |
| 177 |
$mapping->{PowerFactorsens}->{oid}, |
| 178 |
], |
| 179 |
instances => [ keys %sensors ], |
| 180 |
instance_regexp => '^(.*)$' |
| 181 |
); |
| 182 |
my $snmp_result_data = $options{snmp}->get_leef(nothing_quit => 1); |
| 183 |
|
| 184 |
$self->{sensors} = {}; |
| 185 |
foreach my $oid (keys %$snmp_result_data) { |
| 186 |
next if ($oid !~ /^$mapping->{TRMSsens}->{oid}\.(.*)/); |
| 187 |
my $instance = $1; |
| 188 |
my $result = $options{snmp}->map_instance( |
| 189 |
mapping => $mapping, |
| 190 |
results => $snmp_result_data, |
| 191 |
instance => $instance |
| 192 |
); |
| 193 |
|
| 194 |
if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '' && |
| 195 |
(!defined($groups{$result->{Groupsens}}) || |
| 196 |
($groups{$result->{Groupsens}} !~ /$self->{option_results}->{filter_group}/))) { |
| 197 |
$self->{output}->output_add(long_msg => "skipping sensor '" . $sensors{$instance} . "'.", debug => 1); |
| 198 |
next; |
| 199 |
} |
| 200 |
if (defined($self->{option_results}->{filter_phase}) && $self->{option_results}->{filter_phase} ne '' && |
| 201 |
$result->{Phasesens} !~ /$self->{option_results}->{filter_phase}/) { |
| 202 |
$self->{output}->output_add(long_msg => "skipping sensor '" . $sensors{$instance} . "'.", debug => 1); |
| 203 |
next; |
| 204 |
} |
| 205 |
|
| 206 |
$self->{sensors}->{$instance}->{display} = $sensors{$instance}; |
| 207 |
$self->{sensors}->{$instance}->{TRMSsens} = $result->{TRMSsens} / 100; |
| 208 |
$self->{sensors}->{$instance}->{ACsens} = $result->{ACsens} / 100; |
| 209 |
$self->{sensors}->{$instance}->{DCsens} = $result->{DCsens} / 100; |
| 210 |
$self->{sensors}->{$instance}->{POLsens} = $result->{POLsens}; |
| 211 |
$self->{sensors}->{$instance}->{Psens} = $result->{Psens}; |
| 212 |
$self->{sensors}->{$instance}->{Whsens} = $result->{Whsens} / 10; |
| 213 |
$self->{sensors}->{$instance}->{PowerFactorsens} = $result->{PowerFactorsens} / 100; |
| 214 |
|
| 215 |
$self->{sensors}->{$instance}->{Phasesens} = $result->{Phasesens}; |
| 216 |
$self->{sensors}->{$instance}->{Groupsens} = |
| 217 |
(defined($groups{$result->{Groupsens}})) ? $groups{$result->{Groupsens}} : '-'; |
| 218 |
} |
| 219 |
|
| 220 |
if (scalar(keys %{$self->{sensors}}) <= 0) { |
| 221 |
$self->{output}->add_option_msg(short_msg => "No sensors found."); |
| 222 |
$self->{output}->option_exit(); |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
1; |
| 227 |
|
| 228 |
__END__ |
| 229 |
|
| 230 |
=head1 MODE |
| 231 |
|
| 232 |
Check sensors measurements. |
| 233 |
|
| 234 |
=over 8 |
| 235 |
|
| 236 |
=item B<--filter-name> |
| 237 |
|
| 238 |
Filter by sensor name (can be a regexp). |
| 239 |
|
| 240 |
=item B<--filter-group> |
| 241 |
|
| 242 |
Filter by sensor group name (can be a regexp). |
| 243 |
|
| 244 |
=item B<--filter-phase> |
| 245 |
|
| 246 |
Filter by sensor phase (can be a regexp). |
| 247 |
|
| 248 |
=item B<--filter-counters> |
| 249 |
|
| 250 |
Only display some counters (regexp can be used). |
| 251 |
Example: --filter-counters='^current$' |
| 252 |
|
| 253 |
=item B<--warning-*> B<--critical-*> |
| 254 |
|
| 255 |
Warning threshold. |
| 256 |
Can be: 'current-mixte', 'current-alternative', 'current-direct', |
| 257 |
'power-active', 'energy-active', 'power-factor'. |
| 258 |
|
| 259 |
=back |
| 260 |
|
| 261 |
=cut |