blob: 35ce7c94c28f4b2973ca54308abbaad0f54a906f [file] [log] [blame]
Nikhil Potadeafbaa092019-03-06 16:18:13 -08001/*
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
Lei YU9916d412025-02-06 11:51:18 +000018#include <boost/container/flat_map.hpp>
Nikhil Potadeafbaa092019-03-06 16:18:13 -080019#include <sdbusplus/asio/object_server.hpp>
Lei YU9916d412025-02-06 11:51:18 +000020#include <sdbusplus/bus/match.hpp>
Nikhil Potadeafbaa092019-03-06 16:18:13 -080021#include <sel_logger.hpp>
22#include <sensorutils.hpp>
23
Patrick Williamsa58ea682025-02-01 08:22:21 -050024inline static sdbusplus::bus::match_t startPulseEventMonitor(
25 std::shared_ptr<sdbusplus::asio::connection> conn)
Nikhil Potadeafbaa092019-03-06 16:18:13 -080026{
Denis Zlobin56ccc242023-04-27 07:29:03 +000027 auto pulseEventMatcherCallback = [conn](sdbusplus::message_t& msg) {
Nikhil Potadeafbaa092019-03-06 16:18:13 -080028 std::string thresholdInterface;
Patrick Williams761bf202020-05-13 18:00:24 -050029 boost::container::flat_map<std::string, std::variant<std::string>>
Nikhil Potadeafbaa092019-03-06 16:18:13 -080030 propertiesChanged;
31 msg.read(thresholdInterface, propertiesChanged);
Potin Lai7f5518a2024-03-19 00:37:36 +080032 std::string objPath = msg.get_path();
Nikhil Potadeafbaa092019-03-06 16:18:13 -080033
34 if (propertiesChanged.empty())
35 {
36 return;
37 }
38
39 std::string event = propertiesChanged.begin()->first;
40
Patrick Williams16afcb92020-05-13 11:39:46 -050041 auto variant =
42 std::get_if<std::string>(&propertiesChanged.begin()->second);
Nikhil Potadeafbaa092019-03-06 16:18:13 -080043
44 if (event.empty() || nullptr == variant)
45 {
46 return;
47 }
48
49 if (event == "CurrentHostState")
50 {
Potin Lai7f5518a2024-03-19 00:37:36 +080051 std::string journalMsg = "Host";
Denis Zlobin56ccc242023-04-27 07:29:03 +000052 std::string redfishMsgId;
Potin Lai7f5518a2024-03-19 00:37:36 +080053 std::string_view hostObjPathPrefix =
54 "/xyz/openbmc_project/state/host";
55
56 if (objPath.starts_with(hostObjPathPrefix))
57 {
58 journalMsg += objPath.erase(0, hostObjPathPrefix.size());
59 }
Denis Zlobin56ccc242023-04-27 07:29:03 +000060
Nikhil Potadeafbaa092019-03-06 16:18:13 -080061 if (*variant == "xyz.openbmc_project.State.Host.HostState.Off")
62 {
Zoey YJ Chung02124a12025-02-13 18:45:30 +080063 journalMsg += " state is off";
Denis Zlobin56ccc242023-04-27 07:29:03 +000064 redfishMsgId = "OpenBMC.0.1.DCPowerOff";
Nikhil Potadeafbaa092019-03-06 16:18:13 -080065 }
66 else if (*variant ==
67 "xyz.openbmc_project.State.Host.HostState.Running")
68 {
Zoey YJ Chung02124a12025-02-13 18:45:30 +080069 journalMsg += " state is on";
Denis Zlobin56ccc242023-04-27 07:29:03 +000070 redfishMsgId = "OpenBMC.0.1.DCPowerOn";
Nikhil Potadeafbaa092019-03-06 16:18:13 -080071 }
Denis Zlobin56ccc242023-04-27 07:29:03 +000072 else
73 {
74 return;
75 }
76#ifdef SEL_LOGGER_SEND_TO_LOGGING_SERVICE
77 sdbusplus::message_t newLogEntry = conn->new_method_call(
78 "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
79 "xyz.openbmc_project.Logging.Create", "Create");
80 const std::string logLevel =
81 "xyz.openbmc_project.Logging.Entry.Level.Informational";
82 const std::string hostPathName = "HOST_PATH";
83 const std::string hostPath = msg.get_path();
84 newLogEntry.append(
85 std::move(journalMsg), std::move(logLevel),
86 std::map<std::string, std::string>(
87 {{std::move(hostPathName), std::move(hostPath)}}));
88 conn->call(newLogEntry);
89#else
90 sd_journal_send("MESSAGE=%s", journalMsg.c_str(),
91 "REDFISH_MESSAGE_ID=%s", redfishMsgId.c_str(),
92 NULL);
93#endif
Nikhil Potadeafbaa092019-03-06 16:18:13 -080094 }
95 };
96
Patrick Williamsccef2272022-07-22 19:26:54 -050097 sdbusplus::bus::match_t pulseEventMatcher(
98 static_cast<sdbusplus::bus_t&>(*conn),
Nikhil Potadeafbaa092019-03-06 16:18:13 -080099 "type='signal',interface='org.freedesktop.DBus.Properties',member='"
100 "PropertiesChanged',arg0namespace='xyz.openbmc_project.State.Host'",
101 std::move(pulseEventMatcherCallback));
102
103 return pulseEventMatcher;
Patrick Williams69f7fa32023-05-10 07:50:41 -0500104}