Matt Spinler | 711d51d | 2019-11-06 09:36:51 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2019 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 16 | #include "pel.hpp" |
| 17 | |
| 18 | #include "bcd_time.hpp" |
Matt Spinler | c63e2e8 | 2019-12-02 15:50:12 -0600 | [diff] [blame] | 19 | #include "extended_user_header.hpp" |
Matt Spinler | aa65947 | 2019-10-23 09:26:48 -0500 | [diff] [blame] | 20 | #include "failing_mtms.hpp" |
Harisuddin Mohamed Isa | 600d15a | 2019-12-20 12:42:26 +0800 | [diff] [blame] | 21 | #include "json_utils.hpp" |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 22 | #include "log_id.hpp" |
Matt Spinler | f1e85e2 | 2019-11-01 11:31:31 -0500 | [diff] [blame] | 23 | #include "pel_rules.hpp" |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 24 | #include "pel_values.hpp" |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 25 | #include "section_factory.hpp" |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 26 | #include "src.hpp" |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 27 | #include "stream.hpp" |
Matt Spinler | afa857c | 2019-10-24 13:03:46 -0500 | [diff] [blame] | 28 | #include "user_data_formats.hpp" |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 29 | |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 30 | #include <iostream> |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 31 | #include <phosphor-logging/log.hpp> |
| 32 | |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 33 | namespace openpower |
| 34 | { |
| 35 | namespace pels |
| 36 | { |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 37 | namespace message = openpower::pels::message; |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 38 | namespace pv = openpower::pels::pel_values; |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 39 | |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 40 | constexpr auto unknownValue = "Unknown"; |
| 41 | |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 42 | PEL::PEL(const message::Entry& entry, uint32_t obmcLogID, uint64_t timestamp, |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 43 | phosphor::logging::Entry::Level severity, |
Matt Spinler | aa65947 | 2019-10-23 09:26:48 -0500 | [diff] [blame] | 44 | const AdditionalData& additionalData, |
| 45 | const DataInterfaceBase& dataIface) |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 46 | { |
| 47 | _ph = std::make_unique<PrivateHeader>(entry.componentID, obmcLogID, |
| 48 | timestamp); |
| 49 | _uh = std::make_unique<UserHeader>(entry, severity); |
| 50 | |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 51 | auto src = std::make_unique<SRC>(entry, additionalData); |
Matt Spinler | c63e2e8 | 2019-12-02 15:50:12 -0600 | [diff] [blame] | 52 | |
| 53 | auto euh = std::make_unique<ExtendedUserHeader>(dataIface, entry, *src); |
| 54 | |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 55 | _optionalSections.push_back(std::move(src)); |
Matt Spinler | c63e2e8 | 2019-12-02 15:50:12 -0600 | [diff] [blame] | 56 | _optionalSections.push_back(std::move(euh)); |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 57 | |
Matt Spinler | aa65947 | 2019-10-23 09:26:48 -0500 | [diff] [blame] | 58 | auto mtms = std::make_unique<FailingMTMS>(dataIface); |
| 59 | _optionalSections.push_back(std::move(mtms)); |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 60 | |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 61 | auto ud = util::makeSysInfoUserDataSection(additionalData, dataIface); |
| 62 | _optionalSections.push_back(std::move(ud)); |
| 63 | |
Matt Spinler | afa857c | 2019-10-24 13:03:46 -0500 | [diff] [blame] | 64 | if (!additionalData.empty()) |
| 65 | { |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 66 | ud = util::makeADUserDataSection(additionalData); |
Matt Spinler | 6d66382 | 2020-01-22 14:50:46 -0600 | [diff] [blame] | 67 | |
| 68 | // To be safe, check there isn't too much data |
| 69 | if (size() + ud->header().size <= _maxPELSize) |
| 70 | { |
| 71 | _optionalSections.push_back(std::move(ud)); |
| 72 | } |
Matt Spinler | afa857c | 2019-10-24 13:03:46 -0500 | [diff] [blame] | 73 | } |
| 74 | |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 75 | _ph->setSectionCount(2 + _optionalSections.size()); |
Matt Spinler | f1e85e2 | 2019-11-01 11:31:31 -0500 | [diff] [blame] | 76 | |
| 77 | checkRulesAndFix(); |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 78 | } |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 79 | |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 80 | PEL::PEL(std::vector<uint8_t>& data) : PEL(data, 0) |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 81 | { |
| 82 | } |
| 83 | |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 84 | PEL::PEL(std::vector<uint8_t>& data, uint32_t obmcLogID) |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 85 | { |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 86 | populateFromRawData(data, obmcLogID); |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 87 | } |
| 88 | |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 89 | void PEL::populateFromRawData(std::vector<uint8_t>& data, uint32_t obmcLogID) |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 90 | { |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 91 | Stream pelData{data}; |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 92 | _ph = std::make_unique<PrivateHeader>(pelData); |
| 93 | if (obmcLogID != 0) |
| 94 | { |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 95 | _ph->setOBMCLogID(obmcLogID); |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | _uh = std::make_unique<UserHeader>(pelData); |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 99 | |
| 100 | // Use the section factory to create the rest of the objects |
| 101 | for (size_t i = 2; i < _ph->sectionCount(); i++) |
| 102 | { |
| 103 | auto section = section_factory::create(pelData); |
| 104 | _optionalSections.push_back(std::move(section)); |
| 105 | } |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | bool PEL::valid() const |
| 109 | { |
| 110 | bool valid = _ph->valid(); |
| 111 | |
| 112 | if (valid) |
| 113 | { |
| 114 | valid = _uh->valid(); |
| 115 | } |
| 116 | |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 117 | if (valid) |
| 118 | { |
| 119 | if (!std::all_of(_optionalSections.begin(), _optionalSections.end(), |
| 120 | [](const auto& section) { return section->valid(); })) |
| 121 | { |
| 122 | valid = false; |
| 123 | } |
| 124 | } |
| 125 | |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 126 | return valid; |
| 127 | } |
| 128 | |
| 129 | void PEL::setCommitTime() |
| 130 | { |
| 131 | auto now = std::chrono::system_clock::now(); |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 132 | _ph->setCommitTimestamp(getBCDTime(now)); |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | void PEL::assignID() |
| 136 | { |
Matt Spinler | 97d19b4 | 2019-10-29 11:34:03 -0500 | [diff] [blame] | 137 | _ph->setID(generatePELID()); |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 138 | } |
| 139 | |
Matt Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 140 | void PEL::flatten(std::vector<uint8_t>& pelBuffer) const |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 141 | { |
| 142 | Stream pelData{pelBuffer}; |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 143 | |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 144 | if (!valid()) |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 145 | { |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 146 | using namespace phosphor::logging; |
| 147 | log<level::WARNING>("Unflattening an invalid PEL"); |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 148 | } |
| 149 | |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 150 | _ph->flatten(pelData); |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 151 | _uh->flatten(pelData); |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 152 | |
| 153 | for (auto& section : _optionalSections) |
| 154 | { |
| 155 | section->flatten(pelData); |
| 156 | } |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 157 | } |
| 158 | |
Matt Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 159 | std::vector<uint8_t> PEL::data() const |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 160 | { |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 161 | std::vector<uint8_t> pelData; |
| 162 | flatten(pelData); |
| 163 | return pelData; |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 164 | } |
| 165 | |
Matt Spinler | f1b46ff | 2020-01-22 14:10:04 -0600 | [diff] [blame] | 166 | size_t PEL::size() const |
| 167 | { |
| 168 | size_t size = 0; |
| 169 | |
| 170 | if (_ph) |
| 171 | { |
| 172 | size += _ph->header().size; |
| 173 | } |
| 174 | |
| 175 | if (_uh) |
| 176 | { |
| 177 | size += _uh->header().size; |
| 178 | } |
| 179 | |
| 180 | for (const auto& section : _optionalSections) |
| 181 | { |
| 182 | size += section->header().size; |
| 183 | } |
| 184 | |
| 185 | return size; |
| 186 | } |
| 187 | |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 188 | std::optional<SRC*> PEL::primarySRC() const |
| 189 | { |
| 190 | auto src = std::find_if( |
| 191 | _optionalSections.begin(), _optionalSections.end(), [](auto& section) { |
| 192 | return section->header().id == |
| 193 | static_cast<uint16_t>(SectionID::primarySRC); |
| 194 | }); |
| 195 | if (src != _optionalSections.end()) |
| 196 | { |
| 197 | return static_cast<SRC*>(src->get()); |
| 198 | } |
| 199 | |
| 200 | return std::nullopt; |
| 201 | } |
| 202 | |
Matt Spinler | f1e85e2 | 2019-11-01 11:31:31 -0500 | [diff] [blame] | 203 | void PEL::checkRulesAndFix() |
| 204 | { |
| 205 | auto [actionFlags, eventType] = |
| 206 | pel_rules::check(_uh->actionFlags(), _uh->eventType(), _uh->severity()); |
| 207 | |
| 208 | _uh->setActionFlags(actionFlags); |
| 209 | _uh->setEventType(eventType); |
| 210 | } |
| 211 | |
Matt Spinler | acb7c10 | 2020-01-10 13:49:22 -0600 | [diff] [blame] | 212 | void PEL::printSectionInJSON(const Section& section, std::string& buf, |
| 213 | std::map<uint16_t, size_t>& pluralSections) const |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 214 | { |
| 215 | char tmpB[5]; |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 216 | uint8_t id[] = {static_cast<uint8_t>(section.header().id >> 8), |
| 217 | static_cast<uint8_t>(section.header().id)}; |
| 218 | sprintf(tmpB, "%c%c", id[0], id[1]); |
| 219 | std::string sectionID(tmpB); |
| 220 | std::string sectionName = pv::sectionTitles.count(sectionID) |
| 221 | ? pv::sectionTitles.at(sectionID) |
| 222 | : "Unknown Section"; |
Matt Spinler | acb7c10 | 2020-01-10 13:49:22 -0600 | [diff] [blame] | 223 | |
| 224 | // Add a count if there are multiple of this type of section |
| 225 | auto count = pluralSections.find(section.header().id); |
| 226 | if (count != pluralSections.end()) |
| 227 | { |
| 228 | sectionName += " " + std::to_string(count->second); |
| 229 | count->second++; |
| 230 | } |
| 231 | |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 232 | if (section.valid()) |
| 233 | { |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 234 | auto json = section.getJSON(); |
| 235 | if (json) |
| 236 | { |
Harisuddin Mohamed Isa | 600d15a | 2019-12-20 12:42:26 +0800 | [diff] [blame] | 237 | buf += "\n\"" + sectionName + "\": {\n"; |
| 238 | buf += *json + "\n},\n"; |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 239 | } |
| 240 | else |
| 241 | { |
Harisuddin Mohamed Isa | 600d15a | 2019-12-20 12:42:26 +0800 | [diff] [blame] | 242 | buf += "\n\"" + sectionName + "\": [\n"; |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 243 | std::vector<uint8_t> data; |
| 244 | Stream s{data}; |
| 245 | section.flatten(s); |
| 246 | std::string dstr = dumpHex(std::data(data), data.size()); |
| 247 | buf += dstr + "],\n"; |
| 248 | } |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 249 | } |
| 250 | else |
| 251 | { |
Harisuddin Mohamed Isa | 600d15a | 2019-12-20 12:42:26 +0800 | [diff] [blame] | 252 | buf += "\n\"Invalid Section\": [\n \"invalid\"\n],\n"; |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
Matt Spinler | acb7c10 | 2020-01-10 13:49:22 -0600 | [diff] [blame] | 256 | std::map<uint16_t, size_t> PEL::getPluralSections() const |
| 257 | { |
| 258 | std::map<uint16_t, size_t> sectionCounts; |
| 259 | |
| 260 | for (const auto& section : optionalSections()) |
| 261 | { |
| 262 | if (sectionCounts.find(section->header().id) == sectionCounts.end()) |
| 263 | { |
| 264 | sectionCounts[section->header().id] = 1; |
| 265 | } |
| 266 | else |
| 267 | { |
| 268 | sectionCounts[section->header().id]++; |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | std::map<uint16_t, size_t> sections; |
| 273 | for (const auto& [id, count] : sectionCounts) |
| 274 | { |
| 275 | if (count > 1) |
| 276 | { |
| 277 | // Start with 0 here and printSectionInJSON() |
| 278 | // will increment it as it goes. |
| 279 | sections.emplace(id, 0); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | return sections; |
| 284 | } |
| 285 | |
Matt Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 286 | void PEL::toJSON() const |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 287 | { |
Matt Spinler | acb7c10 | 2020-01-10 13:49:22 -0600 | [diff] [blame] | 288 | auto sections = getPluralSections(); |
| 289 | |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 290 | std::string buf = "{"; |
Matt Spinler | acb7c10 | 2020-01-10 13:49:22 -0600 | [diff] [blame] | 291 | printSectionInJSON(*(_ph.get()), buf, sections); |
| 292 | printSectionInJSON(*(_uh.get()), buf, sections); |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 293 | for (auto& section : this->optionalSections()) |
| 294 | { |
Matt Spinler | acb7c10 | 2020-01-10 13:49:22 -0600 | [diff] [blame] | 295 | printSectionInJSON(*(section.get()), buf, sections); |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 296 | } |
| 297 | buf += "}"; |
| 298 | std::size_t found = buf.rfind(","); |
| 299 | if (found != std::string::npos) |
| 300 | buf.replace(found, 1, ""); |
| 301 | std::cout << buf << std::endl; |
| 302 | } |
Harisuddin Mohamed Isa | 600d15a | 2019-12-20 12:42:26 +0800 | [diff] [blame] | 303 | |
Matt Spinler | c7c3e40 | 2020-01-22 15:07:25 -0600 | [diff] [blame] | 304 | namespace util |
| 305 | { |
| 306 | |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 307 | std::unique_ptr<UserData> makeJSONUserDataSection(const nlohmann::json& json) |
| 308 | { |
| 309 | auto jsonString = json.dump(); |
| 310 | std::vector<uint8_t> jsonData(jsonString.begin(), jsonString.end()); |
| 311 | |
| 312 | // Pad to a 4 byte boundary |
| 313 | while ((jsonData.size() % 4) != 0) |
| 314 | { |
| 315 | jsonData.push_back(0); |
| 316 | } |
| 317 | |
| 318 | return std::make_unique<UserData>( |
| 319 | static_cast<uint16_t>(ComponentID::phosphorLogging), |
| 320 | static_cast<uint8_t>(UserDataFormat::json), |
| 321 | static_cast<uint8_t>(UserDataFormatVersion::json), jsonData); |
| 322 | } |
| 323 | |
Matt Spinler | c7c3e40 | 2020-01-22 15:07:25 -0600 | [diff] [blame] | 324 | std::unique_ptr<UserData> makeADUserDataSection(const AdditionalData& ad) |
| 325 | { |
| 326 | assert(!ad.empty()); |
| 327 | nlohmann::json json; |
| 328 | |
| 329 | // Remove the 'ESEL' entry, as it contains a full PEL in the value. |
| 330 | if (ad.getValue("ESEL")) |
| 331 | { |
| 332 | auto newAD = ad; |
| 333 | newAD.remove("ESEL"); |
| 334 | json = newAD.toJSON(); |
| 335 | } |
| 336 | else |
| 337 | { |
| 338 | json = ad.toJSON(); |
| 339 | } |
| 340 | |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 341 | return makeJSONUserDataSection(json); |
| 342 | } |
Matt Spinler | c7c3e40 | 2020-01-22 15:07:25 -0600 | [diff] [blame] | 343 | |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 344 | void addProcessNameToJSON(nlohmann::json& json, |
| 345 | const std::optional<std::string>& pid, |
| 346 | const DataInterfaceBase& dataIface) |
| 347 | { |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 348 | std::string name{unknownValue}; |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 349 | |
| 350 | try |
Matt Spinler | c7c3e40 | 2020-01-22 15:07:25 -0600 | [diff] [blame] | 351 | { |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 352 | if (pid) |
| 353 | { |
| 354 | auto n = dataIface.getProcessName(*pid); |
| 355 | if (n) |
| 356 | { |
| 357 | name = *n; |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | catch (std::exception& e) |
| 362 | { |
Matt Spinler | c7c3e40 | 2020-01-22 15:07:25 -0600 | [diff] [blame] | 363 | } |
| 364 | |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 365 | json["Process Name"] = std::move(name); |
| 366 | } |
| 367 | |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 368 | void addBMCFWVersionIDToJSON(nlohmann::json& json, |
| 369 | const DataInterfaceBase& dataIface) |
| 370 | { |
| 371 | auto id = dataIface.getBMCFWVersionID(); |
| 372 | if (id.empty()) |
| 373 | { |
| 374 | id = unknownValue; |
| 375 | } |
| 376 | |
| 377 | json["BMC Version ID"] = std::move(id); |
| 378 | } |
| 379 | |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 380 | std::string lastSegment(char separator, std::string data) |
| 381 | { |
| 382 | auto pos = data.find_last_of(separator); |
| 383 | if (pos != std::string::npos) |
| 384 | { |
| 385 | data = data.substr(pos + 1); |
| 386 | } |
| 387 | |
| 388 | return data; |
| 389 | } |
| 390 | |
| 391 | void addStatesToJSON(nlohmann::json& json, const DataInterfaceBase& dataIface) |
| 392 | { |
| 393 | json["BMCState"] = lastSegment('.', dataIface.getBMCState()); |
| 394 | json["ChassisState"] = lastSegment('.', dataIface.getChassisState()); |
| 395 | json["HostState"] = lastSegment('.', dataIface.getHostState()); |
| 396 | } |
| 397 | |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 398 | std::unique_ptr<UserData> |
| 399 | makeSysInfoUserDataSection(const AdditionalData& ad, |
| 400 | const DataInterfaceBase& dataIface) |
| 401 | { |
| 402 | nlohmann::json json; |
| 403 | |
| 404 | addProcessNameToJSON(json, ad.getValue("_PID"), dataIface); |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 405 | addBMCFWVersionIDToJSON(json, dataIface); |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 406 | addStatesToJSON(json, dataIface); |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 407 | |
| 408 | return makeJSONUserDataSection(json); |
Matt Spinler | c7c3e40 | 2020-01-22 15:07:25 -0600 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | } // namespace util |
| 412 | |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 413 | } // namespace pels |
| 414 | } // namespace openpower |