# Version and similar info
$NAME = 'check_openmanage';
-$VERSION = '3.5.7-beta2';
+$VERSION = '3.5.7-beta4';
$AUTHOR = 'Trond H. Amundsen';
$CONTACT = 't.h.amundsen@usit.uio.no';
}
+# This helper function returns the corresponding value of a hash key,
+# but takes into account that the key may not exist
+sub get_hashval {
+ my $key = shift || return undef;
+ my $hash = shift;
+ return exists $hash->{$key} ? $hash->{$key} : "Undefined value $key";
+}
+
+
#---------------------------------------------------------------------
# Check functions
if ($snmp) {
$id = $out->{controllerNumber} - 1;
$name = $out->{controllerName};
- $state = $ctrl_state{$out->{controllerState}};
+ $state = get_hashval($out->{controllerState}, \%ctrl_state);
$status = $snmp_status{$out->{controllerComponentStatus}};
$minfw = exists $out->{controllerMinFWVersion}
? $out->{controllerMinFWVersion} : undef;
else {
$id = join q{:}, ($out->{arrayDiskChannel}, $out->{arrayDiskTargetID});
}
- $state = defined $out->{arrayDiskState}
- ? $pdisk_state{$out->{arrayDiskState}}
- : 'Unknown';
- $status = defined $out->{arrayDiskComponentStatus}
- ? $snmp_status{$out->{arrayDiskComponentStatus}}
- : 'Unknown';
+ $state = get_hashval($out->{arrayDiskState}, \%pdisk_state);
+ $status = $snmp_status{$out->{arrayDiskComponentStatus}};
$fpred = $out->{arrayDiskSmartAlertIndication} == 2 ? 1 : 0;
$progr = q{};
$nexus = convert_nexus($out->{arrayDiskNexusID});
if ($snmp) {
$id = $out->{virtualDiskTargetID};
$dev = $out->{virtualDiskDeviceName};
- $state = $vdisk_state{$out->{virtualDiskState}};
+ $state = get_hashval($out->{virtualDiskState}, \%vdisk_state);
+ $layout = get_hashval($out->{virtualDiskLayout}, \%vdisk_layout);
$status = $snmp_status{$out->{virtualDiskComponentStatus}};
- $layout = $vdisk_layout{$out->{virtualDiskLayout}};
$size = sprintf '%.2f GB', $out->{virtualDiskLengthInMB} / 1024;
$progr = q{}; # can't get this from SNMP(?)
$nexus = convert_nexus($out->{virtualDiskNexusID});
BATTERY:
foreach my $out (@output) {
if ($snmp) {
- $state = $bat_state{$out->{batteryState}};
$status = $snmp_status{$out->{batteryComponentStatus}};
- $learn = exists $out->{batteryLearnState}
- ? $bat_learn_state{$out->{batteryLearnState}} : undef;
- $pred = exists $out->{batteryPredictedCapacity}
- ? $bat_pred_cap{$out->{batteryPredictedCapacity}} : undef;
+ $state = get_hashval($out->{batteryState}, \%bat_state);
+ $learn = get_hashval($out->{batteryLearnState}, \%bat_learn_state);
+ $pred = get_hashval($out->{batteryPredictedCapacity}, \%bat_pred_cap);
$ctrl = $out->{batteryConnectionControllerNumber} - 1;
$nexus = convert_nexus($out->{batteryNexusID});
$id = $nexus;
if ($snmp) {
$id = $out->{channelNumber} - 1;
$name = $out->{channelName};
- $state = $conn_state{$out->{channelState}};
$status = $snmp_status{$out->{channelComponentStatus}};
- $type = $conn_bustype{$out->{channelBusType}};
+ $state = get_hashval($out->{channelState}, \%conn_state);
+ $type = get_hashval($out->{channelBusType}, \%conn_bustype);
$nexus = convert_nexus($out->{channelNexusID});
$ctrl = $nexus;
$ctrl =~ s{(\d+):\d+}{$1}xms;
ENCLOSURE:
foreach my $out (@output) {
if ($snmp) {
- $id = $out->{'enclosureNumber'} - 1;
- $name = $out->{'enclosureName'};
- $state = $encl_state{$out->{'enclosureState'}};
- $status = $snmp_status{$out->{'enclosureComponentStatus'}};
+ $id = $out->{enclosureNumber} - 1;
+ $name = $out->{enclosureName};
+ $state = get_hashval($out->{enclosureState}, \%encl_state);
+ $status = $snmp_status{$out->{enclosureComponentStatus}};
$firmware = exists $out->{enclosureFirmwareVersion}
? $out->{enclosureFirmwareVersion} : 'N/A';
$nexus = convert_nexus($out->{enclosureNexusID});
if ($snmp) {
$id = $out->{fanNumber} - 1;
$name = $out->{fanName};
- $state = $fan_state{$out->{fanState}};
+ $state = get_hashval($out->{fanState}, \%fan_state);
$status = $snmp_status{$out->{fanComponentStatus}};
$speed = $out->{fanProbeCurrValue};
$encl_id = $out->{fanConnectionEnclosureNumber} - 1;
if ($snmp) {
$id = $out->{powerSupplyNumber};
$name = $out->{powerSupplyName};
- $state = $ps_state{$out->{powerSupplyState}};
+ $state = get_hashval($out->{powerSupplyState}, \%ps_state);
$status = $snmp_status{$out->{powerSupplyComponentStatus}};
$encl_id = $out->{powerSupplyConnectionEnclosureNumber} - 1;
$encl_name = $out->{powerSupplyConnectionEnclosureName};
if ($snmp) {
$id = $out->{temperatureProbeNumber} - 1;
$name = $out->{temperatureProbeName};
- $state = $temp_state{$out->{temperatureProbeState}};
+ $state = get_hashval($out->{temperatureProbeState}, \%temp_state);
$status = $snmp_status{$out->{temperatureProbeComponentStatus}};
$unit = $out->{temperatureProbeUnit};
$reading = $out->{temperatureProbeCurValue};
if ($snmp) {
$id = $out->{enclosureManagementModuleNumber} - 1;
$name = $out->{enclosureManagementModuleName};
- $state = $emms_state{$out->{enclosureManagementModuleState}};
+ $state = get_hashval($out->{enclosureManagementModuleState}, \%emms_state);
$status = $snmp_status{$out->{enclosureManagementModuleComponentStatus}};
$encl_id = $out->{enclosureManagementModuleConnectionEnclosureNumber} - 1;
$encl_name = $out->{enclosureManagementModuleConnectionEnclosureName};
$index = $out->{powerSupplyIndex} - 1;
$status = $snmp_status{$out->{powerSupplyStatus}};
- $type = $ps_type{$out->{powerSupplyType}};
+ $type = get_hashval($out->{powerSupplyType}, \%ps_type);
$err_type = defined $out->{powerSupplyConfigurationErrorType}
? $ps_config_error_type{$out->{powerSupplyConfigurationErrorType}} : undef;
? $out->{temperatureProbeLowerCriticalThreshold} / 10 : '[N/A]';
$min_warn = exists $out->{temperatureProbeLowerNonCriticalThreshold}
? $out->{temperatureProbeLowerNonCriticalThreshold} / 10 : '[N/A]';
- $type = $probe_type{$out->{temperatureProbeType}};
+ $type = get_hashval($out->{temperatureProbeType}, \%probe_type);
$discrete = exists $out->{temperatureProbeDiscreteReading}
? $out->{temperatureProbeDiscreteReading} : undef;
}
$state = join q{, }, @states;
}
else {
- $state = $cpu_state{$out->{processorDeviceStatusState}};
+ $state = get_hashval($out->{processorDeviceStatusState}, \%cpu_state);
}
$man = $out->{processorDeviceManufacturerName};
$family = (exists $out->{processorDeviceFamily}
$status = $snmp_probestatus{$out->{voltageProbeStatus}};
$reading = exists $out->{voltageProbeReading}
? sprintf('%.3f V', $out->{voltageProbeReading}/1000)
- : $volt_discrete_reading{$out->{voltageProbeDiscreteReading}};
+ : get_hashval($out->{voltageProbeDiscreteReading}, \%volt_discrete_reading);
$location = $out->{voltageProbeLocationName};
}
else {
if ($snmp) {
$index = $out->{batteryIndex} - 1;
$status = $snmp_status{$out->{batteryStatus}};
- $reading = $bat_reading{$out->{batteryReading}};
+ $reading = get_hashval($out->{batteryReading}, \%bat_reading);
$location = $out->{batteryLocationName};
}
else {
if ($snmp) {
$index = $out->{amperageProbeIndex} - 1;
$status = $snmp_status{$out->{amperageProbeStatus}};
- $reading = $amp_type{$out->{amperageProbeType}} eq 'amperageProbeTypeIsDiscrete'
- ? $amp_discrete{$out->{amperageProbeDiscreteReading}}
+ $reading = get_hashval($out->{amperageProbeType}, \%amp_type) eq 'amperageProbeTypeIsDiscrete'
+ ? get_hashval($out->{amperageProbeDiscreteReading}, \%amp_discrete)
: $out->{amperageProbeReading};
$location = $out->{amperageProbeLocationName};
$max_crit = exists $out->{amperageProbeUpperCriticalThreshold}
if ($snmp) {
$index = $out->{intrusionIndex} - 1;
$status = $snmp_status{$out->{intrusionStatus}};
- $reading = $int_reading{$out->{intrusionReading}};
+ $reading = get_hashval($out->{intrusionReading}, \%int_reading);
}
else {
$index = $out->{'Index'};