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