blob: 25c21ae482441e64220106d661907ab307bdbade [file] [log] [blame]
Jason M. Billsb6c92982020-12-04 16:35:02 -08001/*
2// Copyright (c) 2021 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#pragma once
17#include <sdbusplus/asio/object_server.hpp>
Paul Fertser97b5ef22024-01-23 10:07:21 +000018#include <xyz/openbmc_project/Logging/Entry/common.hpp>
Jason M. Billsb6c92982020-12-04 16:35:02 -080019
20#include <iostream>
21
22namespace host_error_monitor::base_monitor
23{
24
25class BaseMonitor
26{
27 public:
28 bool valid;
Ed Tanousee00ccc2023-03-01 10:37:43 -080029 boost::asio::io_context& io;
Jason M. Billsb6c92982020-12-04 16:35:02 -080030 std::shared_ptr<sdbusplus::asio::connection> conn;
31
32 std::string signalName;
33
Ed Tanousee00ccc2023-03-01 10:37:43 -080034 BaseMonitor(boost::asio::io_context& io,
Jason M. Billsb6c92982020-12-04 16:35:02 -080035 std::shared_ptr<sdbusplus::asio::connection> conn,
36 const std::string& signalName) :
37 valid(false),
38 io(io), conn(conn), signalName(signalName)
39
40 {
41 std::cerr << "Initializing " << signalName << " Monitor\n";
42 }
43
44 virtual void hostOn()
45 {}
46
47 bool isValid()
48 {
49 return valid;
50 }
Paul Fertser97b5ef22024-01-23 10:07:21 +000051
52 protected:
53 void log_message(int priority, const std::string& msg,
54 const std::string& redfish_id,
55 const std::string& redfish_msg)
56 {
57#ifdef SEND_TO_LOGGING_SERVICE
58 (void)redfish_id;
59 (void)redfish_msg;
60 using namespace sdbusplus::common::xyz::openbmc_project::logging;
61 sdbusplus::message_t newLogEntry = conn->new_method_call(
62 "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
63 "xyz.openbmc_project.Logging.Create", "Create");
64 const std::string logLevel =
65 Entry::convertLevelToString(static_cast<Entry::Level>(priority));
66 newLogEntry.append(msg, std::move(logLevel),
67 std::map<std::string, std::string>{});
68 conn->call(newLogEntry);
69#else
70 sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i",
71 priority, "REDFISH_MESSAGE_ID=%s", redfish_id.c_str(),
72 "REDFISH_MESSAGE_ARGS=%s", redfish_msg.c_str(), NULL);
73#endif
74 }
Jason M. Billsb6c92982020-12-04 16:35:02 -080075};
76} // namespace host_error_monitor::base_monitor