|  | #include "../utils.hpp" | 
|  |  | 
|  | #include <systemd/sd-journal.h> | 
|  |  | 
|  | #include <boost/container/flat_map.hpp> | 
|  | #include <nlohmann/json.hpp> | 
|  |  | 
|  | #include <string> | 
|  |  | 
|  | void logDeviceAdded(const nlohmann::json& record) | 
|  | { | 
|  | if (!deviceHasLogging(record)) | 
|  | { | 
|  | return; | 
|  | } | 
|  | auto findType = record.find("Type"); | 
|  | auto findAsset = | 
|  | record.find("xyz.openbmc_project.Inventory.Decorator.Asset"); | 
|  |  | 
|  | std::string model = "Unknown"; | 
|  | std::string type = "Unknown"; | 
|  | std::string sn = "Unknown"; | 
|  | std::string name = "Unknown"; | 
|  |  | 
|  | 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()) | 
|  | { | 
|  | const std::string* getSn = findSn->get_ptr<const std::string*>(); | 
|  | if (getSn != nullptr) | 
|  | { | 
|  | sn = *getSn; | 
|  | } | 
|  | else | 
|  | { | 
|  | sn = findSn->dump(); | 
|  | } | 
|  | } | 
|  | } | 
|  |  | 
|  | auto findName = record.find("Name"); | 
|  | if (findName != record.end()) | 
|  | { | 
|  | name = findName->get<std::string>(); | 
|  | } | 
|  |  | 
|  | sd_journal_send("MESSAGE=Inventory Added: %s", name.c_str(), "PRIORITY=%i", | 
|  | LOG_INFO, "REDFISH_MESSAGE_ID=%s", | 
|  | "OpenBMC.0.1.InventoryAdded", | 
|  | "REDFISH_MESSAGE_ARGS=%s,%s,%s", model.c_str(), | 
|  | type.c_str(), sn.c_str(), "NAME=%s", name.c_str(), NULL); | 
|  | } | 
|  |  | 
|  | void logDeviceRemoved(const nlohmann::json& record) | 
|  | { | 
|  | if (!deviceHasLogging(record)) | 
|  | { | 
|  | return; | 
|  | } | 
|  | auto findType = record.find("Type"); | 
|  | auto findAsset = | 
|  | record.find("xyz.openbmc_project.Inventory.Decorator.Asset"); | 
|  |  | 
|  | std::string model = "Unknown"; | 
|  | std::string type = "Unknown"; | 
|  | std::string sn = "Unknown"; | 
|  | std::string name = "Unknown"; | 
|  |  | 
|  | 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()) | 
|  | { | 
|  | const std::string* getSn = findSn->get_ptr<const std::string*>(); | 
|  | if (getSn != nullptr) | 
|  | { | 
|  | sn = *getSn; | 
|  | } | 
|  | else | 
|  | { | 
|  | sn = findSn->dump(); | 
|  | } | 
|  | } | 
|  | } | 
|  |  | 
|  | auto findName = record.find("Name"); | 
|  | if (findName != record.end()) | 
|  | { | 
|  | name = findName->get<std::string>(); | 
|  | } | 
|  |  | 
|  | sd_journal_send("MESSAGE=Inventory Removed: %s", name.c_str(), | 
|  | "PRIORITY=%i", LOG_INFO, "REDFISH_MESSAGE_ID=%s", | 
|  | "OpenBMC.0.1.InventoryRemoved", | 
|  | "REDFISH_MESSAGE_ARGS=%s,%s,%s", model.c_str(), | 
|  | type.c_str(), sn.c_str(), "NAME=%s", name.c_str(), NULL); | 
|  | } |