blob: 3c8f999b2ba305f6a73573dc427af37cf907bda5 [file] [log] [blame]
Jim Wright930458c2022-01-24 14:37:27 -06001/**
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>
Jim Wright930458c2022-01-24 14:37:27 -060025
26namespace phosphor::power::sequencer
27{
28
29using namespace phosphor::logging;
30
Patrick Williams7354ce62022-07-22 19:26:56 -050031PowerSequencerMonitor::PowerSequencerMonitor(sdbusplus::bus_t& bus) : bus(bus)
Jim Wright930458c2022-01-24 14:37:27 -060032{}
33
Jim Wright213ffe92022-06-03 08:54:30 -050034void PowerSequencerMonitor::createBmcDump()
35{
36 try
37 {
38 auto method = bus.new_method_call(
39 "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump/bmc",
40 "xyz.openbmc_project.Dump.Create", "CreateDump");
41 method.append(
42 std::vector<
43 std::pair<std::string, std::variant<std::string, uint64_t>>>());
44 bus.call_noreply(method);
45 }
Jim Wrightc91eed02022-07-22 11:27:06 -050046 catch (const std::exception& e)
Jim Wright213ffe92022-06-03 08:54:30 -050047 {
48 log<level::ERR>(
Jim Wrightc91eed02022-07-22 11:27:06 -050049 fmt::format("Unable to create dump, error: {}", e.what()).c_str());
Jim Wright213ffe92022-06-03 08:54:30 -050050 }
51}
52
Jim Wright930458c2022-01-24 14:37:27 -060053void PowerSequencerMonitor::logError(
54 const std::string& message,
55 std::map<std::string, std::string>& additionalData)
56{
57 try
58 {
59 auto method = bus.new_method_call(
60 "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
61 "xyz.openbmc_project.Logging.Create", "Create");
62
63 // Add PID to AdditionalData
64 additionalData.emplace("_PID", std::to_string(getpid()));
Jim Wright7f20c5d2022-02-28 20:49:39 -060065 // Set as system terminating
66 additionalData.emplace("SEVERITY_DETAIL", "SYSTEM_TERM");
Jim Wright930458c2022-01-24 14:37:27 -060067
68 method.append(message,
69 sdbusplus::xyz::openbmc_project::Logging::server::Entry::
70 Level::Critical,
71 additionalData);
72 bus.call_noreply(method);
73 }
74 catch (const std::exception& e)
75 {
76 log<level::ERR>(
Jim Wrightc91eed02022-07-22 11:27:06 -050077 fmt::format("Unable to log error, message: {}, error: {}", message,
Jim Wright930458c2022-01-24 14:37:27 -060078 e.what())
79 .c_str());
80 }
81}
82
83void PowerSequencerMonitor::onFailure(bool timeout,
84 const std::string& powerSupplyError)
85{
86 std::map<std::string, std::string> additionalData{};
87 if (!powerSupplyError.empty())
88 {
89 // Default to power supply error
90 logError(powerSupplyError, additionalData);
91 }
92 else if (timeout)
93 {
94 // Default to timeout error
Jim Wrightc48551a2022-12-22 15:43:14 -060095 logError(powerOnTimeoutError, additionalData);
Jim Wright930458c2022-01-24 14:37:27 -060096 }
97 else
98 {
99 // Default to generic pgood error
Jim Wrightc48551a2022-12-22 15:43:14 -0600100 logError(shutdownError, additionalData);
Jim Wright930458c2022-01-24 14:37:27 -0600101 }
Jim Wright213ffe92022-06-03 08:54:30 -0500102 if (!timeout)
103 {
104 createBmcDump();
105 }
Jim Wright930458c2022-01-24 14:37:27 -0600106}
107
108} // namespace phosphor::power::sequencer