Enhance device added / removed log message
Add model, type, and sn to the message.
Tested: looked at redfish log after boot
Change-Id: I01bd039de4eeebd32fa11aac99202f4c6aff8890
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/include/EntityManager.hpp b/include/EntityManager.hpp
index 7f46ce2..74ba827 100644
--- a/include/EntityManager.hpp
+++ b/include/EntityManager.hpp
@@ -19,20 +19,74 @@
#include <systemd/sd-journal.h>
#include <iostream>
+#include <nlohmann/json.hpp>
#include <string>
-inline void logDeviceAdded(const std::string& device)
+inline void logDeviceAdded(const nlohmann::json& record)
{
+ auto findType = record.find("Type");
+ auto findAsset =
+ record.find("xyz.openbmc_project.Inventory.Decorator.Asset");
+
+ std::string model = "Unkown";
+ std::string type = "Unknown";
+ std::string sn = "Unkown";
+
+ if (findType != record.end())
+ {
+ type = findType->get<std::string>();
+ }
+ if (findAsset != record.end())
+ {
+ auto findModel = findAsset->find("Model");
+ auto findSn = findAsset->find("SerialNumber");
+ if (findModel != findAsset->end())
+ {
+ model = findModel->get<std::string>();
+ }
+ if (findSn != findAsset->end())
+ {
+ sn = findSn->get<std::string>();
+ }
+ }
+
sd_journal_send("MESSAGE=%s", "Inventory Added", "PRIORITY=%i", LOG_ERR,
"REDFISH_MESSAGE_ID=%s", "OpenBMC.0.1.InventoryAdded",
- "REDFISH_MESSAGE_ARGS=%s", device.c_str(), NULL);
+ "REDFISH_MESSAGE_ARGS=%s,%s,%s", model.c_str(),
+ type.c_str(), sn.c_str(), NULL);
}
-inline void logDeviceRemoved(const std::string& device)
+inline void logDeviceRemoved(const nlohmann::json& record)
{
+ auto findType = record.find("Type");
+ auto findAsset =
+ record.find("xyz.openbmc_project.Inventory.Decorator.Asset");
+
+ std::string model = "Unkown";
+ std::string type = "Unknown";
+ std::string sn = "Unkown";
+
+ if (findType != record.end())
+ {
+ type = findType->get<std::string>();
+ }
+ if (findAsset != record.end())
+ {
+ auto findModel = findAsset->find("Model");
+ auto findSn = findAsset->find("SerialNumber");
+ if (findModel != findAsset->end())
+ {
+ model = findModel->get<std::string>();
+ }
+ if (findSn != findAsset->end())
+ {
+ sn = findSn->get<std::string>();
+ }
+ }
sd_journal_send("MESSAGE=%s", "Inventory Removed", "PRIORITY=%i", LOG_ERR,
"REDFISH_MESSAGE_ID=%s", "OpenBMC.0.1.InventoryRemoved",
- "REDFISH_MESSAGE_ARGS=%s", device.c_str(), NULL);
+ "REDFISH_MESSAGE_ARGS=%s,%s,%s", model.c_str(),
+ type.c_str(), sn.c_str(), NULL);
}
\ No newline at end of file
diff --git a/src/EntityManager.cpp b/src/EntityManager.cpp
index bd8ccc7..da940b3 100644
--- a/src/EntityManager.cpp
+++ b/src/EntityManager.cpp
@@ -1471,7 +1471,8 @@
}
// overwrite ourselves with cleaned up version
_systemConfiguration[recordName] = record;
- logDeviceAdded(record.at("Name").get<std::string>());
+
+ logDeviceAdded(record);
foundDeviceIdx++;
}
@@ -1520,53 +1521,53 @@
}
timer.expires_from_now(boost::posix_time::seconds(10));
- timer.async_wait([&systemConfiguration](
- const boost::system::error_code& ec) {
- if (ec == boost::asio::error::operation_aborted)
- {
- // we were cancelled
- return;
- }
-
- bool powerOff = !isPowerOn();
- for (const auto& item : lastJson.items())
- {
- if (systemConfiguration.find(item.key()) ==
- systemConfiguration.end())
+ timer.async_wait(
+ [&systemConfiguration](const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
{
- bool isDetectedPowerOn = false;
- auto powerState = item.value().find("PowerState");
- if (powerState != item.value().end())
+ // we were cancelled
+ return;
+ }
+
+ bool powerOff = !isPowerOn();
+ for (const auto& item : lastJson.items())
+ {
+ if (systemConfiguration.find(item.key()) ==
+ systemConfiguration.end())
{
- auto ptr = powerState->get_ptr<const std::string*>();
- if (ptr)
+ bool isDetectedPowerOn = false;
+ auto powerState = item.value().find("PowerState");
+ if (powerState != item.value().end())
{
- if (*ptr == "On" || *ptr == "BiosPost")
+ auto ptr = powerState->get_ptr<const std::string*>();
+ if (ptr)
{
- isDetectedPowerOn = true;
+ if (*ptr == "On" || *ptr == "BiosPost")
+ {
+ isDetectedPowerOn = true;
+ }
}
}
- }
- if (powerOff && isDetectedPowerOn)
- {
- // power not on yet, don't know if it's there or not
- continue;
- }
- if (!powerOff && scannedPowerOff && isDetectedPowerOn)
- {
- // already logged it when power was off
- continue;
- }
+ if (powerOff && isDetectedPowerOn)
+ {
+ // power not on yet, don't know if it's there or not
+ continue;
+ }
+ if (!powerOff && scannedPowerOff && isDetectedPowerOn)
+ {
+ // already logged it when power was off
+ continue;
+ }
- logDeviceRemoved(item.value().at("Name").get<std::string>());
+ logDeviceRemoved(item.value());
+ }
}
- }
- scannedPowerOff = true;
- if (!powerOff)
- {
- scannedPowerOn = true;
- }
- });
+ scannedPowerOff = true;
+ if (!powerOff)
+ {
+ scannedPowerOn = true;
+ }
+ });
}
// main properties changed entry