blob: df723abdc3261df90477f73a2ed57162c1d85cca [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
32PowerSequencerMonitor::PowerSequencerMonitor(sdbusplus::bus::bus& bus) :
33 bus(bus)
34{}
35
36void 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()));
Jim Wright7f20c5d2022-02-28 20:49:39 -060048 // Set as system terminating
49 additionalData.emplace("SEVERITY_DETAIL", "SYSTEM_TERM");
Jim Wright930458c2022-01-24 14:37:27 -060050
51 method.append(message,
52 sdbusplus::xyz::openbmc_project::Logging::server::Entry::
53 Level::Critical,
54 additionalData);
55 bus.call_noreply(method);
56 }
57 catch (const std::exception& e)
58 {
59 log<level::ERR>(
60 fmt::format("Unable to log error, message: {}, error {}", message,
61 e.what())
62 .c_str());
63 }
64}
65
66void PowerSequencerMonitor::onFailure(bool timeout,
67 const std::string& powerSupplyError)
68{
69 std::map<std::string, std::string> additionalData{};
70 if (!powerSupplyError.empty())
71 {
72 // Default to power supply error
73 logError(powerSupplyError, additionalData);
74 }
75 else if (timeout)
76 {
77 // Default to timeout error
78 logError("xyz.openbmc_project.Power.Error.PowerOnTimeout",
79 additionalData);
80 }
81 else
82 {
83 // Default to generic pgood error
84 logError("xyz.openbmc_project.Power.Error.Shutdown", additionalData);
85 }
86}
87
88} // namespace phosphor::power::sequencer