blob: 603dae104f1823aa74f68f943e25e209976224ad [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>
25#include <map>
26
27namespace phosphor::power::sequencer
28{
29
30using namespace phosphor::logging;
31
Patrick Williams7354ce62022-07-22 19:26:56 -050032PowerSequencerMonitor::PowerSequencerMonitor(sdbusplus::bus_t& bus) : bus(bus)
Jim Wright930458c2022-01-24 14:37:27 -060033{}
34
Jim Wright213ffe92022-06-03 08:54:30 -050035void PowerSequencerMonitor::createBmcDump()
36{
37 try
38 {
39 auto method = bus.new_method_call(
40 "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump/bmc",
41 "xyz.openbmc_project.Dump.Create", "CreateDump");
42 method.append(
43 std::vector<
44 std::pair<std::string, std::variant<std::string, uint64_t>>>());
45 bus.call_noreply(method);
46 }
Jim Wrightc91eed02022-07-22 11:27:06 -050047 catch (const std::exception& e)
Jim Wright213ffe92022-06-03 08:54:30 -050048 {
49 log<level::ERR>(
Jim Wrightc91eed02022-07-22 11:27:06 -050050 fmt::format("Unable to create dump, error: {}", e.what()).c_str());
Jim Wright213ffe92022-06-03 08:54:30 -050051 }
52}
53
Jim Wright930458c2022-01-24 14:37:27 -060054void PowerSequencerMonitor::logError(
55 const std::string& message,
56 std::map<std::string, std::string>& additionalData)
57{
58 try
59 {
60 auto method = bus.new_method_call(
61 "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
62 "xyz.openbmc_project.Logging.Create", "Create");
63
64 // Add PID to AdditionalData
65 additionalData.emplace("_PID", std::to_string(getpid()));
Jim Wright7f20c5d2022-02-28 20:49:39 -060066 // Set as system terminating
67 additionalData.emplace("SEVERITY_DETAIL", "SYSTEM_TERM");
Jim Wright930458c2022-01-24 14:37:27 -060068
69 method.append(message,
70 sdbusplus::xyz::openbmc_project::Logging::server::Entry::
71 Level::Critical,
72 additionalData);
73 bus.call_noreply(method);
74 }
75 catch (const std::exception& e)
76 {
77 log<level::ERR>(
Jim Wrightc91eed02022-07-22 11:27:06 -050078 fmt::format("Unable to log error, message: {}, error: {}", message,
Jim Wright930458c2022-01-24 14:37:27 -060079 e.what())
80 .c_str());
81 }
82}
83
84void PowerSequencerMonitor::onFailure(bool timeout,
85 const std::string& powerSupplyError)
86{
87 std::map<std::string, std::string> additionalData{};
88 if (!powerSupplyError.empty())
89 {
90 // Default to power supply error
91 logError(powerSupplyError, additionalData);
92 }
93 else if (timeout)
94 {
95 // Default to timeout error
96 logError("xyz.openbmc_project.Power.Error.PowerOnTimeout",
97 additionalData);
98 }
99 else
100 {
101 // Default to generic pgood error
102 logError("xyz.openbmc_project.Power.Error.Shutdown", additionalData);
103 }
Jim Wright213ffe92022-06-03 08:54:30 -0500104 if (!timeout)
105 {
106 createBmcDump();
107 }
Jim Wright930458c2022-01-24 14:37:27 -0600108}
109
110} // namespace phosphor::power::sequencer