Jim Wright | 930458c | 2022-01-24 14:37:27 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2021 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 | */ |
| 16 | |
| 17 | #include "power_sequencer_monitor.hpp" |
| 18 | |
| 19 | #include <fmt/format.h> |
| 20 | |
| 21 | #include <phosphor-logging/elog.hpp> |
| 22 | #include <phosphor-logging/log.hpp> |
| 23 | |
| 24 | #include <exception> |
| 25 | #include <map> |
| 26 | |
| 27 | namespace phosphor::power::sequencer |
| 28 | { |
| 29 | |
| 30 | using namespace phosphor::logging; |
| 31 | |
| 32 | PowerSequencerMonitor::PowerSequencerMonitor(sdbusplus::bus::bus& bus) : |
| 33 | bus(bus) |
| 34 | {} |
| 35 | |
| 36 | void PowerSequencerMonitor::logError( |
| 37 | const std::string& message, |
| 38 | std::map<std::string, std::string>& additionalData) |
| 39 | { |
| 40 | try |
| 41 | { |
| 42 | auto method = bus.new_method_call( |
| 43 | "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", |
| 44 | "xyz.openbmc_project.Logging.Create", "Create"); |
| 45 | |
| 46 | // Add PID to AdditionalData |
| 47 | additionalData.emplace("_PID", std::to_string(getpid())); |
| 48 | |
| 49 | method.append(message, |
| 50 | sdbusplus::xyz::openbmc_project::Logging::server::Entry:: |
| 51 | Level::Critical, |
| 52 | additionalData); |
| 53 | bus.call_noreply(method); |
| 54 | } |
| 55 | catch (const std::exception& e) |
| 56 | { |
| 57 | log<level::ERR>( |
| 58 | fmt::format("Unable to log error, message: {}, error {}", message, |
| 59 | e.what()) |
| 60 | .c_str()); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | void PowerSequencerMonitor::onFailure(bool timeout, |
| 65 | const std::string& powerSupplyError) |
| 66 | { |
| 67 | std::map<std::string, std::string> additionalData{}; |
| 68 | if (!powerSupplyError.empty()) |
| 69 | { |
| 70 | // Default to power supply error |
| 71 | logError(powerSupplyError, additionalData); |
| 72 | } |
| 73 | else if (timeout) |
| 74 | { |
| 75 | // Default to timeout error |
| 76 | logError("xyz.openbmc_project.Power.Error.PowerOnTimeout", |
| 77 | additionalData); |
| 78 | } |
| 79 | else |
| 80 | { |
| 81 | // Default to generic pgood error |
| 82 | logError("xyz.openbmc_project.Power.Error.Shutdown", additionalData); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | } // namespace phosphor::power::sequencer |