blob: 0f67f300f1a0e548be4e4968fae849df55641ccc [file] [log] [blame]
Deepak Kodihallic4966192018-08-23 02:19:58 -05001#pragma once
2
3#include <sdbusplus/bus.hpp>
4#include <sdbusplus/server/object.hpp>
5#include <string>
Deepak Kodihalli9fab2792018-08-28 07:47:11 -05006#include <phosphor-logging/log.hpp>
Deepak Kodihallic4966192018-08-23 02:19:58 -05007#include "xyz/openbmc_project/Network/Client/server.hpp"
8
9namespace phosphor
10{
11namespace rsyslog_config
12{
13
Deepak Kodihalli9fab2792018-08-28 07:47:11 -050014using namespace phosphor::logging;
Deepak Kodihallic4966192018-08-23 02:19:58 -050015using NetworkClient = sdbusplus::xyz::openbmc_project::Network::server::Client;
16using Iface = sdbusplus::server::object::object<NetworkClient>;
17
18/** @class Server
19 * @brief Configuration for rsyslog server
20 * @details A concrete implementation of the
21 * xyz.openbmc_project.Network.Client API, in order to
22 * provide remote rsyslog server's address and port.
23 */
24class Server : public Iface
25{
26 public:
27 Server() = delete;
28 Server(const Server&) = delete;
29 Server& operator=(const Server&) = delete;
30 Server(Server&&) = delete;
31 Server& operator=(Server&&) = delete;
32 virtual ~Server() = default;
33
34 /** @brief Constructor to put object onto bus at a dbus path.
35 * @param[in] bus - Bus to attach to.
36 * @param[in] path - Path to attach at.
37 * @param[in] filePath - rsyslog remote logging config file
38 */
39 Server(sdbusplus::bus::bus& bus,
40 const std::string& path,
41 const char* filePath) :
Deepak Kodihalli9fab2792018-08-28 07:47:11 -050042 Iface(bus, path.c_str(), true),
Deepak Kodihallic4966192018-08-23 02:19:58 -050043 configFilePath(filePath)
44 {
Deepak Kodihalli9fab2792018-08-28 07:47:11 -050045 try
46 {
47 restore(configFilePath.c_str());
48 }
49 catch(const std::exception& e)
50 {
51 log<level::ERR>(e.what());
52 }
53
54 emit_object_added();
Deepak Kodihallic4966192018-08-23 02:19:58 -050055 }
56
57 using NetworkClient::address;
58 using NetworkClient::port;
59
60 /** @brief Override that updates rsyslog config file as well
61 * @param[in] value - remote server address
62 * @returns value of changed address
63 */
64 virtual std::string address(std::string value) override;
65
66 /** @brief Override that updates rsyslog config file as well
67 * @param[in] value - remote server port
68 * @returns value of changed port
69 */
70 virtual uint16_t port(uint16_t value) override;
71
72 private:
73 /** @brief Update remote server address and port in
74 * rsyslog config file.
75 * @param[in] serverAddress - remote server address
76 * @param[in] serverPort - remote server port
77 * @param[in] filePath - rsyslog config file path
78 */
79 void writeConfig(
80 const std::string& serverAddress,
81 uint16_t serverPort,
82 const char* filePath);
83
Deepak Kodihalli4db81462018-08-27 06:01:46 -050084 /** @brief Checks if input IP address is valid (uses getaddrinfo)
85 * @param[in] address - server address
86 * @returns true if valid, false otherwise
87 */
88 bool addressValid(const std::string& address);
89
Deepak Kodihalli9fab2792018-08-28 07:47:11 -050090 /** @brief Populate existing config into D-Bus properties
91 * @param[in] filePath - rsyslog config file path
92 */
93 void restore(const char* filePath);
94
Deepak Kodihallic4966192018-08-23 02:19:58 -050095 std::string configFilePath{};
96};
97
98} // namespace rsyslog_config
99} // namespace phosphor