From: Guilherme Maciel Ferreira Date: Tue, 23 Aug 2011 01:30:39 +0000 (-0300) Subject: Reads the host port from configuration file X-Git-Tag: v1.1^2~4 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=b32f744478db60e0dc4d8e96584059a1c1e29a23;p=pingcheck Reads the host port from configuration file --- diff --git a/src/config/configurationreader.cpp b/src/config/configurationreader.cpp index 3928b28..9eee6fd 100644 --- a/src/config/configurationreader.cpp +++ b/src/config/configurationreader.cpp @@ -21,6 +21,7 @@ on this file might be covered by the GNU General Public License. #include #include +#include #include #include @@ -74,6 +75,9 @@ ConfigurationReader::ConfigurationReader() : LinkDownIntervalCmdDesc( "How long the link must be offline in order to consider it down." ), HostNameCmdStr( "host.name" ), HostNameCmdDesc( "Host address" ), + DefaultHostPort( 80 ), // HTTP port + HostPortCmdStr( "host.port" ), + HostPortCmdDesc( "Host port number" ), DefaultHostIntervalInSec( 60 ), // 60 seconds HostIntervalCmdStr( "host.interval" ), HostIntervalCmdDesc( "Interval between each ping to the host" ) @@ -216,6 +220,7 @@ options_description ConfigurationReader::get_configuration_options() const ( LinkUpIntervalCmdStr.c_str(), value()->default_value( DefaultLinkUpIntervalInMin ), LinkUpIntervalCmdDesc.c_str() ) ( LinkDownIntervalCmdStr.c_str(), value()->default_value( DefaultLinkDownIntervalInMin ), LinkDownIntervalCmdDesc.c_str() ) ( HostNameCmdStr.c_str(), value< vector >(), HostNameCmdDesc.c_str() ) + ( HostPortCmdStr.c_str(), value< vector >(), HostPortCmdDesc.c_str() ) ( HostIntervalCmdStr.c_str(), value< vector >(), HostIntervalCmdDesc.c_str() ) ; @@ -316,6 +321,8 @@ bool ConfigurationReader::parse_configuration_options( const variables_map &vm ) vector hosts_names = vm[ HostNameCmdStr ].as< vector > (); BOOST_FOREACH( string host_name, hosts_names ) { + BOOST_ASSERT( !host_name.empty() ); + HostItem host_item( new Host( host_name ) ); hosts_list.push_back( host_item ); @@ -330,6 +337,28 @@ bool ConfigurationReader::parse_configuration_options( const variables_map &vm ) BOOST_ASSERT( hosts_names_count >= static_cast( host_down_limit ) ); } + // [host] port + size_t host_port_count = 0; + if ( vm.count( HostPortCmdStr ) > 0 ) + { + HostList hosts_list = Config.get_hosts(); + HostList::iterator hosts_it = hosts_list.begin(); + + vector hosts_ports = vm[ HostPortCmdStr ].as< vector >(); + BOOST_FOREACH( int host_port, hosts_ports ) + { + BOOST_ASSERT( ( 0 <= host_port ) && ( host_port <= numeric_limits::max() ) ); + + HostItem host_item = *hosts_it; + host_item->set_port( static_cast(host_port) ); + ++hosts_it; + + GlobalLogger.info() << HostPortCmdStr << "=" << host_port << endl; + } + + host_port_count = hosts_ports.size(); + } + // [host] interval size_t hosts_interval_count = 0; if ( vm.count( HostIntervalCmdStr ) > 0 ) @@ -337,9 +366,11 @@ bool ConfigurationReader::parse_configuration_options( const variables_map &vm ) HostList hosts_list = Config.get_hosts(); HostList::iterator hosts_it = hosts_list.begin(); - vector hosts_intervals = vm[ HostIntervalCmdStr ].as< vector > (); + vector hosts_intervals = vm[ HostIntervalCmdStr ].as< vector >(); BOOST_FOREACH( int host_interval_in_sec, hosts_intervals ) { + BOOST_ASSERT( 0 < host_interval_in_sec ); + HostItem host_item = *hosts_it; host_item->set_interval_in_sec( host_interval_in_sec ); ++hosts_it; @@ -359,6 +390,7 @@ bool ConfigurationReader::parse_configuration_options( const variables_map &vm ) return false; } + BOOST_ASSERT( hosts_names_count == host_port_count ); BOOST_ASSERT( hosts_names_count == hosts_interval_count ); return true; diff --git a/src/config/configurationreader.h b/src/config/configurationreader.h index 338db85..3365ce6 100644 --- a/src/config/configurationreader.h +++ b/src/config/configurationreader.h @@ -107,6 +107,9 @@ private: const std::string LinkDownIntervalCmdDesc; const std::string HostNameCmdStr; const std::string HostNameCmdDesc; + const int DefaultHostPort; + const std::string HostPortCmdStr; + const std::string HostPortCmdDesc; const int DefaultHostIntervalInSec; const std::string HostIntervalCmdStr; const std::string HostIntervalCmdDesc;