Add application to configure rsyslog
The application implements the xyz.openbmc_project.Network.Client D-Bus
interface to set a remote rsyslog server's address and port in the
rsyslog config file.
This lets us configure rsyslog to be able to stream out logs.
TODO: Exception handling and validation will be handled in subsequent
commits.
Change-Id: I8917daab3f0de1806d2f1aafe99cb3a872f19184
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/phosphor-rsyslog-config/server-conf.cpp b/phosphor-rsyslog-config/server-conf.cpp
new file mode 100644
index 0000000..16c792d
--- /dev/null
+++ b/phosphor-rsyslog-config/server-conf.cpp
@@ -0,0 +1,42 @@
+#include "server-conf.hpp"
+#include "utils.hpp"
+#include <fstream>
+
+namespace phosphor
+{
+namespace rsyslog_config
+{
+
+namespace utils = phosphor::rsyslog_utils;
+
+std::string Server::address(std::string value)
+{
+ writeConfig(value, port(), configFilePath.c_str());
+ auto result = NetworkClient::address(value);
+ return result;
+}
+
+uint16_t Server::port(uint16_t value)
+{
+ writeConfig(address(), value, configFilePath.c_str());
+ auto result = NetworkClient::port(value);
+ return result;
+}
+
+void Server::writeConfig(
+ const std::string& serverAddress,
+ uint16_t serverPort,
+ const char* filePath)
+{
+ if (serverPort && !serverAddress.empty())
+ {
+ std::fstream stream(filePath, std::fstream::out);
+ // write '*.* @@remote-host:port'
+ stream << "*.* @@" << serverAddress << ":" << serverPort;
+
+ utils::restart();
+ }
+}
+
+} // namespace rsyslog_config
+} // namespace phosphor