1package Classes::ATS::ATSTHREEPHASE::Components::BatterySubsystem; 2our @ISA = qw(Monitoring::GLPlugin::SNMP::Item); 3use strict; 4 5sub init { 6 my ($self) = @_; 7 $self->get_snmp_objects("ATS-THREEPHASE-MIB", qw(sysUpsRecInputPresentOk sysUpsBypInputPresentOk 8 sysUpsOperationMode sysUpsOutputSource sysUpsBatteryDischargerOn 9 sysUpsBatteryChargerOn sysUpsLoadOnManualBypass sysUpsBatteryStatus 10 sysUpsBatteryGroupRemainingCapacity sysUpsBatteryGroupRemainingRunTime 11 sysUpsBatteryGroupPositiveTotalBatteryVoltage sysUpsBatteryGroupNegativeTotalBatteryVoltage 12 sysUpsBatteryGroupPositiveBatteryVoltagePerCell sysUpsBatteryGroupNegativeBatteryVoltagePerCell 13 sysUpsBatteryGroupChargingWatt sysUpsBatteryGroupDischargingWatt 14 sysUpsBatteryGroupPositiveBatteryChargerCurrent sysUpsBatteryGroupNegativeBatteryChargerCurrent 15 sysUpsBatteryGroupPositiveBatteryDischargerCurrent sysUpsBatteryGroupNegativeBatteryDischargerCurrent 16 17 18 )); 19 $self->get_snmp_tables("ATS-THREEPHASE-MIB", [ 20 ["batteries", "upsBatteryGroupTable", "Classes::ATS::ATSTHREEPHASE::Components::BatterySubsystem::Battery"], 21 ["sysbatteries", "", "Monitoring::GLPlugin::SNMP::TableItem"], 22 ["load", "upsLoadGroupTable", "Classes::ATS::ATSTHREEPHASE::Components::BatterySubsystem::Load"], 23 ["inputs", "upsInputGroupTable", "Classes::ATS::ATSTHREEPHASE::Components::BatterySubsystem::Input"], 24 ["outputs", "upsOutputGroupTable", "Classes::ATS::ATSTHREEPHASE::Components::BatterySubsystem::Output"], 25 ["bypass", "upsBypassGroupTable", "Classes::ATS::ATSTHREEPHASE::Components::BatterySubsystem::Bypass"], 26 ["wkstatus", "upsStatusGroupTable", "Classes::ATS::ATSTHREEPHASE::Components::BatterySubsystem::WKStatus"], #upsWellKnownStatusTable 27 28 ]); 29 @{$self->{batteries}} = grep { $_->{valid} } @{$self->{batteries}}; 30 @{$self->{wkstatus}} = grep { $_->{valid} } @{$self->{wkstatus}}; 31 @{$self->{inputs}} = grep { $_->{valid} } @{$self->{inputs}}; 32 @{$self->{outputs}} = grep { $_->{valid} } @{$self->{outputs}}; 33 @{$self->{bypass}} = grep { $_->{valid} } @{$self->{bypass}}; 34 @{$self->{load}} = grep { $_->{valid} } @{$self->{load}}; 35} 36 37sub xcheck { 38 my ($self) = @_; 39 $self->add_info('checking battery'); 40 41 if (defined $self->{upsBatteryTemperature}) { 42 $self->set_thresholds( 43 metric => 'battery_temperature', warning => '35', critical => '38'); 44 $self->add_info(sprintf 'temperature is %.2fC', $self->{upsBatteryTemperature}); 45 $self->add_message( 46 $self->check_thresholds( 47 value => $self->{upsBatteryTemperature}, 48 metric => 'battery_temperature')); 49 $self->add_perfdata( 50 label => 'battery_temperature', 51 value => $self->{upsBatteryTemperature}, 52 ); 53 } 54 55 if ($self->{upsSecondsOnBattery}) { 56 $self->set_thresholds( 57 metric => 'remaining_time', warning => '15:', critical => '10:'); 58 $self->add_info(sprintf 'remaining battery run time is %.2fmin', $self->{upsEstimatedMinutesRemaining}); 59 $self->add_message( 60 $self->check_thresholds( 61 value => $self->{upsEstimatedMinutesRemaining}, 62 metric => 'remaining_time')); 63 } else { 64 $self->set_thresholds( 65 metric => 'remaining_time', warning => '0:', critical => '0:'); 66 # do not evaluate with check_thresholds, because there might be 67 # higher thresholds set by warningx/criticalx 68 $self->add_ok('unit is not on battery power'); 69 } 70 $self->add_perfdata( 71 label => 'remaining_time', 72 value => $self->{upsEstimatedMinutesRemaining}, 73 ); 74 75 if (defined $self->{upsEstimatedChargeRemaining}) { 76 $self->set_thresholds( 77 metric => 'capacity', warning => '25:', critical => '10:'); 78 $self->add_info(sprintf 'capacity is %.2f%%', $self->{upsEstimatedChargeRemaining}); 79 $self->add_message( 80 $self->check_thresholds( 81 value => $self->{upsEstimatedChargeRemaining}, 82 metric => 'capacity')); 83 $self->add_perfdata( 84 label => 'capacity', 85 value => $self->{upsEstimatedChargeRemaining}, 86 uom => '%', 87 ); 88 } 89 90 if (defined ($self->{upsBatteryVoltage})) { 91 $self->add_info(sprintf 'battery voltage is %d VDC', $self->{upsBatteryVoltage}); 92 $self->add_perfdata( 93 label => 'battery_voltage', 94 value => $self->{upsBatteryVoltage}, 95 ); 96 } 97 98 $self->add_perfdata( 99 label => 'output_frequency', 100 value => $self->{upsOutputFrequency}, 101 ); 102 103 foreach (@{$self->{inputs}}) { 104 $_->check(); 105 } 106 foreach (@{$self->{outputs}}) { 107 $_->check(); 108 } 109 110 if ($self->{upsBatteryStatus} && $self->{upsBatteryStatus} ne "batteryNormal") { 111 $self->add_critical("battery has status: ".$self->{upsBatteryStatus}); 112 } 113} 114 115sub xdump { 116 my ($self) = @_; 117 printf "[BATTERY]\n"; 118 foreach (grep /^ups/, keys %{$self}) { 119 printf "%s: %s\n", $_, $self->{$_}; 120 } 121 printf "info: %s\n", $self->{info}; 122 printf "\n"; 123 foreach (@{$self->{inputs}}) { 124 $_->dump(); 125 } 126 foreach (@{$self->{outputs}}) { 127 $_->dump(); 128 } 129} 130 131 132package Classes::ATS::ATSTHREEPHASE::Components::BatterySubsystem::Battery; 133our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem); 134use strict; 135 136sub finish { 137 my ($self) = @_; 138 $self->{valid} = 0; 139 foreach (qw(upsBatteryGroupPositiveBatteryVoltagePerCell 140 upsBatteryGroupNegativeBatteryVoltagePerCell 141 upsBatteryGroupNegativeTotalBatteryVoltage 142 upsBatteryGroupPositiveTotalBatteryVoltage)) { 143 if ($self->{$_}) { 144 $self->{valid} = 1; 145 } 146 } 147 if ($self->{valid}) { 148 $self->{upsBatteryGroupRemainingCapacity} /= 10; 149 foreach (qw(upsBatteryGroupPositiveTotalBatteryVoltage 150 upsBatteryGroupNegativeTotalBatteryVoltage upsBatteryGroupPositiveBatteryVoltagePerCell 151 upsBatteryGroupNegativeBatteryVoltagePerCell upsBatteryGroupChargingWatt 152 upsBatteryGroupDischargingWatt upsBatteryGroupPositiveBatteryChargerCurrent 153 upsBatteryGroupNegativeBatteryChargerCurrent upsBatteryGroupPositiveBatteryDischargerCurrent 154 upsBatteryGroupNegativeBatteryDischargerCurrent)) { 155 $self->{$_} /= 100; 156 } 157 } 158} 159 160sub check { 161 my ($self) = @_; 162 $self->set_thresholds( 163 metric => 'capacity', warning => '25:', critical => '10:'); 164 $self->add_info(sprintf 'capacity is %.2f%%', $self->{upsBatteryGroupRemainingCapacity}); 165 $self->add_message( 166 $self->check_thresholds( 167 value => $self->{upsBatteryGroupRemainingCapacity}, 168 metric => 'capacity')); 169 $self->add_perfdata( 170 label => 'capacity', 171 value => $self->{upsBatteryGroupRemainingCapacity}, 172 uom => '%', 173 ); 174 if ($self->{upsBatteryGroupRemainingRunTime}) { 175 $self->set_thresholds( 176 metric => 'remaining_time', warning => '15:', critical => '10:'); 177 $self->add_info(sprintf 'remaining battery run time is %.2fmin', $self->{upsBatteryGroupRemainingRunTime}); 178 $self->add_message( 179 $self->check_thresholds( 180 value => $self->{upsBatteryGroupRemainingRunTime}, 181 metric => 'remaining_time')); 182 } else { 183 $self->set_thresholds( 184 metric => 'remaining_time', warning => '0:', critical => '0:'); 185 # do not evaluate with check_thresholds, because there might be 186 # higher thresholds set by warningx/criticalx 187 $self->add_ok('unit is not on battery power'); 188 } 189 $self->add_perfdata( 190 label => 'remaining_time', 191 value => $self->{upsBatteryGroupRemainingRunTime}, 192 ); 193} 194 195 196package Classes::ATS::ATSTHREEPHASE::Components::BatterySubsystem::Input; 197our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem); 198use strict; 199 200sub finish { 201 my ($self) = @_; 202 $self->{valid} = 0; 203 foreach (qw(upsInputGroupCurrentR upsInputGroupCurrentS 204 upsInputGroupCurrentT)) { 205 if ($self->{$_}) { 206 $self->{valid} = 1; 207 } 208 } 209 foreach (grep /^upsInput/, keys %{$self}) { 210 $self->{$_} /= 10; 211 } 212} 213 214sub check { 215 my ($self) = @_; 216 if ($self->{upsInputGroupVoltageR} < 1 && $self->{upsInputGroupVoltageS} < 1 && 217 $self->{upsInputGroupVoltageT}) { 218 $self->add_critical(sprintf 'input power%s outage', $self->{flat_indices}); 219 } 220 $self->add_perfdata( 221 label => 'input_voltageR'.$self->{flat_indices}, 222 value => $self->{upsInputGroupVoltageR}, 223 ); 224 $self->add_perfdata( 225 label => 'input_voltageS'.$self->{flat_indices}, 226 value => $self->{upsInputGroupVoltageS}, 227 ); 228 $self->add_perfdata( 229 label => 'input_voltageT'.$self->{flat_indices}, 230 value => $self->{upsInputGroupVoltageT}, 231 ); 232 $self->add_perfdata( 233 label => 'input_frequency'.$self->{flat_indices}, 234 value => $self->{upsInputGroupFrequency}, 235 ); 236 $self->add_perfdata( 237 label => 'input_currentR'.$self->{flat_indices}, 238 value => $self->{upsInputGroupCurrentR}, 239 ); 240 $self->add_perfdata( 241 label => 'input_currentS'.$self->{flat_indices}, 242 value => $self->{upsInputGroupCurrentS}, 243 ); 244 $self->add_perfdata( 245 label => 'input_currentT'.$self->{flat_indices}, 246 value => $self->{upsInputGroupCurrentT}, 247 ); 248} 249 250package Classes::ATS::ATSTHREEPHASE::Components::BatterySubsystem::Output; 251our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem); 252use strict; 253 254sub finish { 255 my ($self) = @_; 256 $self->{valid} = 0; 257 foreach (qw(upsOutputGroupCurrentR upsOutputGroupCurrentS 258 upsOutputGroupCurrentT)) { 259 if ($self->{$_}) { 260 $self->{valid} = 1; 261 } 262 } 263 foreach (grep /^upsOutput/, keys %{$self}) { 264 $self->{$_} /= 10; 265 } 266} 267 268sub check { 269 my ($self) = @_; 270 $self->add_perfdata( 271 label => 'output_voltageR'.$self->{flat_indices}, 272 value => $self->{upsOutputGroupVoltageR}, 273 ); 274 $self->add_perfdata( 275 label => 'output_voltageS'.$self->{flat_indices}, 276 value => $self->{upsOutputGroupVoltageS}, 277 ); 278 $self->add_perfdata( 279 label => 'output_voltageT'.$self->{flat_indices}, 280 value => $self->{upsOutputGroupVoltageT}, 281 ); 282 $self->add_perfdata( 283 label => 'output_frequency'.$self->{flat_indices}, 284 value => $self->{upsOutputGroupFrequency}, 285 ); 286 $self->add_perfdata( 287 label => 'output_currentR'.$self->{flat_indices}, 288 value => $self->{upsOutputGroupCurrentR}, 289 ); 290 $self->add_perfdata( 291 label => 'output_currentS'.$self->{flat_indices}, 292 value => $self->{upsOutputGroupCurrentS}, 293 ); 294 $self->add_perfdata( 295 label => 'output_currentT'.$self->{flat_indices}, 296 value => $self->{upsOutputGroupCurrentT}, 297 ); 298 $self->add_perfdata( 299 label => 'output_powerR'.$self->{flat_indices}, 300 value => $self->{upsOutputGroupPowerFactorR} || 0, 301 ); 302 $self->add_perfdata( 303 label => 'output_powerS'.$self->{flat_indices}, 304 value => $self->{upsOutputGroupPowerFactorS} || 0, 305 ); 306 $self->add_perfdata( 307 label => 'output_powerT'.$self->{flat_indices}, 308 value => $self->{upsOutputGroupPowerFactor} || 0, 309 ); 310} 311 312 313package Classes::ATS::ATSTHREEPHASE::Components::BatterySubsystem::Bypass; 314our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem); 315use strict; 316 317sub finish { 318 my ($self) = @_; 319 $self->{valid} = 0; 320 foreach (qw(upsBypassGroupCurrentR upsBypassGroupCurrentS 321 upsBypassGroupCurrentT)) { 322 if ($self->{$_}) { 323 $self->{valid} = 1; 324 } 325 } 326 foreach (grep /^upsBypass/, keys %{$self}) { 327 $self->{$_} /= 10; 328 } 329} 330 331sub check { 332 my ($self) = @_; 333 $self->add_perfdata( 334 label => 'bypass_voltageR'.$self->{flat_indices}, 335 value => $self->{upsBypassGroupVoltageR}, 336 ); 337 $self->add_perfdata( 338 label => 'bypass_voltageS'.$self->{flat_indices}, 339 value => $self->{upsBypassGroupVoltageS}, 340 ); 341 $self->add_perfdata( 342 label => 'bypass_voltageT'.$self->{flat_indices}, 343 value => $self->{upsBypassGroupVoltageT}, 344 ); 345 $self->add_perfdata( 346 label => 'bypass_frequency'.$self->{flat_indices}, 347 value => $self->{upsBypassGroupFrequency}, 348 ); 349 $self->add_perfdata( 350 label => 'bypass_currentR'.$self->{flat_indices}, 351 value => $self->{upsBypassGroupCurrentR}, 352 ); 353 $self->add_perfdata( 354 label => 'bypass_currentS'.$self->{flat_indices}, 355 value => $self->{upsBypassGroupCurrentS}, 356 ); 357 $self->add_perfdata( 358 label => 'bypass_currentT'.$self->{flat_indices}, 359 value => $self->{upsBypassGroupCurrentT}, 360 ); 361} 362 363 364package Classes::ATS::ATSTHREEPHASE::Components::BatterySubsystem::Load; 365our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem); 366use strict; 367 368sub finish { 369 my ($self) = @_; 370 $self->{valid} = 0; 371 foreach (qw(upsLoadGroupLoadR upsLoadGroupLoadS 372 upsLoadGroupLoadT)) { 373 if ($self->{$_}) { 374 $self->{valid} = 1; 375 } 376 } 377 foreach (grep /^upsLoad/, keys %{$self}) { 378 $self->{$_} /= 10; 379 } 380} 381 382sub check { 383 my ($self) = @_; 384 my $metric = 'output_loadR'.$self->{flat_indices}; 385 $self->set_thresholds( 386 metric => $metric, warning => '75', critical => '85'); 387 $self->add_info(sprintf 'output loadR%d %.2f%%', $self->{flat_indices}, $self->{upsLoadGroupLoadR}); 388 $self->add_message( 389 $self->check_thresholds( 390 value => $self->{upsLoadGroupLoadR}, 391 metric => $metric)); 392 $self->add_perfdata( 393 label => $metric, 394 value => $self->{upsLoadGroupLoadR}, 395 uom => '%', 396 ); 397 $metric = 'output_loadS'.$self->{flat_indices}; 398 $self->set_thresholds( 399 metric => $metric, warning => '75', critical => '85'); 400 $self->add_info(sprintf 'output loadS%d %.2f%%', $self->{flat_indices}, $self->{upsLoadGroupLoadS}); 401 $self->add_message( 402 $self->check_thresholds( 403 value => $self->{upsLoadGroupLoadS}, 404 metric => $metric)); 405 $self->add_perfdata( 406 label => $metric, 407 value => $self->{upsLoadGroupLoadS}, 408 uom => '%', 409 ); 410 $metric = 'output_loadT'.$self->{flat_indices}; 411 $self->set_thresholds( 412 metric => $metric, warning => '75', critical => '85'); 413 $self->add_info(sprintf 'output loadT%d %.2f%%', $self->{flat_indices}, $self->{upsLoadGroupLoadT}); 414 $self->add_message( 415 $self->check_thresholds( 416 value => $self->{upsLoadGroupLoadT}, 417 metric => $metric)); 418 $self->add_perfdata( 419 label => $metric, 420 value => $self->{upsLoadGroupLoadT}, 421 uom => '%', 422 ); 423} 424 425 426package Classes::ATS::ATSTHREEPHASE::Components::BatterySubsystem::WKStatus; 427our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem); 428use strict; 429 430sub finish { 431 my ($self) = @_; 432 $self->{valid} = 0; 433 foreach (qw(upsStatusGroupBatteryStatus 434 upsStatusGroupOperationMode upsStatusGroupOutputSource 435 upsStatusGroupParallelUnitary)) { 436 if ($self->{$_} ne "unknown") { 437 $self->{valid} = 1; 438 } 439 } 440} 441 442sub check { 443 my ($self) = @_; 444 $self->add_info(sprintf "battery status is %s", $self->{upsStatusGroupBatteryStatus}); 445 if ($self->{upsStatusGroupBatteryStatus} eq "batteryOk") { 446 $self->add_ok(); 447 } elsif ($self->{upsStatusGroupBatteryStatus} eq "batteryLow" || 448 $self->{upsStatusGroupBatteryStatus} eq "batteryWeake" || 449 $self->{upsStatusGroupBatteryStatus} eq "upsOff") { 450 $self->add_warning(); 451 } elsif ($self->{upsStatusGroupBatteryStatus} eq "unknown") { 452 $self->add_unknown(); 453 } 454} 455 456 457 458