Jason M. Bills | b6c9298 | 2020-12-04 16:35:02 -0800 | [diff] [blame] | 1 | /* |
| 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 Fertser | 97b5ef2 | 2024-01-23 10:07:21 +0000 | [diff] [blame^] | 18 | #include <xyz/openbmc_project/Logging/Entry/common.hpp> |
Jason M. Bills | b6c9298 | 2020-12-04 16:35:02 -0800 | [diff] [blame] | 19 | |
| 20 | #include <iostream> |
| 21 | |
| 22 | namespace host_error_monitor::base_monitor |
| 23 | { |
| 24 | |
| 25 | class BaseMonitor |
| 26 | { |
| 27 | public: |
| 28 | bool valid; |
Ed Tanous | ee00ccc | 2023-03-01 10:37:43 -0800 | [diff] [blame] | 29 | boost::asio::io_context& io; |
Jason M. Bills | b6c9298 | 2020-12-04 16:35:02 -0800 | [diff] [blame] | 30 | std::shared_ptr<sdbusplus::asio::connection> conn; |
| 31 | |
| 32 | std::string signalName; |
| 33 | |
Ed Tanous | ee00ccc | 2023-03-01 10:37:43 -0800 | [diff] [blame] | 34 | BaseMonitor(boost::asio::io_context& io, |
Jason M. Bills | b6c9298 | 2020-12-04 16:35:02 -0800 | [diff] [blame] | 35 | 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 Fertser | 97b5ef2 | 2024-01-23 10:07:21 +0000 | [diff] [blame^] | 51 | |
| 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. Bills | b6c9298 | 2020-12-04 16:35:02 -0800 | [diff] [blame] | 75 | }; |
| 76 | } // namespace host_error_monitor::base_monitor |