From abb06ac230917f2dfbf6fd180a44e240affb3a0a Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Thu, 7 Apr 2011 12:47:17 +0200 Subject: [PATCH] Reading the network interface from the configuration file. --- conf/pingcheck.conf | 1 + src/config/configuration.cpp | 13 +++++++++++++ src/config/configuration.h | 6 ++++++ src/config/configurationreader.cpp | 14 ++++++++++++++ src/config/configurationreader.h | 2 ++ 5 files changed, 36 insertions(+), 0 deletions(-) diff --git a/conf/pingcheck.conf b/conf/pingcheck.conf index f517b26..82468a3 100644 --- a/conf/pingcheck.conf +++ b/conf/pingcheck.conf @@ -1,3 +1,4 @@ +source-network-interface=eth1 hosts-down-limit=4 ping-fail-limit=40 status-notifier-cmd=./system_status_alert.sh ${status} diff --git a/src/config/configuration.cpp b/src/config/configuration.cpp index baa2425..69b89b6 100644 --- a/src/config/configuration.cpp +++ b/src/config/configuration.cpp @@ -10,6 +10,7 @@ using namespace std; Configuration::Configuration() : ConfigFileName( "" ), + SourceNetworkInterface( "" ), HostsDownLimit( 0 ), MinHostsDownLimit( 0 ), MaxHostsDownLimit( 50 ), @@ -40,6 +41,18 @@ void Configuration::set_config_file_name( const std::string &config_file_name ) this->ConfigFileName = config_file_name; } +string Configuration::get_source_network_interface() const +{ + return SourceNetworkInterface; +} + +void Configuration::set_source_network_interface( + const string &source_network_interface +) +{ + SourceNetworkInterface = source_network_interface; +} + int Configuration::get_hosts_down_limit() const { return HostsDownLimit; diff --git a/src/config/configuration.h b/src/config/configuration.h index 1d8d0d3..b6de740 100644 --- a/src/config/configuration.h +++ b/src/config/configuration.h @@ -21,6 +21,11 @@ public: std::string get_config_file_name() const; void set_config_file_name( const std::string &config_file_name ); + std::string get_source_network_interface() const; + void set_source_network_interface( + const std::string &source_network_interface + ); + int get_hosts_down_limit() const; void set_hosts_down_limit( const int hosts_down_limit ); @@ -38,6 +43,7 @@ public: private: std::string ConfigFileName; + std::string SourceNetworkInterface; int HostsDownLimit; const int MinHostsDownLimit; const int MaxHostsDownLimit; diff --git a/src/config/configurationreader.cpp b/src/config/configurationreader.cpp index a110e71..d4c855c 100644 --- a/src/config/configurationreader.cpp +++ b/src/config/configurationreader.cpp @@ -23,6 +23,8 @@ ConfigurationReader::ConfigurationReader() : DefaultConfigFileName( "pingcheck.conf" ), ConfigFileCmdStr( "config-file" ), ConfigFileCmdDesc( "Name of the configuration file." ), + SourceNetworkInterfaceCmdStr( "source-network-interface" ), + SourceNetworkInterfaceCmdDesc( "The network interface from where the packets will be received and originated" ), DefaultHostsDownLimit( 1 ), // 1 host down at most HostsDownLimitCmdStr( "hosts-down-limit" ), HostsDownLimitCmdDesc( "Limit of host that have to be down in order to notify." ), @@ -117,6 +119,7 @@ options_description ConfigurationReader::get_configuration_options() const { options_description options( "Configuration" ); options.add_options() + ( SourceNetworkInterfaceCmdStr.c_str(), value(), SourceNetworkInterfaceCmdDesc.c_str() ) ( HostsDownLimitCmdStr.c_str(), value()->default_value( DefaultHostsDownLimit ), HostsDownLimitCmdDesc.c_str() ) ( PingFailLimitCmdStr.c_str(), value()->default_value( DefaultPingFailLimit ), PingFailLimitCmdDesc.c_str() ) ( StatusNotifierCmdCmdStr.c_str(), value(), StatusNotifierCmdCmdDesc.c_str() ) @@ -139,6 +142,17 @@ bool ConfigurationReader::parse_configuration_options( const variables_map &vm ) cout << ConfigFileCmdStr << "=" << config_file_name << endl; } + // source-network-interface + if ( vm.count( SourceNetworkInterfaceCmdStr ) ) + { + string source_network_interface = + vm[ SourceNetworkInterfaceCmdStr ].as (); + Config.set_source_network_interface( source_network_interface ); + + cout << SourceNetworkInterfaceCmdStr << "=" << source_network_interface + << endl; + } + // hosts-down-limit int host_down_limit = 0; if ( vm.count( HostsDownLimitCmdStr ) ) diff --git a/src/config/configurationreader.h b/src/config/configurationreader.h index 875e4d0..313e23a 100644 --- a/src/config/configurationreader.h +++ b/src/config/configurationreader.h @@ -61,6 +61,8 @@ private: const std::string DefaultConfigFileName; const std::string ConfigFileCmdStr; const std::string ConfigFileCmdDesc; + const std::string SourceNetworkInterfaceCmdStr; + const std::string SourceNetworkInterfaceCmdDesc; const int DefaultHostsDownLimit; const std::string HostsDownLimitCmdStr; const std::string HostsDownLimitCmdDesc; -- 1.7.1