| 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::mainsmeasurements; |
| 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 |
return "Phase '" . $options{instance_value}->{display} . "' "; |
| 32 |
} |
| 33 |
|
| 34 |
sub set_counters { |
| 35 |
my ($self, %options) = @_; |
| 36 |
|
| 37 |
$self->{maps_counters_type} = [ |
| 38 |
{ name => 'global', type => 0, cb_init => 'skip_global' }, |
| 39 |
{ name => 'phases', type => 1, cb_prefix_output => 'prefix_output', |
| 40 |
message_multiple => 'All mains phases are ok', skipped_code => { -10 => 1 } }, |
| 41 |
]; |
| 42 |
|
| 43 |
$self->{maps_counters}->{global} = [ |
| 44 |
{ label => 'power-active-total', nlabel => 'power.active.watt', set => { |
| 45 |
key_values => [ { name => 'p3' } ], |
| 46 |
output_template => 'Active Power: %.2f W', |
| 47 |
perfdatas => [ |
| 48 |
{ value => 'p3', template => '%.2f', unit => 'W', min => 0 }, |
| 49 |
], |
| 50 |
} |
| 51 |
}, |
| 52 |
{ label => 'power-reactive-total', nlabel => 'power.reactive.voltamperereactive', set => { |
| 53 |
key_values => [ { name => 'q3' } ], |
| 54 |
output_template => 'Reactive Power: %.2f VAR', |
| 55 |
perfdatas => [ |
| 56 |
{ value => 'q3', template => '%.2f', unit => 'VAR', min => 0 }, |
| 57 |
], |
| 58 |
} |
| 59 |
}, |
| 60 |
{ label => 'power-apparent-total', nlabel => 'power.apparent.voltampere', set => { |
| 61 |
key_values => [ { name => 's3' } ], |
| 62 |
output_template => 'Apparent Power: %.2f VA', |
| 63 |
perfdatas => [ |
| 64 |
{ value => 's3', template => '%.2f', unit => 'VA', min => 0 }, |
| 65 |
], |
| 66 |
} |
| 67 |
}, |
| 68 |
]; |
| 69 |
|
| 70 |
$self->{maps_counters}->{phases} = [ |
| 71 |
{ label => 'voltage', nlabel => 'phase.voltage.volt', set => { |
| 72 |
key_values => [ { name => 'uL' }, { name => 'display' } ], |
| 73 |
output_template => 'Voltage: %.2f V', |
| 74 |
perfdatas => [ |
| 75 |
{ value => 'uL', template => '%.2f', unit => 'V', min => 0, |
| 76 |
label_extra_instance => 1, instance_use => 'display' }, |
| 77 |
], |
| 78 |
} |
| 79 |
}, |
| 80 |
{ label => 'current', nlabel => 'phase.current.ampere', set => { |
| 81 |
key_values => [ { name => 'iL' }, { name => 'display' } ], |
| 82 |
output_template => 'Current: %.2f A', |
| 83 |
perfdatas => [ |
| 84 |
{ value => 'iL', template => '%.2f', unit => 'A', min => 0, |
| 85 |
label_extra_instance => 1, instance_use => 'display' }, |
| 86 |
], |
| 87 |
} |
| 88 |
}, |
| 89 |
{ label => 'power-factor', nlabel => 'phase.power.factor.ratio', set => { |
| 90 |
key_values => [ { name => 'pfL' }, { name => 'display' } ], |
| 91 |
output_template => 'Power Factor: %.2f', |
| 92 |
perfdatas => [ |
| 93 |
{ value => 'pfL', template => '%.2f', min => 0, max => 1, |
| 94 |
label_extra_instance => 1, instance_use => 'display' }, |
| 95 |
], |
| 96 |
} |
| 97 |
}, |
| 98 |
{ label => 'cosphi', nlabel => 'phase.cosphi.ratio', set => { |
| 99 |
key_values => [ { name => 'cosP' }, { name => 'display' } ], |
| 100 |
output_template => 'Cos Phi: %.2f', |
| 101 |
perfdatas => [ |
| 102 |
{ value => 'cosP', template => '%.2f', min => 0, max => 1, |
| 103 |
label_extra_instance => 1, instance_use => 'display' }, |
| 104 |
], |
| 105 |
} |
| 106 |
}, |
| 107 |
{ label => 'power-active', nlabel => 'phase.power.active.watt', set => { |
| 108 |
key_values => [ { name => 'pL' }, { name => 'display' } ], |
| 109 |
output_template => 'Active Power: %.2f W', |
| 110 |
perfdatas => [ |
| 111 |
{ value => 'pL', template => '%.2f', unit => 'W', min => 0, |
| 112 |
label_extra_instance => 1, instance_use => 'display' }, |
| 113 |
], |
| 114 |
} |
| 115 |
}, |
| 116 |
{ label => 'power-reactive', nlabel => 'phase.power.reactive.voltamperereactive', set => { |
| 117 |
key_values => [ { name => 'qL' }, { name => 'display' } ], |
| 118 |
output_template => 'Reactive Power: %.2f VAR', |
| 119 |
perfdatas => [ |
| 120 |
{ value => 'qL', template => '%.2f', unit => 'VAR', min => 0, |
| 121 |
label_extra_instance => 1, instance_use => 'display' }, |
| 122 |
], |
| 123 |
} |
| 124 |
}, |
| 125 |
{ label => 'power-apparent', nlabel => 'phase.power.apparent.voltampere', set => { |
| 126 |
key_values => [ { name => 'sL' }, { name => 'display' } ], |
| 127 |
output_template => 'Apparent Power: %.2f VA', |
| 128 |
perfdatas => [ |
| 129 |
{ value => 'sL', template => '%.2f', unit => 'VA', min => 0, |
| 130 |
label_extra_instance => 1, instance_use => 'display' }, |
| 131 |
], |
| 132 |
} |
| 133 |
}, |
| 134 |
{ label => 'energy-active', nlabel => 'phase.energy.active.watthours', set => { |
| 135 |
key_values => [ { name => 'whL' }, { name => 'display' } ], |
| 136 |
output_template => 'Active Energy: %.2f Wh', |
| 137 |
perfdatas => [ |
| 138 |
{ value => 'whL', template => '%.2f', unit => 'Wh', min => 0, |
| 139 |
label_extra_instance => 1, instance_use => 'display' }, |
| 140 |
], |
| 141 |
} |
| 142 |
}, |
| 143 |
{ label => 'energy-reactive', nlabel => 'phase.energy.reactive.voltamperereactivehours', set => { |
| 144 |
key_values => [ { name => 'qhL' }, { name => 'display' } ], |
| 145 |
output_template => 'Reactive Energy: %.2f VARh', |
| 146 |
perfdatas => [ |
| 147 |
{ value => 'qhL', template => '%.2f', unit => 'VARh', min => 0, |
| 148 |
label_extra_instance => 1, instance_use => 'display' }, |
| 149 |
], |
| 150 |
} |
| 151 |
}, |
| 152 |
{ label => 'energy-apparent', nlabel => 'phase.energy.apparent.voltamperehours', set => { |
| 153 |
key_values => [ { name => 'shL' }, { name => 'display' } ], |
| 154 |
output_template => 'Apparent Energy: %.2f VAh', |
| 155 |
perfdatas => [ |
| 156 |
{ value => 'shL', template => '%.2f', unit => 'VAh', min => 0, |
| 157 |
label_extra_instance => 1, instance_use => 'display' }, |
| 158 |
], |
| 159 |
} |
| 160 |
}, |
| 161 |
{ label => 'voltage-thd', nlabel => 'phase.voltage.thd.percentage', set => { |
| 162 |
key_values => [ { name => 'thdUL' }, { name => 'display' } ], |
| 163 |
output_template => 'Voltage THD: %.2f %%', |
| 164 |
perfdatas => [ |
| 165 |
{ value => 'thdUL', template => '%.2f', unit => '%', min => 0, |
| 166 |
label_extra_instance => 1, instance_use => 'display' }, |
| 167 |
], |
| 168 |
} |
| 169 |
}, |
| 170 |
{ label => 'current-thd', nlabel => 'phase.current.thd.percentage', set => { |
| 171 |
key_values => [ { name => 'thdIL' }, { name => 'display' } ], |
| 172 |
output_template => 'Current THD: %.2f %%', |
| 173 |
perfdatas => [ |
| 174 |
{ value => 'thdIL', template => '%.2f', unit => '%', min => 0, |
| 175 |
label_extra_instance => 1, instance_use => 'display' }, |
| 176 |
], |
| 177 |
} |
| 178 |
}, |
| 179 |
]; |
| 180 |
} |
| 181 |
|
| 182 |
sub skip_global { |
| 183 |
my ($self, %options) = @_; |
| 184 |
|
| 185 |
scalar(keys %{$self->{phases}}) > 1 ? return(0) : return(1); |
| 186 |
} |
| 187 |
|
| 188 |
sub new { |
| 189 |
my ($class, %options) = @_; |
| 190 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 191 |
bless $self, $class; |
| 192 |
|
| 193 |
$options{options}->add_options(arguments => { |
| 194 |
"filter-phase:s" => { name => 'filter_phase' }, |
| 195 |
}); |
| 196 |
|
| 197 |
return $self; |
| 198 |
} |
| 199 |
|
| 200 |
sub check_options { |
| 201 |
my ($self, %options) = @_; |
| 202 |
$self->SUPER::check_options(%options); |
| 203 |
} |
| 204 |
|
| 205 |
my $mapping = { |
| 206 |
uL => { oid => '.1.3.6.1.4.1.51055.1.24' }, # PHASE VOLTAGE (0.01V) |
| 207 |
iL => { oid => '.1.3.6.1.4.1.51055.1.25' }, # LINE CURRENT (0.01A) |
| 208 |
pfL => { oid => '.1.3.6.1.4.1.51055.1.26' }, # POWER FACTOR (0.01) |
| 209 |
cosP => { oid => '.1.3.6.1.4.1.51055.1.27' }, # COSPHI |
| 210 |
sL => { oid => '.1.3.6.1.4.1.51055.1.29' }, # APPARENT POWER (VA) |
| 211 |
pL => { oid => '.1.3.6.1.4.1.51055.1.31' }, # ACTIVE POWER (W) |
| 212 |
qL => { oid => '.1.3.6.1.4.1.51055.1.33' }, # REACTIVE POWER (VAr) |
| 213 |
whL => { oid => '.1.3.6.1.4.1.51055.1.36' }, # ACTIVE ENERGY (0.01Wh) |
| 214 |
qhL => { oid => '.1.3.6.1.4.1.51055.1.37' }, # REACTIVE ENERGY (0.01Varh) |
| 215 |
thdUL => { oid => '.1.3.6.1.4.1.51055.1.38' }, # VOLTAGE THD (%) |
| 216 |
thdIL => { oid => '.1.3.6.1.4.1.51055.1.39' }, # CURRENT THD (%) |
| 217 |
shL => { oid => '.1.3.6.1.4.1.51055.1.41' }, # APPARENT ENERGY (0.01Vah) |
| 218 |
}; |
| 219 |
my $oid_main = '.1.3.6.1.4.1.51055.1'; |
| 220 |
|
| 221 |
sub manage_selection { |
| 222 |
my ($self, %options) = @_; |
| 223 |
|
| 224 |
my $snmp_result = $options{snmp}->get_table( |
| 225 |
oid => $oid_main, start => $mapping->{uL}->{oid}, end => $mapping->{shL}->{oid}, |
| 226 |
); |
| 227 |
|
| 228 |
$self->{global} = { s3 => 0, p3 => 0, q3 => 0 }; |
| 229 |
$self->{phases} = {}; |
| 230 |
foreach my $oid (keys %$snmp_result) { |
| 231 |
next if ($oid !~ /^$mapping->{uL}->{oid}\.(.*)/); |
| 232 |
my $instance = $1; |
| 233 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 234 |
|
| 235 |
if (defined($self->{option_results}->{filter_phase}) && $self->{option_results}->{filter_phase} ne '' && |
| 236 |
$instance !~ /$self->{option_results}->{filter_phase}/) { |
| 237 |
$self->{output}->output_add(long_msg => "skipping sensor '" . $snmp_result->{$oid} . "'.", debug => 1); |
| 238 |
next; |
| 239 |
} |
| 240 |
|
| 241 |
$self->{phases}->{$instance}->{display} = 'L' . $instance; |
| 242 |
$self->{phases}->{$instance}->{uL} = $result->{uL} / 100; |
| 243 |
$self->{phases}->{$instance}->{iL} = $result->{iL} / 100; |
| 244 |
$self->{phases}->{$instance}->{pfL} = $result->{pfL} / 100; |
| 245 |
$self->{phases}->{$instance}->{cosP} = $result->{cosP}; |
| 246 |
$self->{phases}->{$instance}->{sL} = $result->{sL}; |
| 247 |
$self->{phases}->{$instance}->{pL} = $result->{pL}; |
| 248 |
$self->{phases}->{$instance}->{qL} = $result->{qL}; |
| 249 |
$self->{phases}->{$instance}->{shL} = $result->{shL} / 100; |
| 250 |
$self->{phases}->{$instance}->{whL} = $result->{whL} / 100; |
| 251 |
$self->{phases}->{$instance}->{qhL} = $result->{qhL} / 100; |
| 252 |
$self->{phases}->{$instance}->{thdUL} = $result->{thdUL} / 100; |
| 253 |
$self->{phases}->{$instance}->{thdIL} = $result->{thdIL} / 100; |
| 254 |
|
| 255 |
$self->{global}->{s3} += $result->{sL}; |
| 256 |
$self->{global}->{p3} += $result->{pL}; |
| 257 |
$self->{global}->{q3} += $result->{qL}; |
| 258 |
} |
| 259 |
|
| 260 |
if (scalar(keys %{$self->{phases}}) <= 0) { |
| 261 |
$self->{output}->add_option_msg(short_msg => "No phases found."); |
| 262 |
$self->{output}->option_exit(); |
| 263 |
} |
| 264 |
} |
| 265 |
|
| 266 |
1; |
| 267 |
|
| 268 |
__END__ |
| 269 |
|
| 270 |
=head1 MODE |
| 271 |
|
| 272 |
Check mains phases measurements. |
| 273 |
|
| 274 |
=over 8 |
| 275 |
|
| 276 |
=item B<--filter-phase> |
| 277 |
|
| 278 |
Filter by phase (can be a regexp). |
| 279 |
|
| 280 |
=item B<--filter-counters> |
| 281 |
|
| 282 |
Only display some counters (regexp can be used). |
| 283 |
Example: --filter-counters='^power|energy$' |
| 284 |
|
| 285 |
=item B<--warning-*> B<--critical-*> |
| 286 |
|
| 287 |
Warning threshold. |
| 288 |
Can be: 'power-apparent-total', 'power-active-total', 'power-reactive-total', |
| 289 |
'voltage', 'current', 'power-factor', 'cosphi', 'power-apparent', |
| 290 |
'power-active', 'power-reactive', 'energy-apparent', 'energy-active', |
| 291 |
'energy-reactive', 'voltage-thd', 'current-thd'. |
| 292 |
|
| 293 |
=back |
| 294 |
|
| 295 |
=cut |