#include <stdint.h>
#include <string>
+#include <vector>
#include "host.h"
std::size_t get_limit_to_notify() const;
void set_limit_to_notify( const std::size_t limit_to_notify );
- Host get_host() const;
- void set_host( const Host& host );
+ std::vector<HostItem> get_hosts() const;
+ void set_hosts( const std::vector<HostItem> &hosts_list );
private:
std::string ConfigFileName;
std::size_t LimitToNotify;
- Host Host_;
+ std::vector<HostItem> Hosts;
const std::size_t MinLimitToNotify;
const std::size_t MaxLimitToNotify;
#include <boost/assert.hpp>
+#include <boost/foreach.hpp>
#include <fstream>
#include <iostream>
-#include <iterator>
#include "configurationreader.h"
using namespace std;
+using namespace boost;
using namespace boost::program_options;
//-----------------------------------------------------------------------------
options_description options( "Configuration" );
options.add_options()
( LimitToNotifyCmdStr.c_str(), value<size_t>()->default_value( DefaultLimitToNotify ), LimitToNotifyCmdDesc.c_str() )
- ( HostNameCmdStr.c_str(), value< string >(), HostNameCmdDesc.c_str() )
- ( HostIntervalCmdStr.c_str(), value<size_t>()->default_value( DefaultHostInterval ), HostIntervalCmdDesc.c_str() )
+ ( HostNameCmdStr.c_str(), value< vector<string> >(), HostNameCmdDesc.c_str() )
+ ( HostIntervalCmdStr.c_str(), value< vector<size_t> >(), HostIntervalCmdDesc.c_str() )
;
return options;
cout << LimitToNotifyCmdStr << "=" << limit_to_notify << endl;
}
+ size_t hosts_names_total = 0;
if ( vm.count( HostNameCmdStr ) )
{
- string host_name = vm[ HostNameCmdStr ].as<string> ();
- Host host = Config.get_host();
- host.set_address( host_name );
- Config.set_host( host );
+ vector<HostItem> hosts_list;
- cout << HostNameCmdStr << "=" << host_name << endl;
+ vector<string> hosts_names = vm[ HostNameCmdStr ].as< vector<string> > ();
+ BOOST_FOREACH( string host_name, hosts_names )
+ {
+ HostItem host_item( new Host( host_name ) );
+ hosts_list.push_back( host_item );
+
+ cout << HostNameCmdStr << "=" << host_name << endl;
+ }
+
+ Config.set_hosts( hosts_list );
+
+ hosts_names_total = hosts_names.size();
}
+ size_t hosts_interval_total = 0;
if ( vm.count( HostIntervalCmdStr ) )
{
- size_t host_interval = vm[ HostIntervalCmdStr ].as<size_t> ();
- Host host = Config.get_host();
- host.set_interval( host_interval );
- Config.set_host( host );
+ vector<HostItem> hosts_list = Config.get_hosts();
+ vector<HostItem>::iterator hosts_it = hosts_list.begin();
- cout << HostIntervalCmdStr << "=" << host_interval << endl;
+ vector<size_t> hosts_intervals = vm[ HostIntervalCmdStr ].as< vector<size_t> > ();
+ BOOST_FOREACH( size_t host_interval, hosts_intervals )
+ {
+ HostItem host_item = *hosts_it;
+ host_item->set_interval( host_interval );
+ hosts_it++;
+
+ cout << HostIntervalCmdStr << "=" << host_interval << endl;
+ }
+
+ hosts_interval_total = hosts_intervals.size();
}
+ // TODO deal when interval for a given host was not set. use DefaultHostInterval
+ BOOST_ASSERT(hosts_names_total == hosts_interval_total);
+
return true;
}
}
}
- catch ( exception& e )
+ catch ( std::exception &e )
{
cout << e.what() << endl;
return false;
#include <boost/asio.hpp>
#include <boost/bind.hpp>
+#include <boost/foreach.hpp>
#include <istream>
#include <iostream>
#include <ostream>
+#include <vector>
#include "configurationreader.h"
#include "host.h"
if ( read_success )
{
Configuration config = config_reader.get_configuration();
- Host host = config.get_host();
-
- PingCheck check( host );
- check.start_pinging();
+ vector<HostItem> hosts = config.get_hosts();
+ BOOST_FOREACH( HostItem host, hosts )
+ {
+ PingCheck check( *host );
+ check.start_pinging();
+ }
}
return 0;