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