blob: 0ad6b38b12e5f7c978384091e5cfa0a5a6706343 [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
18#include <sdbusplus/asio/object_server.hpp>
19#include <sel_logger.hpp>
20#include <sensorutils.hpp>
21
Patrick Williamsccef2272022-07-22 19:26:54 -050022inline static sdbusplus::bus::match_t
Nikhil Potadeafbaa092019-03-06 16:18:13 -080023 startPulseEventMonitor(std::shared_ptr<sdbusplus::asio::connection> conn)
24{
Denis Zlobin56ccc242023-04-27 07:29:03 +000025 auto pulseEventMatcherCallback = [conn](sdbusplus::message_t& msg) {
Nikhil Potadeafbaa092019-03-06 16:18:13 -080026 std::string thresholdInterface;
Patrick Williams761bf202020-05-13 18:00:24 -050027 boost::container::flat_map<std::string, std::variant<std::string>>
Nikhil Potadeafbaa092019-03-06 16:18:13 -080028 propertiesChanged;
29 msg.read(thresholdInterface, propertiesChanged);
Potin Lai7f5518a2024-03-19 00:37:36 +080030 std::string objPath = msg.get_path();
Nikhil Potadeafbaa092019-03-06 16:18:13 -080031
32 if (propertiesChanged.empty())
33 {
34 return;
35 }
36
37 std::string event = propertiesChanged.begin()->first;
38
Patrick Williams16afcb92020-05-13 11:39:46 -050039 auto variant =
40 std::get_if<std::string>(&propertiesChanged.begin()->second);
Nikhil Potadeafbaa092019-03-06 16:18:13 -080041
42 if (event.empty() || nullptr == variant)
43 {
44 return;
45 }
46
47 if (event == "CurrentHostState")
48 {
Potin Lai7f5518a2024-03-19 00:37:36 +080049 std::string journalMsg = "Host";
Denis Zlobin56ccc242023-04-27 07:29:03 +000050 std::string redfishMsgId;
Potin Lai7f5518a2024-03-19 00:37:36 +080051 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 Zlobin56ccc242023-04-27 07:29:03 +000058
Nikhil Potadeafbaa092019-03-06 16:18:13 -080059 if (*variant == "xyz.openbmc_project.State.Host.HostState.Off")
60 {
Potin Lai7f5518a2024-03-19 00:37:36 +080061 journalMsg += " system DC power is off";
Denis Zlobin56ccc242023-04-27 07:29:03 +000062 redfishMsgId = "OpenBMC.0.1.DCPowerOff";
Nikhil Potadeafbaa092019-03-06 16:18:13 -080063 }
64 else if (*variant ==
65 "xyz.openbmc_project.State.Host.HostState.Running")
66 {
Potin Lai7f5518a2024-03-19 00:37:36 +080067 journalMsg += " system DC power is on";
Denis Zlobin56ccc242023-04-27 07:29:03 +000068 redfishMsgId = "OpenBMC.0.1.DCPowerOn";
Nikhil Potadeafbaa092019-03-06 16:18:13 -080069 }
Denis Zlobin56ccc242023-04-27 07:29:03 +000070 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 Potadeafbaa092019-03-06 16:18:13 -080092 }
93 };
94
Patrick Williamsccef2272022-07-22 19:26:54 -050095 sdbusplus::bus::match_t pulseEventMatcher(
96 static_cast<sdbusplus::bus_t&>(*conn),
Nikhil Potadeafbaa092019-03-06 16:18:13 -080097 "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 Williams69f7fa32023-05-10 07:50:41 -0500102}