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