| Patrick Venture | 46470a3 | 2018-09-07 19:26:25 -0700 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "selutility.hpp" |
| 4 | |
| Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 5 | #include <ipmid/api.hpp> |
| Vernon Mauery | 3325024 | 2019-03-12 16:49:26 -0700 | [diff] [blame] | 6 | #include <ipmid/types.hpp> |
| Vernon Mauery | 6a98fe7 | 2019-03-11 15:57:48 -0700 | [diff] [blame] | 7 | #include <ipmid/utils.hpp> |
| Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 8 | #include <phosphor-logging/elog-errors.hpp> |
| George Liu | 7acfcf0 | 2024-07-17 20:14:56 +0800 | [diff] [blame] | 9 | #include <phosphor-logging/lg2.hpp> |
| Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 10 | #include <xyz/openbmc_project/Common/error.hpp> |
| Alexander Hansen | 93aa983 | 2025-11-07 15:29:49 +0100 | [diff] [blame^] | 11 | #include <xyz/openbmc_project/ObjectMapper/common.hpp> |
| Patrick Venture | 46470a3 | 2018-09-07 19:26:25 -0700 | [diff] [blame] | 12 | |
| Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 13 | #include <charconv> |
| 14 | #include <chrono> |
| 15 | #include <filesystem> |
| 16 | #include <vector> |
| 17 | |
| Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 18 | extern const ipmi::sensor::InvObjectIDMap invSensors; |
| 19 | using namespace phosphor::logging; |
| 20 | using InternalFailure = |
| Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 21 | sdbusplus::error::xyz::openbmc_project::common::InternalFailure; |
| Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 22 | |
| Alexander Hansen | 93aa983 | 2025-11-07 15:29:49 +0100 | [diff] [blame^] | 23 | using ObjectMapper = sdbusplus::common::xyz::openbmc_project::ObjectMapper; |
| 24 | |
| Lei YU | 5015e95 | 2020-12-03 14:01:31 +0800 | [diff] [blame] | 25 | namespace |
| 26 | { |
| 27 | |
| 28 | constexpr auto systemEventRecord = 0x02; |
| Lei YU | 07c15b7 | 2020-12-06 15:08:06 +0800 | [diff] [blame] | 29 | constexpr auto generatorID = 0x2000; |
| 30 | constexpr auto eventMsgRevision = 0x04; |
| 31 | constexpr auto assertEvent = 0x00; |
| 32 | constexpr auto deassertEvent = 0x80; |
| 33 | constexpr auto selDataSize = 3; |
| 34 | constexpr auto oemCDDataSize = 9; |
| 35 | constexpr auto oemEFDataSize = 13; |
| Lei YU | 5015e95 | 2020-12-03 14:01:31 +0800 | [diff] [blame] | 36 | |
| Patrick Williams | 39deff2 | 2024-12-11 21:12:59 -0500 | [diff] [blame] | 37 | constexpr auto propAdditionalData = "AdditionalData"; |
| Lei YU | 07c15b7 | 2020-12-06 15:08:06 +0800 | [diff] [blame] | 38 | constexpr auto propResolved = "Resolved"; |
| 39 | |
| Lei YU | 719a41c | 2020-12-03 17:50:44 +0800 | [diff] [blame] | 40 | constexpr auto strEventDir = "EVENT_DIR"; |
| 41 | constexpr auto strGenerateId = "GENERATOR_ID"; |
| 42 | constexpr auto strRecordType = "RECORD_TYPE"; |
| 43 | constexpr auto strSensorData = "SENSOR_DATA"; |
| 44 | constexpr auto strSensorPath = "SENSOR_PATH"; |
| 45 | |
| Lei YU | 5015e95 | 2020-12-03 14:01:31 +0800 | [diff] [blame] | 46 | } // namespace |
| 47 | |
| Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 48 | namespace ipmi |
| 49 | { |
| 50 | |
| 51 | namespace sel |
| 52 | { |
| 53 | |
| 54 | namespace internal |
| 55 | { |
| 56 | |
| Lei YU | 5015e95 | 2020-12-03 14:01:31 +0800 | [diff] [blame] | 57 | inline bool isRecordOEM(uint8_t recordType) |
| 58 | { |
| 59 | return recordType != systemEventRecord; |
| 60 | } |
| 61 | |
| Lei YU | 07c15b7 | 2020-12-06 15:08:06 +0800 | [diff] [blame] | 62 | using entryDataMap = std::map<PropertyName, PropertyType>; |
| Lei YU | 5015e95 | 2020-12-03 14:01:31 +0800 | [diff] [blame] | 63 | |
| Lei YU | 07c15b7 | 2020-12-06 15:08:06 +0800 | [diff] [blame] | 64 | int convert(const std::string_view& str, int base = 10) |
| Lei YU | 5015e95 | 2020-12-03 14:01:31 +0800 | [diff] [blame] | 65 | { |
| William A. Kennington III | 4c52102 | 2023-07-28 13:07:30 -0700 | [diff] [blame] | 66 | int ret = 0; |
| Lei YU | 5015e95 | 2020-12-03 14:01:31 +0800 | [diff] [blame] | 67 | std::from_chars(str.data(), str.data() + str.size(), ret, base); |
| Lei YU | 07c15b7 | 2020-12-06 15:08:06 +0800 | [diff] [blame] | 68 | return ret; |
| Lei YU | 5015e95 | 2020-12-03 14:01:31 +0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | // Convert the string to a vector of uint8_t, where the str is formatted as hex |
| 72 | std::vector<uint8_t> convertVec(const std::string_view& str) |
| 73 | { |
| 74 | std::vector<uint8_t> ret; |
| 75 | auto len = str.size() / 2; |
| 76 | ret.reserve(len); |
| 77 | for (size_t i = 0; i < len; ++i) |
| 78 | { |
| Lei YU | 07c15b7 | 2020-12-06 15:08:06 +0800 | [diff] [blame] | 79 | ret.emplace_back( |
| 80 | static_cast<uint8_t>(convert(str.substr(i * 2, 2), 16))); |
| Lei YU | 5015e95 | 2020-12-03 14:01:31 +0800 | [diff] [blame] | 81 | } |
| 82 | return ret; |
| 83 | } |
| 84 | |
| Lei YU | 719a41c | 2020-12-03 17:50:44 +0800 | [diff] [blame] | 85 | /** Construct OEM SEL record according to IPMI spec 32.2, 32.3. */ |
| Lei YU | 07c15b7 | 2020-12-06 15:08:06 +0800 | [diff] [blame] | 86 | void constructOEMSEL(uint8_t recordType, std::chrono::milliseconds timestamp, |
| Potin Lai | 0c6561d | 2025-01-16 00:08:52 +0800 | [diff] [blame] | 87 | const AdditionalData& data, GetSELEntryResponse& record) |
| Lei YU | 719a41c | 2020-12-03 17:50:44 +0800 | [diff] [blame] | 88 | { |
| Potin Lai | 0c6561d | 2025-01-16 00:08:52 +0800 | [diff] [blame] | 89 | auto dataIter = data.find(strSensorData); |
| 90 | assert(dataIter != data.end()); |
| Lei YU | 719a41c | 2020-12-03 17:50:44 +0800 | [diff] [blame] | 91 | auto sensorData = convertVec(dataIter->second); |
| 92 | if (recordType >= 0xC0 && recordType < 0xE0) |
| 93 | { |
| 94 | record.event.oemCD.timeStamp = static_cast<uint32_t>( |
| 95 | std::chrono::duration_cast<std::chrono::seconds>(timestamp) |
| 96 | .count()); |
| 97 | record.event.oemCD.recordType = recordType; |
| 98 | // The ManufactureID and OEM Defined are packed in the sensor data |
| 99 | // Fill the 9 bytes of Manufacture ID and oemDefined |
| 100 | memcpy(&record.event.oemCD.manufacturerID, sensorData.data(), |
| Lei YU | 07c15b7 | 2020-12-06 15:08:06 +0800 | [diff] [blame] | 101 | std::min(sensorData.size(), static_cast<size_t>(oemCDDataSize))); |
| Lei YU | 719a41c | 2020-12-03 17:50:44 +0800 | [diff] [blame] | 102 | } |
| 103 | else if (recordType >= 0xE0) |
| 104 | { |
| 105 | record.event.oemEF.recordType = recordType; |
| 106 | // The remaining 13 bytes are the OEM Defined data |
| 107 | memcpy(&record.event.oemEF.oemDefined, sensorData.data(), |
| Lei YU | 07c15b7 | 2020-12-06 15:08:06 +0800 | [diff] [blame] | 108 | std::min(sensorData.size(), static_cast<size_t>(oemEFDataSize))); |
| Lei YU | 719a41c | 2020-12-03 17:50:44 +0800 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
| Lei YU | 07c15b7 | 2020-12-06 15:08:06 +0800 | [diff] [blame] | 112 | void constructSEL(uint8_t recordType, std::chrono::milliseconds timestamp, |
| Potin Lai | 0c6561d | 2025-01-16 00:08:52 +0800 | [diff] [blame] | 113 | const AdditionalData& data, const entryDataMap&, |
| Lei YU | 07c15b7 | 2020-12-06 15:08:06 +0800 | [diff] [blame] | 114 | GetSELEntryResponse& record) |
| 115 | { |
| 116 | if (recordType != systemEventRecord) |
| 117 | { |
| George Liu | 7acfcf0 | 2024-07-17 20:14:56 +0800 | [diff] [blame] | 118 | lg2::error("Invalid recordType"); |
| Lei YU | 07c15b7 | 2020-12-06 15:08:06 +0800 | [diff] [blame] | 119 | elog<InternalFailure>(); |
| 120 | } |
| 121 | |
| 122 | // Default values when there is no matched sensor |
| 123 | record.event.eventRecord.sensorType = 0; |
| 124 | record.event.eventRecord.sensorNum = 0xFF; |
| 125 | record.event.eventRecord.eventType = 0; |
| 126 | |
| Potin Lai | 0c6561d | 2025-01-16 00:08:52 +0800 | [diff] [blame] | 127 | auto iter = data.find(strSensorPath); |
| 128 | assert(iter != data.end()); |
| Lei YU | 07c15b7 | 2020-12-06 15:08:06 +0800 | [diff] [blame] | 129 | const auto& sensorPath = iter->second; |
| 130 | auto sensorIter = invSensors.find(sensorPath); |
| 131 | |
| 132 | if (sensorIter != invSensors.end()) |
| 133 | { |
| 134 | // There is a matched sensor |
| 135 | record.event.eventRecord.sensorType = sensorIter->second.sensorType; |
| 136 | record.event.eventRecord.sensorNum = sensorIter->second.sensorID; |
| 137 | |
| Potin Lai | 0c6561d | 2025-01-16 00:08:52 +0800 | [diff] [blame] | 138 | iter = data.find(strEventDir); |
| 139 | assert(iter != data.end()); |
| Lei YU | 07c15b7 | 2020-12-06 15:08:06 +0800 | [diff] [blame] | 140 | auto eventDir = static_cast<uint8_t>(convert(iter->second)); |
| 141 | uint8_t assert = eventDir ? assertEvent : deassertEvent; |
| 142 | record.event.eventRecord.eventType = |
| 143 | assert | sensorIter->second.eventReadingType; |
| 144 | } |
| 145 | record.event.eventRecord.recordType = recordType; |
| 146 | record.event.eventRecord.timeStamp = static_cast<uint32_t>( |
| 147 | std::chrono::duration_cast<std::chrono::seconds>(timestamp).count()); |
| Potin Lai | 0c6561d | 2025-01-16 00:08:52 +0800 | [diff] [blame] | 148 | iter = data.find(strGenerateId); |
| 149 | assert(iter != data.end()); |
| Lei YU | 07c15b7 | 2020-12-06 15:08:06 +0800 | [diff] [blame] | 150 | record.event.eventRecord.generatorID = |
| 151 | static_cast<uint16_t>(convert(iter->second)); |
| 152 | record.event.eventRecord.eventMsgRevision = eventMsgRevision; |
| Potin Lai | 0c6561d | 2025-01-16 00:08:52 +0800 | [diff] [blame] | 153 | iter = data.find(strSensorData); |
| 154 | assert(iter != data.end()); |
| Lei YU | 07c15b7 | 2020-12-06 15:08:06 +0800 | [diff] [blame] | 155 | auto sensorData = convertVec(iter->second); |
| 156 | // The remaining 3 bytes are the sensor data |
| 157 | memcpy(&record.event.eventRecord.eventData1, sensorData.data(), |
| 158 | std::min(sensorData.size(), static_cast<size_t>(selDataSize))); |
| 159 | } |
| 160 | |
| Patrick Williams | 69b4c28 | 2025-03-03 11:19:13 -0500 | [diff] [blame] | 161 | GetSELEntryResponse prepareSELEntry( |
| 162 | const std::string& objPath, |
| 163 | ipmi::sensor::InvObjectIDMap::const_iterator iter) |
| Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 164 | { |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 165 | GetSELEntryResponse record{}; |
| Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 166 | |
| Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 167 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
| Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 168 | auto service = ipmi::getService(bus, logEntryIntf, objPath); |
| 169 | |
| 170 | // Read all the log entry properties. |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 171 | auto methodCall = bus.new_method_call(service.c_str(), objPath.c_str(), |
| 172 | propIntf, "GetAll"); |
| Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 173 | methodCall.append(logEntryIntf); |
| 174 | |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 175 | entryDataMap entryData; |
| 176 | try |
| Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 177 | { |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 178 | auto reply = bus.call(methodCall); |
| 179 | reply.read(entryData); |
| 180 | } |
| 181 | catch (const std::exception& e) |
| 182 | { |
| George Liu | 7acfcf0 | 2024-07-17 20:14:56 +0800 | [diff] [blame] | 183 | lg2::error("Error in reading logging property entries: {ERROR}", |
| 184 | "ERROR", e); |
| Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 185 | elog<InternalFailure>(); |
| 186 | } |
| 187 | |
| Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 188 | // Read Id from the log entry. |
| 189 | static constexpr auto propId = "Id"; |
| 190 | auto iterId = entryData.find(propId); |
| 191 | if (iterId == entryData.end()) |
| 192 | { |
| George Liu | 7acfcf0 | 2024-07-17 20:14:56 +0800 | [diff] [blame] | 193 | lg2::error("Error in reading Id of logging entry"); |
| Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 194 | elog<InternalFailure>(); |
| 195 | } |
| 196 | |
| Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 197 | // Read Timestamp from the log entry. |
| 198 | static constexpr auto propTimeStamp = "Timestamp"; |
| 199 | auto iterTimeStamp = entryData.find(propTimeStamp); |
| 200 | if (iterTimeStamp == entryData.end()) |
| 201 | { |
| George Liu | 7acfcf0 | 2024-07-17 20:14:56 +0800 | [diff] [blame] | 202 | lg2::error("Error in reading Timestamp of logging entry"); |
| Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 203 | elog<InternalFailure>(); |
| 204 | } |
| Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 205 | std::chrono::milliseconds chronoTimeStamp( |
| Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 206 | std::get<uint64_t>(iterTimeStamp->second)); |
| Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 207 | |
| Lei YU | 690f4d5 | 2021-04-28 19:05:24 +0800 | [diff] [blame] | 208 | bool isFromSELLogger = false; |
| Lei YU | 690f4d5 | 2021-04-28 19:05:24 +0800 | [diff] [blame] | 209 | |
| 210 | // The recordID are with the same offset between different types, |
| 211 | // so we are safe to set the recordID here |
| 212 | record.event.eventRecord.recordID = |
| 213 | static_cast<uint16_t>(std::get<uint32_t>(iterId->second)); |
| 214 | |
| 215 | iterId = entryData.find(propAdditionalData); |
| 216 | if (iterId != entryData.end()) |
| 217 | { |
| 218 | // Check if it's a SEL from phosphor-sel-logger which shall contain |
| 219 | // the record ID, etc |
| Patrick Williams | 39deff2 | 2024-12-11 21:12:59 -0500 | [diff] [blame] | 220 | const auto& addData = std::get<AdditionalData>(iterId->second); |
| Patrick Williams | be5a2e0 | 2024-11-22 11:23:17 -0500 | [diff] [blame] | 221 | auto recordTypeIter = addData.find(strRecordType); |
| 222 | if (recordTypeIter != addData.end()) |
| Lei YU | 690f4d5 | 2021-04-28 19:05:24 +0800 | [diff] [blame] | 223 | { |
| 224 | // It is a SEL from phosphor-sel-logger |
| 225 | isFromSELLogger = true; |
| 226 | } |
| 227 | else |
| 228 | { |
| 229 | // Not a SEL from phosphor-sel-logger, it shall have a valid |
| 230 | // invSensor |
| 231 | if (iter == invSensors.end()) |
| 232 | { |
| George Liu | 7acfcf0 | 2024-07-17 20:14:56 +0800 | [diff] [blame] | 233 | lg2::error("System event sensor not found"); |
| Lei YU | 690f4d5 | 2021-04-28 19:05:24 +0800 | [diff] [blame] | 234 | elog<InternalFailure>(); |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | if (isFromSELLogger) |
| Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 240 | { |
| Lei YU | af378fa | 2020-12-02 16:28:57 +0800 | [diff] [blame] | 241 | // It is expected to be a custom SEL entry |
| Potin Lai | 0c6561d | 2025-01-16 00:08:52 +0800 | [diff] [blame] | 242 | const auto& addData = std::get<AdditionalData>(iterId->second); |
| 243 | auto recordType = |
| 244 | static_cast<uint8_t>(convert(addData.find(strRecordType)->second)); |
| Lei YU | 5015e95 | 2020-12-03 14:01:31 +0800 | [diff] [blame] | 245 | auto isOEM = isRecordOEM(recordType); |
| 246 | if (isOEM) |
| 247 | { |
| Potin Lai | 0c6561d | 2025-01-16 00:08:52 +0800 | [diff] [blame] | 248 | constructOEMSEL(recordType, chronoTimeStamp, addData, record); |
| Lei YU | 5015e95 | 2020-12-03 14:01:31 +0800 | [diff] [blame] | 249 | } |
| 250 | else |
| 251 | { |
| Potin Lai | 0c6561d | 2025-01-16 00:08:52 +0800 | [diff] [blame] | 252 | constructSEL(recordType, chronoTimeStamp, addData, entryData, |
| 253 | record); |
| Lei YU | 5015e95 | 2020-12-03 14:01:31 +0800 | [diff] [blame] | 254 | } |
| Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 255 | } |
| 256 | else |
| 257 | { |
| Lei YU | af378fa | 2020-12-02 16:28:57 +0800 | [diff] [blame] | 258 | record.event.eventRecord.timeStamp = static_cast<uint32_t>( |
| 259 | std::chrono::duration_cast<std::chrono::seconds>(chronoTimeStamp) |
| 260 | .count()); |
| 261 | |
| Lei YU | af378fa | 2020-12-02 16:28:57 +0800 | [diff] [blame] | 262 | record.event.eventRecord.recordType = systemEventRecord; |
| 263 | record.event.eventRecord.generatorID = generatorID; |
| 264 | record.event.eventRecord.eventMsgRevision = eventMsgRevision; |
| 265 | |
| 266 | record.event.eventRecord.sensorType = iter->second.sensorType; |
| 267 | record.event.eventRecord.sensorNum = iter->second.sensorID; |
| 268 | record.event.eventRecord.eventData1 = iter->second.eventOffset; |
| 269 | |
| 270 | // Read Resolved from the log entry. |
| Lei YU | af378fa | 2020-12-02 16:28:57 +0800 | [diff] [blame] | 271 | auto iterResolved = entryData.find(propResolved); |
| 272 | if (iterResolved == entryData.end()) |
| 273 | { |
| George Liu | 7acfcf0 | 2024-07-17 20:14:56 +0800 | [diff] [blame] | 274 | lg2::error("Error in reading Resolved field of logging entry"); |
| Lei YU | af378fa | 2020-12-02 16:28:57 +0800 | [diff] [blame] | 275 | elog<InternalFailure>(); |
| 276 | } |
| 277 | |
| Lei YU | af378fa | 2020-12-02 16:28:57 +0800 | [diff] [blame] | 278 | // Evaluate if the event is assertion or deassertion event |
| 279 | if (std::get<bool>(iterResolved->second)) |
| 280 | { |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 281 | record.event.eventRecord.eventType = |
| 282 | deassertEvent | iter->second.eventReadingType; |
| Lei YU | af378fa | 2020-12-02 16:28:57 +0800 | [diff] [blame] | 283 | } |
| 284 | else |
| 285 | { |
| 286 | record.event.eventRecord.eventType = iter->second.eventReadingType; |
| 287 | } |
| Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | return record; |
| 291 | } |
| 292 | |
| 293 | } // namespace internal |
| 294 | |
| Tom Joseph | 6edc8a0 | 2017-06-30 18:52:56 +0530 | [diff] [blame] | 295 | GetSELEntryResponse convertLogEntrytoSEL(const std::string& objPath) |
| 296 | { |
| Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 297 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
| Tom Joseph | 6edc8a0 | 2017-06-30 18:52:56 +0530 | [diff] [blame] | 298 | |
| Vernon Mauery | a7f81cc | 2019-11-06 12:51:43 -0800 | [diff] [blame] | 299 | static constexpr auto assocIntf = |
| 300 | "xyz.openbmc_project.Association.Definitions"; |
| 301 | static constexpr auto assocProp = "Associations"; |
| Tom Joseph | 6edc8a0 | 2017-06-30 18:52:56 +0530 | [diff] [blame] | 302 | |
| George Liu | 42f64ef | 2024-02-05 15:03:18 +0800 | [diff] [blame] | 303 | std::vector<ipmi::Association> assocs; |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 304 | try |
| 305 | { |
| George Liu | 42f64ef | 2024-02-05 15:03:18 +0800 | [diff] [blame] | 306 | auto service = ipmi::getService(bus, assocIntf, objPath); |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 307 | auto propValue = |
| 308 | ipmi::getDbusProperty(bus, service, objPath, assocIntf, assocProp); |
| George Liu | 42f64ef | 2024-02-05 15:03:18 +0800 | [diff] [blame] | 309 | assocs = std::get<std::vector<ipmi::Association>>(propValue); |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 310 | } |
| 311 | catch (const std::exception& e) |
| 312 | { |
| George Liu | 7acfcf0 | 2024-07-17 20:14:56 +0800 | [diff] [blame] | 313 | lg2::error("Error in reading Associations interface: {ERROR}", "ERROR", |
| 314 | e); |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 315 | elog<InternalFailure>(); |
| 316 | } |
| Tom Joseph | 6edc8a0 | 2017-06-30 18:52:56 +0530 | [diff] [blame] | 317 | |
| Tom Joseph | 6edc8a0 | 2017-06-30 18:52:56 +0530 | [diff] [blame] | 318 | /* |
| 319 | * Check if the log entry has any callout associations, if there is a |
| 320 | * callout association try to match the inventory path to the corresponding |
| 321 | * IPMI sensor. |
| 322 | */ |
| 323 | for (const auto& item : assocs) |
| 324 | { |
| 325 | if (std::get<0>(item).compare(CALLOUT_FWD_ASSOCIATION) == 0) |
| 326 | { |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 327 | auto iter = invSensors.find(std::get<2>(item)); |
| 328 | if (iter == invSensors.end()) |
| 329 | { |
| 330 | iter = invSensors.find(BOARD_SENSOR); |
| 331 | if (iter == invSensors.end()) |
| 332 | { |
| George Liu | 7acfcf0 | 2024-07-17 20:14:56 +0800 | [diff] [blame] | 333 | lg2::error("Motherboard sensor not found"); |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 334 | elog<InternalFailure>(); |
| 335 | } |
| 336 | } |
| Tom Joseph | 6edc8a0 | 2017-06-30 18:52:56 +0530 | [diff] [blame] | 337 | |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 338 | return internal::prepareSELEntry(objPath, iter); |
| Tom Joseph | 6edc8a0 | 2017-06-30 18:52:56 +0530 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | |
| 342 | // If there are no callout associations link the log entry to system event |
| 343 | // sensor |
| 344 | auto iter = invSensors.find(SYSTEM_SENSOR); |
| Tom Joseph | 6edc8a0 | 2017-06-30 18:52:56 +0530 | [diff] [blame] | 345 | return internal::prepareSELEntry(objPath, iter); |
| 346 | } |
| 347 | |
| Tom Joseph | 399fd92 | 2017-06-30 18:40:30 +0530 | [diff] [blame] | 348 | std::chrono::seconds getEntryTimeStamp(const std::string& objPath) |
| 349 | { |
| Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 350 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
| Tom Joseph | 399fd92 | 2017-06-30 18:40:30 +0530 | [diff] [blame] | 351 | |
| George Liu | 42f64ef | 2024-02-05 15:03:18 +0800 | [diff] [blame] | 352 | static constexpr auto propTimeStamp = "Timestamp"; |
| Tom Joseph | 399fd92 | 2017-06-30 18:40:30 +0530 | [diff] [blame] | 353 | |
| George Liu | 42f64ef | 2024-02-05 15:03:18 +0800 | [diff] [blame] | 354 | uint64_t timeStamp; |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 355 | try |
| Tom Joseph | 399fd92 | 2017-06-30 18:40:30 +0530 | [diff] [blame] | 356 | { |
| George Liu | 42f64ef | 2024-02-05 15:03:18 +0800 | [diff] [blame] | 357 | auto service = ipmi::getService(bus, logEntryIntf, objPath); |
| 358 | auto propValue = ipmi::getDbusProperty(bus, service, objPath, |
| 359 | logEntryIntf, propTimeStamp); |
| 360 | timeStamp = std::get<uint64_t>(propValue); |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 361 | } |
| 362 | catch (const std::exception& e) |
| 363 | { |
| George Liu | 7acfcf0 | 2024-07-17 20:14:56 +0800 | [diff] [blame] | 364 | lg2::error("Error in reading Timestamp from Entry interface: {ERROR}", |
| 365 | "ERROR", e); |
| Tom Joseph | 399fd92 | 2017-06-30 18:40:30 +0530 | [diff] [blame] | 366 | elog<InternalFailure>(); |
| 367 | } |
| 368 | |
| George Liu | 42f64ef | 2024-02-05 15:03:18 +0800 | [diff] [blame] | 369 | std::chrono::milliseconds chronoTimeStamp(timeStamp); |
| Tom Joseph | 399fd92 | 2017-06-30 18:40:30 +0530 | [diff] [blame] | 370 | |
| 371 | return std::chrono::duration_cast<std::chrono::seconds>(chronoTimeStamp); |
| 372 | } |
| 373 | |
| Tom Joseph | 232f529 | 2017-07-07 20:14:02 +0530 | [diff] [blame] | 374 | void readLoggingObjectPaths(ObjectPaths& paths) |
| 375 | { |
| Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 376 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
| Tom Joseph | 232f529 | 2017-07-07 20:14:02 +0530 | [diff] [blame] | 377 | auto depth = 0; |
| 378 | paths.clear(); |
| 379 | |
| Alexander Hansen | 93aa983 | 2025-11-07 15:29:49 +0100 | [diff] [blame^] | 380 | auto mapperCall = bus.new_method_call( |
| 381 | ObjectMapper::default_service, ObjectMapper::instance_path, |
| 382 | ObjectMapper::interface, |
| 383 | ObjectMapper::method_names::get_sub_tree_paths); |
| Tom Joseph | 232f529 | 2017-07-07 20:14:02 +0530 | [diff] [blame] | 384 | mapperCall.append(logBasePath); |
| 385 | mapperCall.append(depth); |
| 386 | mapperCall.append(ObjectPaths({logEntryIntf})); |
| 387 | |
| Konstantin Aladyshev | 49434b6 | 2022-01-10 16:58:47 +0300 | [diff] [blame] | 388 | try |
| Tom Joseph | 232f529 | 2017-07-07 20:14:02 +0530 | [diff] [blame] | 389 | { |
| Konstantin Aladyshev | 49434b6 | 2022-01-10 16:58:47 +0300 | [diff] [blame] | 390 | auto reply = bus.call(mapperCall); |
| Tom Joseph | 232f529 | 2017-07-07 20:14:02 +0530 | [diff] [blame] | 391 | reply.read(paths); |
| Tom Joseph | 232f529 | 2017-07-07 20:14:02 +0530 | [diff] [blame] | 392 | } |
| Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 393 | catch (const sdbusplus::exception_t& e) |
| Konstantin Aladyshev | 49434b6 | 2022-01-10 16:58:47 +0300 | [diff] [blame] | 394 | { |
| 395 | if (strcmp(e.name(), |
| 396 | "xyz.openbmc_project.Common.Error.ResourceNotFound")) |
| 397 | { |
| 398 | throw; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | std::sort(paths.begin(), paths.end(), |
| 403 | [](const std::string& a, const std::string& b) { |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 404 | namespace fs = std::filesystem; |
| 405 | fs::path pathA(a); |
| 406 | fs::path pathB(b); |
| 407 | auto idA = std::stoul(pathA.filename().string()); |
| 408 | auto idB = std::stoul(pathB.filename().string()); |
| Konstantin Aladyshev | 49434b6 | 2022-01-10 16:58:47 +0300 | [diff] [blame] | 409 | |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 410 | return idA < idB; |
| 411 | }); |
| Tom Joseph | 232f529 | 2017-07-07 20:14:02 +0530 | [diff] [blame] | 412 | } |
| 413 | |
| Tom Joseph | 6b7a143 | 2017-05-19 10:43:36 +0530 | [diff] [blame] | 414 | } // namespace sel |
| 415 | |
| 416 | } // namespace ipmi |