Nikhil Potade | afbaa09 | 2019-03-06 16:18:13 -0800 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2019 Intel 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 | #pragma once |
| 18 | #include <sdbusplus/asio/object_server.hpp> |
| 19 | #include <sel_logger.hpp> |
| 20 | #include <sensorutils.hpp> |
| 21 | |
Patrick Williams | ccef227 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 22 | inline static sdbusplus::bus::match_t |
Nikhil Potade | afbaa09 | 2019-03-06 16:18:13 -0800 | [diff] [blame] | 23 | startPulseEventMonitor(std::shared_ptr<sdbusplus::asio::connection> conn) |
| 24 | { |
Denis Zlobin | 56ccc24 | 2023-04-27 07:29:03 +0000 | [diff] [blame] | 25 | auto pulseEventMatcherCallback = [conn](sdbusplus::message_t& msg) { |
Nikhil Potade | afbaa09 | 2019-03-06 16:18:13 -0800 | [diff] [blame] | 26 | std::string thresholdInterface; |
Patrick Williams | 761bf20 | 2020-05-13 18:00:24 -0500 | [diff] [blame] | 27 | boost::container::flat_map<std::string, std::variant<std::string>> |
Nikhil Potade | afbaa09 | 2019-03-06 16:18:13 -0800 | [diff] [blame] | 28 | propertiesChanged; |
| 29 | msg.read(thresholdInterface, propertiesChanged); |
Potin Lai | 7f5518a | 2024-03-19 00:37:36 +0800 | [diff] [blame] | 30 | std::string objPath = msg.get_path(); |
Nikhil Potade | afbaa09 | 2019-03-06 16:18:13 -0800 | [diff] [blame] | 31 | |
| 32 | if (propertiesChanged.empty()) |
| 33 | { |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | std::string event = propertiesChanged.begin()->first; |
| 38 | |
Patrick Williams | 16afcb9 | 2020-05-13 11:39:46 -0500 | [diff] [blame] | 39 | auto variant = |
| 40 | std::get_if<std::string>(&propertiesChanged.begin()->second); |
Nikhil Potade | afbaa09 | 2019-03-06 16:18:13 -0800 | [diff] [blame] | 41 | |
| 42 | if (event.empty() || nullptr == variant) |
| 43 | { |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | if (event == "CurrentHostState") |
| 48 | { |
Potin Lai | 7f5518a | 2024-03-19 00:37:36 +0800 | [diff] [blame] | 49 | std::string journalMsg = "Host"; |
Denis Zlobin | 56ccc24 | 2023-04-27 07:29:03 +0000 | [diff] [blame] | 50 | std::string redfishMsgId; |
Potin Lai | 7f5518a | 2024-03-19 00:37:36 +0800 | [diff] [blame] | 51 | std::string_view hostObjPathPrefix = |
| 52 | "/xyz/openbmc_project/state/host"; |
| 53 | |
| 54 | if (objPath.starts_with(hostObjPathPrefix)) |
| 55 | { |
| 56 | journalMsg += objPath.erase(0, hostObjPathPrefix.size()); |
| 57 | } |
Denis Zlobin | 56ccc24 | 2023-04-27 07:29:03 +0000 | [diff] [blame] | 58 | |
Nikhil Potade | afbaa09 | 2019-03-06 16:18:13 -0800 | [diff] [blame] | 59 | if (*variant == "xyz.openbmc_project.State.Host.HostState.Off") |
| 60 | { |
Potin Lai | 7f5518a | 2024-03-19 00:37:36 +0800 | [diff] [blame] | 61 | journalMsg += " system DC power is off"; |
Denis Zlobin | 56ccc24 | 2023-04-27 07:29:03 +0000 | [diff] [blame] | 62 | redfishMsgId = "OpenBMC.0.1.DCPowerOff"; |
Nikhil Potade | afbaa09 | 2019-03-06 16:18:13 -0800 | [diff] [blame] | 63 | } |
| 64 | else if (*variant == |
| 65 | "xyz.openbmc_project.State.Host.HostState.Running") |
| 66 | { |
Potin Lai | 7f5518a | 2024-03-19 00:37:36 +0800 | [diff] [blame] | 67 | journalMsg += " system DC power is on"; |
Denis Zlobin | 56ccc24 | 2023-04-27 07:29:03 +0000 | [diff] [blame] | 68 | redfishMsgId = "OpenBMC.0.1.DCPowerOn"; |
Nikhil Potade | afbaa09 | 2019-03-06 16:18:13 -0800 | [diff] [blame] | 69 | } |
Denis Zlobin | 56ccc24 | 2023-04-27 07:29:03 +0000 | [diff] [blame] | 70 | else |
| 71 | { |
| 72 | return; |
| 73 | } |
| 74 | #ifdef SEL_LOGGER_SEND_TO_LOGGING_SERVICE |
| 75 | sdbusplus::message_t newLogEntry = conn->new_method_call( |
| 76 | "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", |
| 77 | "xyz.openbmc_project.Logging.Create", "Create"); |
| 78 | const std::string logLevel = |
| 79 | "xyz.openbmc_project.Logging.Entry.Level.Informational"; |
| 80 | const std::string hostPathName = "HOST_PATH"; |
| 81 | const std::string hostPath = msg.get_path(); |
| 82 | newLogEntry.append( |
| 83 | std::move(journalMsg), std::move(logLevel), |
| 84 | std::map<std::string, std::string>( |
| 85 | {{std::move(hostPathName), std::move(hostPath)}})); |
| 86 | conn->call(newLogEntry); |
| 87 | #else |
| 88 | sd_journal_send("MESSAGE=%s", journalMsg.c_str(), |
| 89 | "REDFISH_MESSAGE_ID=%s", redfishMsgId.c_str(), |
| 90 | NULL); |
| 91 | #endif |
Nikhil Potade | afbaa09 | 2019-03-06 16:18:13 -0800 | [diff] [blame] | 92 | } |
| 93 | }; |
| 94 | |
Patrick Williams | ccef227 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 95 | sdbusplus::bus::match_t pulseEventMatcher( |
| 96 | static_cast<sdbusplus::bus_t&>(*conn), |
Nikhil Potade | afbaa09 | 2019-03-06 16:18:13 -0800 | [diff] [blame] | 97 | "type='signal',interface='org.freedesktop.DBus.Properties',member='" |
| 98 | "PropertiesChanged',arg0namespace='xyz.openbmc_project.State.Host'", |
| 99 | std::move(pulseEventMatcherCallback)); |
| 100 | |
| 101 | return pulseEventMatcher; |
Patrick Williams | 69f7fa3 | 2023-05-10 07:50:41 -0500 | [diff] [blame] | 102 | } |