blob: cbe3afdf3489e471dd725f113a1e65746bb69239 [file] [log] [blame]
Ben Tynerb1ebfcb2020-05-08 18:52:48 -05001#include <unistd.h>
2
Ben Tynerb797b3e2020-06-29 10:12:05 -05003#include <attn/attn_logging.hpp>
Ben Tynerb1ebfcb2020-05-08 18:52:48 -05004#include <phosphor-logging/log.hpp>
5
6namespace attn
7{
8
9/** @brief journal entry of type INFO using phosphor logging */
10template <>
11void trace<INFO>(const char* i_message)
12{
13 phosphor::logging::log<phosphor::logging::level::INFO>(i_message);
14}
15
16/** @brief add an event to the log for PEL generation */
17void event(EventType i_event, std::map<std::string, std::string>& i_additional)
18{
19 bool eventValid = false; // assume no event created
20
21 std::string eventName;
22
23 switch (i_event)
24 {
25 case EventType::Checkstop:
26 eventName = "org.open_power.HwDiags.Error.Checkstop";
27 eventValid = true;
28 break;
29 case EventType::Terminate:
30 eventName = "org.open_power.Attn.Error.Terminate";
31 eventValid = true;
32 break;
33 case EventType::Vital:
34 eventName = "org.open_power.Attn.Error.Vital";
35 eventValid = true;
36 break;
37 case EventType::HwDiagsFail:
38 eventName = "org.open_power.HwDiags.Error.Fail";
39 eventValid = true;
40 break;
41 case EventType::AttentionFail:
42 eventName = "org.open_power.Attn.Error.Fail";
43 eventValid = true;
44 break;
45 default:
46 eventValid = false;
47 break;
48 }
49
50 if (true == eventValid)
51 {
52 // Get access to logging interface and method for creating log
53 auto bus = sdbusplus::bus::new_default_system();
54
55 // using direct create method (for additional data)
56 auto method = bus.new_method_call(
57 "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
58 "xyz.openbmc_project.Logging.Create", "Create");
59
60 // attach additional data
61 method.append(eventName,
62 "xyz.openbmc_project.Logging.Entry.Level.Error",
63 i_additional);
64
65 // log the event
66 auto reply = bus.call(method);
67 }
68}
69
70/** @brief commit checkstop event to log */
71void eventCheckstop(std::map<std::string, std::string>& i_errors)
72{
73 std::map<std::string, std::string> additionalData;
74
75 // TODO need multi-error/multi-callout stuff here
76
77 // if analyzer isolated errors
78 if (!(i_errors.empty()))
79 {
80 // FIXME TEMP CODE - begin
81
82 std::string signature = i_errors.begin()->first;
83 std::string chip = i_errors.begin()->second;
84
85 additionalData["_PID"] = std::to_string(getpid());
86 additionalData["SIGNATURE"] = signature;
87 additionalData["CHIP_ID"] = chip;
88
89 // FIXME TEMP CODE -end
90
91 event(EventType::Checkstop, additionalData);
92 }
93}
94
95/** @brief commit special attention TI event to log */
Ben Tyner40717722020-09-23 09:43:20 -050096void eventTerminate(std::map<std::string, std::string> i_additionalData)
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050097{
Ben Tyner40717722020-09-23 09:43:20 -050098 event(EventType::Terminate, i_additionalData);
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050099}
100
101/** @brief commit SBE vital event to log */
102void eventVital()
103{
104 std::map<std::string, std::string> additionalData;
105
106 additionalData["_PID"] = std::to_string(getpid());
107
108 event(EventType::Vital, additionalData);
109}
110
111/** @brief commit analyzer failure event to log */
112void eventHwDiagsFail(int i_error)
113{
114 std::map<std::string, std::string> additionalData;
115
116 additionalData["_PID"] = std::to_string(getpid());
117
118 event(EventType::HwDiagsFail, additionalData);
119}
120
121/** @brief commit attention handler failure event to log */
122void eventAttentionFail(int i_error)
123{
124 std::map<std::string, std::string> additionalData;
125
126 additionalData["_PID"] = std::to_string(getpid());
127 additionalData["ERROR_CODE"] = std::to_string(i_error);
128
129 event(EventType::AttentionFail, additionalData);
130}
131
132} // namespace attn