From 0febd26b542399cbbfe1c4c01b10a24d9cf4f860 Mon Sep 17 00:00:00 2001 From: Deepak Kodihalli Date: Mon, 27 Aug 2018 05:45:02 -0500 Subject: phosphor-ryslog-conf: add way to disable logging Remote logging via rsyslog can be disabled by writing 0 to the port, or an empty string to the address. Change-Id: I50bce3ff008af1b9c488a09a2b36c01abbe5497d Signed-off-by: Deepak Kodihalli --- README.md | 5 +++++ phosphor-rsyslog-config/server-conf.cpp | 26 ++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e0ea54a..f8ab729 100644 --- a/README.md +++ b/README.md @@ -62,10 +62,15 @@ curl -b cjar -k -H "Content-Type: application/json" -X PUT \ https:////xyz/openbmc_project/network/config/attr/HostName ``` +#### Disabling remote logging +Remote logging can be disabled by writing 0 to the port, or an empty string("") +to the IP. + #### Changing the rsyslog server When switching to a new server from an existing one (i.e the address, or port, or both change), it is recommended to disable the existing configuration first. + ## Adding application specific error YAML * This document captures steps for adding application specific error YAML files and generating local elog-errors.hpp header file for application use. diff --git a/phosphor-rsyslog-config/server-conf.cpp b/phosphor-rsyslog-config/server-conf.cpp index 16c792d..1372e85 100644 --- a/phosphor-rsyslog-config/server-conf.cpp +++ b/phosphor-rsyslog-config/server-conf.cpp @@ -11,6 +11,12 @@ namespace utils = phosphor::rsyslog_utils; std::string Server::address(std::string value) { + auto serverAddress = address(); + if (serverAddress == value) + { + return serverAddress; + } + writeConfig(value, port(), configFilePath.c_str()); auto result = NetworkClient::address(value); return result; @@ -18,6 +24,12 @@ std::string Server::address(std::string value) uint16_t Server::port(uint16_t value) { + auto serverPort = port(); + if (serverPort == value) + { + return serverPort; + } + writeConfig(address(), value, configFilePath.c_str()); auto result = NetworkClient::port(value); return result; @@ -28,14 +40,20 @@ void Server::writeConfig( uint16_t serverPort, const char* filePath) { + std::fstream stream(filePath, std::fstream::out); + if (serverPort && !serverAddress.empty()) { - std::fstream stream(filePath, std::fstream::out); - // write '*.* @@remote-host:port' + // write '*.* @@:' stream << "*.* @@" << serverAddress << ":" << serverPort; - - utils::restart(); } + else // this is a disable request + { + // write '#*.* @@remote-host:port' + stream << "#*.* @@remote-host:port"; + } + + utils::restart(); } } // namespace rsyslog_config -- cgit v1.2.1