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