Deepak Kodihalli | c496619 | 2018-08-23 02:19:58 -0500 | [diff] [blame^] | 1 | #include "server-conf.hpp" |
| 2 | #include "utils.hpp" |
| 3 | #include <fstream> |
| 4 | |
| 5 | namespace phosphor |
| 6 | { |
| 7 | namespace rsyslog_config |
| 8 | { |
| 9 | |
| 10 | namespace utils = phosphor::rsyslog_utils; |
| 11 | |
| 12 | std::string Server::address(std::string value) |
| 13 | { |
| 14 | writeConfig(value, port(), configFilePath.c_str()); |
| 15 | auto result = NetworkClient::address(value); |
| 16 | return result; |
| 17 | } |
| 18 | |
| 19 | uint16_t Server::port(uint16_t value) |
| 20 | { |
| 21 | writeConfig(address(), value, configFilePath.c_str()); |
| 22 | auto result = NetworkClient::port(value); |
| 23 | return result; |
| 24 | } |
| 25 | |
| 26 | void Server::writeConfig( |
| 27 | const std::string& serverAddress, |
| 28 | uint16_t serverPort, |
| 29 | const char* filePath) |
| 30 | { |
| 31 | if (serverPort && !serverAddress.empty()) |
| 32 | { |
| 33 | std::fstream stream(filePath, std::fstream::out); |
| 34 | // write '*.* @@remote-host:port' |
| 35 | stream << "*.* @@" << serverAddress << ":" << serverPort; |
| 36 | |
| 37 | utils::restart(); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | } // namespace rsyslog_config |
| 42 | } // namespace phosphor |