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.
}
// [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;
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<size_t>( 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();
<< 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 );