blob: 795cfb6581c5e3fd462bd69409353275f00f2060 [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>
6#include "xyz/openbmc_project/Network/Client/server.hpp"
7
8namespace phosphor
9{
10namespace rsyslog_config
11{
12
13using NetworkClient = sdbusplus::xyz::openbmc_project::Network::server::Client;
14using Iface = sdbusplus::server::object::object<NetworkClient>;
15
16/** @class Server
17 * @brief Configuration for rsyslog server
18 * @details A concrete implementation of the
19 * xyz.openbmc_project.Network.Client API, in order to
20 * provide remote rsyslog server's address and port.
21 */
22class Server : public Iface
23{
24 public:
25 Server() = delete;
26 Server(const Server&) = delete;
27 Server& operator=(const Server&) = delete;
28 Server(Server&&) = delete;
29 Server& operator=(Server&&) = delete;
30 virtual ~Server() = default;
31
32 /** @brief Constructor to put object onto bus at a dbus path.
33 * @param[in] bus - Bus to attach to.
34 * @param[in] path - Path to attach at.
35 * @param[in] filePath - rsyslog remote logging config file
36 */
37 Server(sdbusplus::bus::bus& bus,
38 const std::string& path,
39 const char* filePath) :
40 Iface(bus, path.c_str()),
41 configFilePath(filePath)
42 {
43 }
44
45 using NetworkClient::address;
46 using NetworkClient::port;
47
48 /** @brief Override that updates rsyslog config file as well
49 * @param[in] value - remote server address
50 * @returns value of changed address
51 */
52 virtual std::string address(std::string value) override;
53
54 /** @brief Override that updates rsyslog config file as well
55 * @param[in] value - remote server port
56 * @returns value of changed port
57 */
58 virtual uint16_t port(uint16_t value) override;
59
60 private:
61 /** @brief Update remote server address and port in
62 * rsyslog config file.
63 * @param[in] serverAddress - remote server address
64 * @param[in] serverPort - remote server port
65 * @param[in] filePath - rsyslog config file path
66 */
67 void writeConfig(
68 const std::string& serverAddress,
69 uint16_t serverPort,
70 const char* filePath);
71
Deepak Kodihalli4db81462018-08-27 06:01:46 -050072 /** @brief Checks if input IP address is valid (uses getaddrinfo)
73 * @param[in] address - server address
74 * @returns true if valid, false otherwise
75 */
76 bool addressValid(const std::string& address);
77
Deepak Kodihallic4966192018-08-23 02:19:58 -050078 std::string configFilePath{};
79};
80
81} // namespace rsyslog_config
82} // namespace phosphor