| 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::ups::himoinsa::snmp::mode::status; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); |
| 28 |
|
| 29 |
sub status_long_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return 'checking component status'; |
| 33 |
} |
| 34 |
|
| 35 |
sub custom_status_output { |
| 36 |
my ($self, %options) = @_; |
| 37 |
|
| 38 |
return $self->{result_values}->{display} . " status: " . $self->{result_values}->{status}; |
| 39 |
} |
| 40 |
|
| 41 |
sub custom_status_commutator_output { |
| 42 |
my ($self, %options) = @_; |
| 43 |
|
| 44 |
return $self->{result_values}->{display} . ": " . $self->{result_values}->{status}; |
| 45 |
} |
| 46 |
|
| 47 |
sub set_counters { |
| 48 |
my ($self, %options) = @_; |
| 49 |
|
| 50 |
$self->{maps_counters_type} = [ |
| 51 |
{ name => 'components', type => 3, cb_long_output => 'status_long_output', indent_long_output => ' ', |
| 52 |
group => [ |
| 53 |
{ name => 'motor-status', type => 0, skipped_code => { -10 => 1 } }, |
| 54 |
{ name => 'mode-status', type => 0, skipped_code => { -10 => 1 } }, |
| 55 |
{ name => 'transfer-pump-status', type => 0, skipped_code => { -10 => 1 } }, |
| 56 |
{ name => 'alarm-status', type => 0, skipped_code => { -10 => 1 } }, |
| 57 |
{ name => 'closed-commutator', type => 0, skipped_code => { -10 => 1 } } |
| 58 |
] |
| 59 |
} |
| 60 |
]; |
| 61 |
|
| 62 |
$self->{maps_counters}->{'motor-status'} = [ |
| 63 |
{ label => 'motor-status', type => 2, set => { |
| 64 |
key_values => [ { name => 'status' }, { name => 'display' } ], |
| 65 |
closure_custom_output => $self->can('custom_status_output'), |
| 66 |
closure_custom_perfdata => sub { return 0; }, |
| 67 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 68 |
} |
| 69 |
} |
| 70 |
]; |
| 71 |
|
| 72 |
$self->{maps_counters}->{'mode-status'} = [ |
| 73 |
{ label => 'mode-status', type => 2, set => { |
| 74 |
key_values => [ { name => 'status' }, { name => 'display' } ], |
| 75 |
closure_custom_output => $self->can('custom_status_commutator_output'), |
| 76 |
closure_custom_perfdata => sub { return 0; }, |
| 77 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 78 |
} |
| 79 |
} |
| 80 |
]; |
| 81 |
|
| 82 |
$self->{maps_counters}->{'transfer-pump-status'} = [ |
| 83 |
{ label => 'transfer-pump-status', type => 2, set => { |
| 84 |
key_values => [ { name => 'status' }, { name => 'display' } ], |
| 85 |
closure_custom_output => $self->can('custom_status_output'), |
| 86 |
closure_custom_perfdata => sub { return 0; }, |
| 87 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 88 |
} |
| 89 |
} |
| 90 |
]; |
| 91 |
|
| 92 |
$self->{maps_counters}->{'alarm-status'} = [ |
| 93 |
{ label => 'alarm-status', type => 2, warning_default => '%{status} =~ /^alarm/', set => { |
| 94 |
key_values => [ { name => 'status' }, { name => 'display' } ], |
| 95 |
closure_custom_output => $self->can('custom_status_output'), |
| 96 |
closure_custom_perfdata => sub { return 0; }, |
| 97 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 98 |
} |
| 99 |
} |
| 100 |
]; |
| 101 |
|
| 102 |
$self->{maps_counters}->{'closed-commutator'} = [ |
| 103 |
{ label => 'closed-commutator', type => 2, set => { |
| 104 |
key_values => [ { name => 'status' }, { name => 'display' } ], |
| 105 |
closure_custom_output => $self->can('custom_status_commutator_output'), |
| 106 |
closure_custom_perfdata => sub { return 0; }, |
| 107 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 108 |
} |
| 109 |
} |
| 110 |
]; |
| 111 |
} |
| 112 |
|
| 113 |
# mapping for CEA7 and CEM7 device |
| 114 |
my $mapping_motor_status = { |
| 115 |
0 => 'unknown', 1 => 'running', 2 => 'stopped' |
| 116 |
}; |
| 117 |
|
| 118 |
my $mapping_mode_status = { |
| 119 |
0 => 'unknown', 4 => 'auto', 8 => 'manual', 16 => 'test', 32 => 'blocked' |
| 120 |
}; |
| 121 |
|
| 122 |
my $mapping_transfer_pump_status = { |
| 123 |
0 => 'off', 64 => 'on' |
| 124 |
}; |
| 125 |
|
| 126 |
my $mapping_alarm_status = { |
| 127 |
0 => 'no alarm', 128 => 'alarm' |
| 128 |
}; |
| 129 |
|
| 130 |
my $mapping_closed_commutator = { |
| 131 |
0 => 'unknown', 256 => 'mains', 512 => 'genset' |
| 132 |
}; |
| 133 |
|
| 134 |
# mapping for CEC7 device |
| 135 |
my $cec7_mapping_alarm_status = { |
| 136 |
0 => 'no alarm', 1 => 'alarm' |
| 137 |
}; |
| 138 |
|
| 139 |
my $cec7_mapping_mode_status = { |
| 140 |
0 => 'unknown', 2 => 'auto', 4 => 'manual', 8 => 'test', 16 => 'blocked' |
| 141 |
}; |
| 142 |
|
| 143 |
my $cec7_mapping_closed_commutator = { |
| 144 |
0 => 'unknown', 32 => 'genset', 64 => 'mains' |
| 145 |
}; |
| 146 |
|
| 147 |
sub get_motor_status { |
| 148 |
my ($self, %options) = @_; |
| 149 |
|
| 150 |
return ($options{value} & 1) | ($options{value} & 2); |
| 151 |
} |
| 152 |
|
| 153 |
sub get_mode_status { |
| 154 |
my ($self, %options) = @_; |
| 155 |
|
| 156 |
return ($options{value} & 4) | ($options{value} & 8) | ($options{value} & 16)| ($options{value} & 32); |
| 157 |
} |
| 158 |
|
| 159 |
sub get_transfer_pump_status { |
| 160 |
my ($self, %options) = @_; |
| 161 |
|
| 162 |
return $options{value} & 64; |
| 163 |
} |
| 164 |
|
| 165 |
sub get_alarm_status { |
| 166 |
my ($self, %options) = @_; |
| 167 |
|
| 168 |
return $options{value} & 128; |
| 169 |
} |
| 170 |
|
| 171 |
sub get_closed_commutator { |
| 172 |
my ($self, %options) = @_; |
| 173 |
|
| 174 |
return ($options{value} & 256) | ($options{value} & 512); |
| 175 |
} |
| 176 |
|
| 177 |
sub get_cec7_alarm_status { |
| 178 |
my ($self, %options) = @_; |
| 179 |
|
| 180 |
return $options{value} & 1; |
| 181 |
} |
| 182 |
|
| 183 |
sub get_cec7_mode_status { |
| 184 |
my ($self, %options) = @_; |
| 185 |
|
| 186 |
return ($options{value} & 2) | ($options{value} & 4) | ($options{value} & 8) | ($options{value} & 16); |
| 187 |
} |
| 188 |
|
| 189 |
sub get_cec7_closed_commutator { |
| 190 |
my ($self, %options) = @_; |
| 191 |
|
| 192 |
return ($options{value} & 32) | ($options{value} & 64); |
| 193 |
} |
| 194 |
|
| 195 |
sub new { |
| 196 |
my ($class, %options) = @_; |
| 197 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 198 |
bless $self, $class; |
| 199 |
|
| 200 |
$options{options}->add_options(arguments => { |
| 201 |
}); |
| 202 |
|
| 203 |
return $self; |
| 204 |
} |
| 205 |
|
| 206 |
my $oid_conmutationmeasuresEntry = '.1.3.6.1.4.1.41809.1.46.0'; |
| 207 |
my $oid_cec7_conmutationmeasuresEntry = '.1.3.6.1.4.1.41809.1.55.1.28.0'; |
| 208 |
|
| 209 |
sub manage_selection { |
| 210 |
my ($self, %options) = @_; |
| 211 |
|
| 212 |
my $snmp_result = $options{snmp}->get_leef(oids => [$oid_conmutationmeasuresEntry], nothing_quit => 1); |
| 213 |
|
| 214 |
my $motor_status = $self->get_motor_status(value => $snmp_result->{$oid_conmutationmeasuresEntry}); |
| 215 |
my $mode_status = $self->get_mode_status(value => $snmp_result->{$oid_conmutationmeasuresEntry}); |
| 216 |
my $transfer_pump_status = $self->get_transfer_pump_status(value => $snmp_result->{$oid_conmutationmeasuresEntry}); |
| 217 |
my $alarm_status = $self->get_alarm_status(value => $snmp_result->{$oid_conmutationmeasuresEntry}); |
| 218 |
my $closed_commutator = $self->get_closed_commutator(value => $snmp_result->{$oid_conmutationmeasuresEntry}); |
| 219 |
|
| 220 |
$self->{components} = { global => {} }; |
| 221 |
|
| 222 |
$self->{components}->{global}->{'motor-status'} = { |
| 223 |
status => $mapping_motor_status->{$motor_status}, |
| 224 |
display => 'motor' |
| 225 |
}; |
| 226 |
|
| 227 |
$self->{components}->{global}->{'mode-status'} = { |
| 228 |
status => $mapping_mode_status->{$mode_status}, |
| 229 |
display => 'commutator mode' |
| 230 |
}; |
| 231 |
|
| 232 |
$self->{components}->{global}->{'transfer-pump-status'} = { |
| 233 |
status => $mapping_transfer_pump_status->{$transfer_pump_status}, |
| 234 |
display => 'transfer pump' |
| 235 |
}; |
| 236 |
|
| 237 |
$self->{components}->{global}->{'alarm-status'} = { |
| 238 |
status => $mapping_alarm_status->{$alarm_status}, |
| 239 |
display => 'alarm' |
| 240 |
}; |
| 241 |
|
| 242 |
$self->{components}->{global}->{'closed-commutator'} = { |
| 243 |
status => $mapping_closed_commutator->{$closed_commutator}, |
| 244 |
display => 'closed commutator' |
| 245 |
}; |
| 246 |
} |
| 247 |
|
| 248 |
1; |
| 249 |
|
| 250 |
__END__ |
| 251 |
|
| 252 |
=head1 MODE |
| 253 |
|
| 254 |
Check Himoinsa device status. |
| 255 |
|
| 256 |
=over 8 |
| 257 |
|
| 258 |
=item B<--warning-alarm-status> |
| 259 |
|
| 260 |
Warning threshold for alarm (default: '%{status} =~ /^alarm/'). |
| 261 |
Can use special variables like: %{status} |
| 262 |
|
| 263 |
=item B<--critical-alarm-status> |
| 264 |
|
| 265 |
Critical threshold for alarm. |
| 266 |
Can use special variables like: %{status} |
| 267 |
|
| 268 |
=item B<--warning-motor-status> |
| 269 |
|
| 270 |
Warning threshold for motor status. |
| 271 |
Can use special variables like: %{status} |
| 272 |
|
| 273 |
=item B<--critical-motor-status> |
| 274 |
|
| 275 |
Critical threshold for motor status. |
| 276 |
Can use special variables like: %{status} |
| 277 |
|
| 278 |
=item B<--warning-mode-status> |
| 279 |
|
| 280 |
Warning threshold for commutator mode status. |
| 281 |
Can use special variables like: %{status} |
| 282 |
|
| 283 |
=item B<--critical-mode-status> |
| 284 |
|
| 285 |
Critical threshold for commutator mode status. |
| 286 |
Can use special variables like: %{status} |
| 287 |
|
| 288 |
=item B<--warning-closed-commutator> |
| 289 |
|
| 290 |
Warning threshold for commutator currently closed. |
| 291 |
Can use special variables like: %{status} |
| 292 |
|
| 293 |
=item B<--critical-closed-commutator> |
| 294 |
|
| 295 |
Critical threshold for commutator currently closed. |
| 296 |
Can use special variables like: %{status} |
| 297 |
|
| 298 |
For example if you want to get an alert if the closed commutator is mains: |
| 299 |
|
| 300 |
--critical-closed-commutator='%{status} =~ /mains/i' |
| 301 |
|
| 302 |
=item B<--warning-transfer-pump-status> |
| 303 |
|
| 304 |
Warning threshold for transfer pump status. |
| 305 |
Can use special variables like: %{status} |
| 306 |
|
| 307 |
=item B<--critical-transfer-pump-status> |
| 308 |
|
| 309 |
Critical threshold for transfer pump status. |
| 310 |
Can use special variables like: %{status} |
| 311 |
|
| 312 |
=back |
| 313 |
|
| 314 |
=cut |