From d7ffab6e89a08bcec75783c523d0e754a8939b46 Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Wed, 4 May 2011 10:50:49 +0200 Subject: [PATCH] Alternative approach to solve: - If one of the "[host]" in the configuration file omit the "interval" entry, the application uses the next "[host]"'s "interval" entry, instead of a default value. The problem is specific to the configuration read classes that are not smart enough to verify which "[host]" have this entry and which don't. Example: [host] name=A [host] name=B interval=1 [host] name=C interval=3 Thus, the tuples will be (A,1) , (B,3), (C,?), but A should have a default value, instead of borrow B's value. The approach consists of ensure the program only runs if there is an interval for every single host. --- TODO | 17 ----------------- src/config/configurationreader.cpp | 21 ++++++++++++++------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/TODO b/TODO index 7baf1f2..79c0ee8 100644 --- a/TODO +++ b/TODO @@ -27,23 +27,6 @@ TODO Guilherme: - fix config parser: -- If one of the "[host]" in the configuration file omit the "interval" entry, - the application uses the next "[host]"'s "interval" entry, instead of a - default value. The problem is specific to the configuration read classes - that are not smart enough to verify which "[host]" have this entry and which - don't. - Example: - [host] - name=A - [host] - name=B - interval=1 - [host] - name=C - interval=3 - Thus, the tuples will be (A,1) , (B,3), (C,?), but A should have a default - value, instead of borrow B's value. - - Perform a better treatment of missing configuration items, actually the application just crashes. diff --git a/src/config/configurationreader.cpp b/src/config/configurationreader.cpp index 7be6ee6..d963fa9 100644 --- a/src/config/configurationreader.cpp +++ b/src/config/configurationreader.cpp @@ -246,8 +246,8 @@ bool ConfigurationReader::parse_configuration_options( const variables_map &vm ) } // [host] name - size_t hosts_names_count = vm.count( HostNameCmdStr ); - if ( hosts_names_count > 0 ) + size_t hosts_names_count = 0; + if ( vm.count( HostNameCmdStr ) > 0 ) { HostList hosts_list; @@ -263,13 +263,14 @@ bool ConfigurationReader::parse_configuration_options( const variables_map &vm ) Config.set_hosts( hosts_list ); - BOOST_ASSERT( hosts_names_count == hosts_names.size() ); + hosts_names_count = hosts_names.size(); + BOOST_ASSERT( hosts_names_count >= static_cast( host_down_limit ) ); } // [host] interval - size_t hosts_interval_count = vm.count( HostIntervalCmdStr ); - if ( hosts_interval_count > 0 ) + size_t hosts_interval_count = 0; + if ( vm.count( HostIntervalCmdStr ) > 0 ) { HostList hosts_list = Config.get_hosts(); HostList::iterator hosts_it = hosts_list.begin(); @@ -285,10 +286,16 @@ bool ConfigurationReader::parse_configuration_options( const variables_map &vm ) << host_interval_in_sec << endl; } - BOOST_ASSERT( hosts_interval_count == hosts_intervals.size() ); + hosts_interval_count = hosts_intervals.size(); } - // TODO deal when interval for a given host was not set. use DefaultHostIntervalInSec + // make sure there is always an interval for each host + if ( hosts_names_count != hosts_interval_count ) + { + GlobalLogger.error() << "Could not parse configuration file." << + " Missing an interval entry for one of the hosts." << endl; + return false; + } BOOST_ASSERT( hosts_names_count == hosts_interval_count ); -- 1.7.1