blob: d2c589a7b56e34de5230809f1b122dc6df8f6397 [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);
30
31 if (propertiesChanged.empty())
32 {
33 return;
34 }
35
36 std::string event = propertiesChanged.begin()->first;
37
Patrick Williams16afcb92020-05-13 11:39:46 -050038 auto variant =
39 std::get_if<std::string>(&propertiesChanged.begin()->second);
Nikhil Potadeafbaa092019-03-06 16:18:13 -080040
41 if (event.empty() || nullptr == variant)
42 {
43 return;
44 }
45
46 if (event == "CurrentHostState")
47 {
Denis Zlobin56ccc242023-04-27 07:29:03 +000048 std::string journalMsg;
49 std::string redfishMsgId;
50
Nikhil Potadeafbaa092019-03-06 16:18:13 -080051 if (*variant == "xyz.openbmc_project.State.Host.HostState.Off")
52 {
Denis Zlobin56ccc242023-04-27 07:29:03 +000053 journalMsg = "Host system DC power is off";
54 redfishMsgId = "OpenBMC.0.1.DCPowerOff";
Nikhil Potadeafbaa092019-03-06 16:18:13 -080055 }
56 else if (*variant ==
57 "xyz.openbmc_project.State.Host.HostState.Running")
58 {
Denis Zlobin56ccc242023-04-27 07:29:03 +000059 journalMsg = "Host system DC power is on";
60 redfishMsgId = "OpenBMC.0.1.DCPowerOn";
Nikhil Potadeafbaa092019-03-06 16:18:13 -080061 }
Denis Zlobin56ccc242023-04-27 07:29:03 +000062 else
63 {
64 return;
65 }
66#ifdef SEL_LOGGER_SEND_TO_LOGGING_SERVICE
67 sdbusplus::message_t newLogEntry = conn->new_method_call(
68 "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
69 "xyz.openbmc_project.Logging.Create", "Create");
70 const std::string logLevel =
71 "xyz.openbmc_project.Logging.Entry.Level.Informational";
72 const std::string hostPathName = "HOST_PATH";
73 const std::string hostPath = msg.get_path();
74 newLogEntry.append(
75 std::move(journalMsg), std::move(logLevel),
76 std::map<std::string, std::string>(
77 {{std::move(hostPathName), std::move(hostPath)}}));
78 conn->call(newLogEntry);
79#else
80 sd_journal_send("MESSAGE=%s", journalMsg.c_str(),
81 "REDFISH_MESSAGE_ID=%s", redfishMsgId.c_str(),
82 NULL);
83#endif
Nikhil Potadeafbaa092019-03-06 16:18:13 -080084 }
85 };
86
Patrick Williamsccef2272022-07-22 19:26:54 -050087 sdbusplus::bus::match_t pulseEventMatcher(
88 static_cast<sdbusplus::bus_t&>(*conn),
Nikhil Potadeafbaa092019-03-06 16:18:13 -080089 "type='signal',interface='org.freedesktop.DBus.Properties',member='"
90 "PropertiesChanged',arg0namespace='xyz.openbmc_project.State.Host'",
91 std::move(pulseEventMatcherCallback));
92
93 return pulseEventMatcher;
Patrick Williams69f7fa32023-05-10 07:50:41 -050094}