summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dcmihandler.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/dcmihandler.cpp b/dcmihandler.cpp
index 11befdc..bfc8466 100644
--- a/dcmihandler.cpp
+++ b/dcmihandler.cpp
@@ -1037,18 +1037,28 @@ int64_t getPowerReading(sdbusplus::bus::bus& bus)
elog<InternalFailure>();
}
- auto service = ipmi::getService(bus, SENSOR_VALUE_INTF, objectPath);
-
- //Read the sensor value and scale properties
- auto properties = ipmi::getAllDbusProperties(
- bus, service, objectPath, SENSOR_VALUE_INTF);
- auto power = properties[SENSOR_VALUE_PROP].get<int64_t>();
- auto scale = properties[SENSOR_SCALE_PROP].get<int64_t>();
+ // Return default value if failed to read from D-Bus object
+ int64_t power = 0;
+ try
+ {
+ auto service = ipmi::getService(bus, SENSOR_VALUE_INTF, objectPath);
- // Power reading needs to be scaled with the Scale value using the formula
- // Value * 10^Scale.
- power *= std::pow(10, scale);
+ //Read the sensor value and scale properties
+ auto properties = ipmi::getAllDbusProperties(
+ bus, service, objectPath, SENSOR_VALUE_INTF);
+ auto value = properties[SENSOR_VALUE_PROP].get<int64_t>();
+ auto scale = properties[SENSOR_SCALE_PROP].get<int64_t>();
+ // Power reading needs to be scaled with the Scale value using the
+ // formula Value * 10^Scale.
+ power = value * std::pow(10, scale);
+ }
+ catch (std::exception& e)
+ {
+ log<level::INFO>("Failure to read power value from D-Bus object",
+ entry("OBJECT_PATH=%s", objectPath),
+ entry("INTERFACE=%s", SENSOR_VALUE_INTF));
+ }
return power;
}
OpenPOWER on IntegriCloud