Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 1 | #include <unistd.h> |
| 2 | |
Ben Tyner | b797b3e | 2020-06-29 10:12:05 -0500 | [diff] [blame] | 3 | #include <attn/attn_logging.hpp> |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 4 | #include <phosphor-logging/log.hpp> |
| 5 | |
| 6 | namespace attn |
| 7 | { |
| 8 | |
| 9 | /** @brief journal entry of type INFO using phosphor logging */ |
| 10 | template <> |
| 11 | void 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 */ |
| 17 | void 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 */ |
| 71 | void 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 */ |
| 96 | void eventTerminate() |
| 97 | { |
| 98 | std::map<std::string, std::string> additionalData; |
| 99 | |
| 100 | additionalData["_PID"] = std::to_string(getpid()); |
| 101 | |
| 102 | event(EventType::Terminate, additionalData); |
| 103 | } |
| 104 | |
| 105 | /** @brief commit SBE vital event to log */ |
| 106 | void eventVital() |
| 107 | { |
| 108 | std::map<std::string, std::string> additionalData; |
| 109 | |
| 110 | additionalData["_PID"] = std::to_string(getpid()); |
| 111 | |
| 112 | event(EventType::Vital, additionalData); |
| 113 | } |
| 114 | |
| 115 | /** @brief commit analyzer failure event to log */ |
| 116 | void eventHwDiagsFail(int i_error) |
| 117 | { |
| 118 | std::map<std::string, std::string> additionalData; |
| 119 | |
| 120 | additionalData["_PID"] = std::to_string(getpid()); |
| 121 | |
| 122 | event(EventType::HwDiagsFail, additionalData); |
| 123 | } |
| 124 | |
| 125 | /** @brief commit attention handler failure event to log */ |
| 126 | void eventAttentionFail(int i_error) |
| 127 | { |
| 128 | std::map<std::string, std::string> additionalData; |
| 129 | |
| 130 | additionalData["_PID"] = std::to_string(getpid()); |
| 131 | additionalData["ERROR_CODE"] = std::to_string(i_error); |
| 132 | |
| 133 | event(EventType::AttentionFail, additionalData); |
| 134 | } |
| 135 | |
| 136 | } // namespace attn |