Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2019 Intel 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 | */ |
| 16 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 17 | #include <PSUEvent.hpp> |
Ed Tanous | 6cb732a | 2021-02-18 15:33:51 -0800 | [diff] [blame] | 18 | #include <SensorPaths.hpp> |
James Feist | 8086aba | 2020-08-25 16:00:59 -0700 | [diff] [blame] | 19 | #include <boost/asio/io_service.hpp> |
| 20 | #include <boost/asio/read_until.hpp> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 21 | #include <boost/container/flat_map.hpp> |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 22 | #include <phosphor-logging/lg2.hpp> |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 23 | #include <sdbusplus/asio/connection.hpp> |
| 24 | #include <sdbusplus/asio/object_server.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 25 | |
| 26 | #include <iostream> |
| 27 | #include <memory> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 28 | #include <stdexcept> |
| 29 | #include <string> |
| 30 | #include <utility> |
| 31 | #include <variant> |
| 32 | #include <vector> |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 33 | |
| 34 | PSUCombineEvent::PSUCombineEvent( |
Yong Li | 3046a02 | 2020-04-03 13:01:02 +0800 | [diff] [blame] | 35 | sdbusplus::asio::object_server& objectServer, |
| 36 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 37 | boost::asio::io_service& io, const std::string& psuName, |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 38 | const PowerState& powerState, |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 39 | boost::container::flat_map<std::string, std::vector<std::string>>& |
| 40 | eventPathList, |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 41 | boost::container::flat_map< |
| 42 | std::string, |
| 43 | boost::container::flat_map<std::string, std::vector<std::string>>>& |
| 44 | groupEventPathList, |
Lei YU | 7170a23 | 2021-02-04 16:19:27 +0800 | [diff] [blame] | 45 | const std::string& combineEventName, double pollRate) : |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 46 | objServer(objectServer) |
| 47 | { |
Ed Tanous | 6cb732a | 2021-02-18 15:33:51 -0800 | [diff] [blame] | 48 | std::string psuNameEscaped = sensor_paths::escapePathForDbus(psuName); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 49 | eventInterface = objServer.add_interface( |
Ed Tanous | 6cb732a | 2021-02-18 15:33:51 -0800 | [diff] [blame] | 50 | "/xyz/openbmc_project/State/Decorator/" + psuNameEscaped + "_" + |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 51 | combineEventName, |
| 52 | "xyz.openbmc_project.State.Decorator.OperationalStatus"); |
James Feist | b6c0b91 | 2019-07-09 12:21:44 -0700 | [diff] [blame] | 53 | eventInterface->register_property("functional", true); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 54 | |
| 55 | if (!eventInterface->initialize()) |
| 56 | { |
| 57 | std::cerr << "error initializing event interface\n"; |
| 58 | } |
| 59 | |
| 60 | std::shared_ptr<std::set<std::string>> combineEvent = |
| 61 | std::make_shared<std::set<std::string>>(); |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 62 | for (const auto& [eventName, paths] : eventPathList) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 63 | { |
Yong Li | 591b1e4 | 2019-12-19 17:46:31 +0800 | [diff] [blame] | 64 | std::shared_ptr<std::set<std::string>> assert = |
| 65 | std::make_shared<std::set<std::string>>(); |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 66 | std::shared_ptr<bool> state = std::make_shared<bool>(false); |
Yong Li | 591b1e4 | 2019-12-19 17:46:31 +0800 | [diff] [blame] | 67 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 68 | std::string eventPSUName = eventName + psuName; |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 69 | for (const auto& path : paths) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 70 | { |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 71 | auto p = std::make_shared<PSUSubEvent>( |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 72 | eventInterface, path, conn, io, powerState, eventName, |
| 73 | eventName, assert, combineEvent, state, psuName, pollRate); |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 74 | p->setupRead(); |
| 75 | |
| 76 | events[eventPSUName].emplace_back(p); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 77 | asserts.emplace_back(assert); |
| 78 | states.emplace_back(state); |
| 79 | } |
| 80 | } |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 81 | |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 82 | for (const auto& [eventName, groupEvents] : groupEventPathList) |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 83 | { |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 84 | for (const auto& [groupEventName, paths] : groupEvents) |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 85 | { |
| 86 | std::shared_ptr<std::set<std::string>> assert = |
| 87 | std::make_shared<std::set<std::string>>(); |
| 88 | std::shared_ptr<bool> state = std::make_shared<bool>(false); |
| 89 | |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 90 | std::string eventPSUName = groupEventName + psuName; |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 91 | for (const auto& path : paths) |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 92 | { |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 93 | auto p = std::make_shared<PSUSubEvent>( |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 94 | eventInterface, path, conn, io, powerState, groupEventName, |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 95 | eventName, assert, combineEvent, state, psuName, pollRate); |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 96 | p->setupRead(); |
| 97 | events[eventPSUName].emplace_back(p); |
| 98 | |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 99 | asserts.emplace_back(assert); |
| 100 | states.emplace_back(state); |
| 101 | } |
| 102 | } |
| 103 | } |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | PSUCombineEvent::~PSUCombineEvent() |
| 107 | { |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 108 | // Clear unique_ptr first |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 109 | for (auto& [psuName, subEvents] : events) |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 110 | { |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 111 | for (auto& subEventPtr : subEvents) |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 112 | { |
| 113 | subEventPtr.reset(); |
| 114 | } |
| 115 | } |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 116 | events.clear(); |
| 117 | objServer.remove_interface(eventInterface); |
| 118 | } |
| 119 | |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 120 | static boost::container::flat_map<std::string, |
| 121 | std::pair<std::string, std::string>> |
| 122 | logID = { |
| 123 | {"PredictiveFailure", |
| 124 | {"OpenBMC.0.1.PowerSupplyFailurePredicted", |
| 125 | "OpenBMC.0.1.PowerSupplyPredictedFailureRecovered"}}, |
| 126 | {"Failure", |
| 127 | {"OpenBMC.0.1.PowerSupplyFailed", "OpenBMC.0.1.PowerSupplyRecovered"}}, |
| 128 | {"ACLost", |
Cheng C Yang | bb732ef | 2019-09-18 16:25:58 +0800 | [diff] [blame] | 129 | {"OpenBMC.0.1.PowerSupplyPowerLost", |
| 130 | "OpenBMC.0.1.PowerSupplyPowerRestored"}}, |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 131 | {"FanFault", |
| 132 | {"OpenBMC.0.1.PowerSupplyFanFailed", |
| 133 | "OpenBMC.0.1.PowerSupplyFanRecovered"}}, |
jayaprakash Mutyala | d12f23e | 2019-12-03 23:03:52 +0000 | [diff] [blame] | 134 | {"ConfigureError", |
| 135 | {"OpenBMC.0.1.PowerSupplyConfigurationError", |
| 136 | "OpenBMC.0.1.PowerSupplyConfigurationErrorRecovered"}}}; |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 137 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 138 | PSUSubEvent::PSUSubEvent( |
| 139 | std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface, |
Yong Li | 3046a02 | 2020-04-03 13:01:02 +0800 | [diff] [blame] | 140 | const std::string& path, std::shared_ptr<sdbusplus::asio::connection>& conn, |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 141 | boost::asio::io_service& io, const PowerState& powerState, |
| 142 | const std::string& groupEventName, const std::string& eventName, |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 143 | std::shared_ptr<std::set<std::string>> asserts, |
| 144 | std::shared_ptr<std::set<std::string>> combineEvent, |
Lei YU | 7170a23 | 2021-02-04 16:19:27 +0800 | [diff] [blame] | 145 | std::shared_ptr<bool> state, const std::string& psuName, double pollRate) : |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 146 | eventInterface(std::move(eventInterface)), |
| 147 | asserts(std::move(asserts)), combineEvent(std::move(combineEvent)), |
| 148 | assertState(std::move(state)), path(path), eventName(eventName), |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 149 | readState(powerState), waitTimer(io), |
| 150 | |
| 151 | inputDev(io, path, boost::asio::random_access_file::read_only), |
| 152 | psuName(psuName), groupEventName(groupEventName), systemBus(conn) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 153 | { |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 154 | buffer = std::make_shared<std::array<char, 128>>(); |
Lei YU | 7170a23 | 2021-02-04 16:19:27 +0800 | [diff] [blame] | 155 | if (pollRate > 0.0) |
| 156 | { |
| 157 | eventPollMs = static_cast<unsigned int>(pollRate * 1000); |
| 158 | } |
Ed Tanous | 99c4409 | 2022-01-14 09:59:09 -0800 | [diff] [blame] | 159 | |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 160 | auto found = logID.find(eventName); |
| 161 | if (found == logID.end()) |
| 162 | { |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 163 | assertMessage.clear(); |
| 164 | deassertMessage.clear(); |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 165 | } |
| 166 | else |
| 167 | { |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 168 | assertMessage = found->second.first; |
| 169 | deassertMessage = found->second.second; |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | auto fanPos = path.find("fan"); |
| 173 | if (fanPos != std::string::npos) |
| 174 | { |
| 175 | fanName = path.substr(fanPos); |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 176 | auto fanNamePos = fanName.find('_'); |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 177 | if (fanNamePos != std::string::npos) |
| 178 | { |
| 179 | fanName = fanName.substr(0, fanNamePos); |
| 180 | } |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 181 | } |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 182 | } |
| 183 | |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 184 | PSUSubEvent::~PSUSubEvent() |
| 185 | { |
| 186 | waitTimer.cancel(); |
| 187 | inputDev.close(); |
| 188 | } |
| 189 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 190 | void PSUSubEvent::setupRead(void) |
| 191 | { |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 192 | if (!readingStateGood(readState)) |
| 193 | { |
| 194 | // Deassert the event |
| 195 | updateValue(0); |
| 196 | restartRead(); |
| 197 | return; |
| 198 | } |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 199 | if (!buffer) |
| 200 | { |
| 201 | std::cerr << "Buffer was invalid?"; |
| 202 | return; |
| 203 | } |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 204 | |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 205 | std::weak_ptr<PSUSubEvent> weakRef = weak_from_this(); |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 206 | inputDev.async_read_some_at( |
| 207 | 0, boost::asio::buffer(buffer->data(), buffer->size() - 1), |
| 208 | [weakRef, buffer{buffer}](const boost::system::error_code& ec, |
| 209 | std::size_t bytesTransferred) { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 210 | std::shared_ptr<PSUSubEvent> self = weakRef.lock(); |
| 211 | if (self) |
| 212 | { |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 213 | self->handleResponse(ec, bytesTransferred); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 214 | } |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 215 | }); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 216 | } |
| 217 | |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 218 | void PSUSubEvent::restartRead() |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 219 | { |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 220 | std::weak_ptr<PSUSubEvent> weakRef = weak_from_this(); |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 221 | waitTimer.expires_from_now(std::chrono::milliseconds(eventPollMs)); |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 222 | waitTimer.async_wait([weakRef](const boost::system::error_code& ec) { |
| 223 | if (ec == boost::asio::error::operation_aborted) |
| 224 | { |
| 225 | return; |
| 226 | } |
| 227 | std::shared_ptr<PSUSubEvent> self = weakRef.lock(); |
| 228 | if (self) |
| 229 | { |
| 230 | self->setupRead(); |
| 231 | } |
| 232 | }); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 233 | } |
| 234 | |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 235 | void PSUSubEvent::handleResponse(const boost::system::error_code& err, |
| 236 | size_t bytesTransferred) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 237 | { |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 238 | if (err == boost::asio::error::operation_aborted) |
| 239 | { |
| 240 | return; |
| 241 | } |
| 242 | |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 243 | if ((err == boost::system::errc::bad_file_descriptor) || |
| 244 | (err == boost::asio::error::misc_errors::not_found)) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 245 | { |
| 246 | return; |
| 247 | } |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 248 | if (!buffer) |
| 249 | { |
| 250 | std::cerr << "Buffer was invalid?"; |
| 251 | return; |
| 252 | } |
| 253 | // null terminate the string so we don't walk off the end |
| 254 | std::array<char, 128>& bufferRef = *buffer; |
| 255 | bufferRef[bytesTransferred] = '\0'; |
| 256 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 257 | if (!err) |
| 258 | { |
| 259 | std::string response; |
| 260 | try |
| 261 | { |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 262 | int nvalue = std::stoi(bufferRef.data()); |
Josh Lehan | 833661a | 2020-03-04 17:35:41 -0800 | [diff] [blame] | 263 | updateValue(nvalue); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 264 | errCount = 0; |
| 265 | } |
| 266 | catch (const std::invalid_argument&) |
| 267 | { |
| 268 | errCount++; |
| 269 | } |
| 270 | } |
| 271 | else |
| 272 | { |
| 273 | errCount++; |
| 274 | } |
| 275 | if (errCount >= warnAfterErrorCount) |
| 276 | { |
| 277 | if (errCount == warnAfterErrorCount) |
| 278 | { |
| 279 | std::cerr << "Failure to read event at " << path << "\n"; |
| 280 | } |
| 281 | updateValue(0); |
| 282 | errCount++; |
| 283 | } |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 284 | restartRead(); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | // Any of the sub events of one event is asserted, then the event will be |
| 288 | // asserted. Only if none of the sub events are asserted, the event will be |
| 289 | // deasserted. |
| 290 | void PSUSubEvent::updateValue(const int& newValue) |
| 291 | { |
Josh Lehan | 833661a | 2020-03-04 17:35:41 -0800 | [diff] [blame] | 292 | // Take no action if value already equal |
| 293 | // Same semantics as Sensor::updateValue(const double&) |
| 294 | if (newValue == value) |
| 295 | { |
| 296 | return; |
| 297 | } |
| 298 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 299 | if (newValue == 0) |
| 300 | { |
Yong Li | 591b1e4 | 2019-12-19 17:46:31 +0800 | [diff] [blame] | 301 | // log deassert only after all asserts are gone |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 302 | if (!(*asserts).empty()) |
| 303 | { |
Yong Li | 591b1e4 | 2019-12-19 17:46:31 +0800 | [diff] [blame] | 304 | auto found = (*asserts).find(path); |
| 305 | if (found == (*asserts).end()) |
| 306 | { |
| 307 | return; |
| 308 | } |
| 309 | (*asserts).erase(path); |
| 310 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 311 | return; |
| 312 | } |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 313 | if (*assertState) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 314 | { |
| 315 | *assertState = false; |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 316 | auto foundCombine = (*combineEvent).find(groupEventName); |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 317 | if (foundCombine == (*combineEvent).end()) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 318 | { |
| 319 | return; |
| 320 | } |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 321 | (*combineEvent).erase(groupEventName); |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 322 | if (!deassertMessage.empty()) |
| 323 | { |
| 324 | // Fan Failed has two args |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 325 | if (deassertMessage == "OpenBMC.0.1.PowerSupplyFanRecovered") |
| 326 | { |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 327 | lg2::info("{EVENT} deassert", "EVENT", eventName, |
| 328 | "REDFISH_MESSAGE_ID", deassertMessage, |
| 329 | "REDFISH_MESSAGE_ARGS", |
| 330 | (psuName + ',' + fanName)); |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 331 | } |
| 332 | else |
| 333 | { |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 334 | lg2::info("{EVENT} deassert", "EVENT", eventName, |
| 335 | "REDFISH_MESSAGE_ID", deassertMessage, |
| 336 | "REDFISH_MESSAGE_ARGS", psuName); |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 340 | if ((*combineEvent).empty()) |
| 341 | { |
| 342 | eventInterface->set_property("functional", true); |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | else |
| 347 | { |
Paul Fertser | 3453354 | 2021-07-20 08:29:09 +0000 | [diff] [blame] | 348 | std::cerr << "PSUSubEvent asserted by " << path << "\n"; |
| 349 | |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 350 | if ((!*assertState) && ((*asserts).empty())) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 351 | { |
| 352 | *assertState = true; |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 353 | if (!assertMessage.empty()) |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 354 | { |
| 355 | // Fan Failed has two args |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 356 | if (assertMessage == "OpenBMC.0.1.PowerSupplyFanFailed") |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 357 | { |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 358 | lg2::warning("{EVENT} assert", "EVENT", eventName, |
| 359 | "REDFISH_MESSAGE_ID", assertMessage, |
| 360 | "REDFISH_MESSAGE_ARGS", |
| 361 | (psuName + ',' + fanName)); |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 362 | } |
| 363 | else |
| 364 | { |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 365 | lg2::warning("{EVENT} assert", "EVENT", eventName, |
| 366 | "REDFISH_MESSAGE_ID", assertMessage, |
| 367 | "REDFISH_MESSAGE_ARGS", psuName); |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 368 | } |
| 369 | } |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 370 | if ((*combineEvent).empty()) |
| 371 | { |
| 372 | eventInterface->set_property("functional", false); |
| 373 | } |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 374 | (*combineEvent).emplace(groupEventName); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 375 | } |
Yong Li | 591b1e4 | 2019-12-19 17:46:31 +0800 | [diff] [blame] | 376 | (*asserts).emplace(path); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 377 | } |
| 378 | value = newValue; |
| 379 | } |