vector< PingSchedulerItem > scheduler_list;
BOOST_FOREACH( HostItem host, hosts )
{
+ string ping_address = (*host).get_address();
+ uint ping_interval = (*host).get_interval();
PingSchedulerItem scheduler(
- new PingScheduler( io_service, *host )
+ new PingScheduler(
+ io_service, ping_address, ping_interval
+ )
);
scheduler_list.push_back( scheduler );
}
scheduler->start_pinging();
}
- // Main loop to handle ping requests when they were scheduled
+ // Main loop to handle scheduled ping requests
io_service.run();
}
#include <iostream>
#include "boostpinger.h"
+#include "dnsresolver.h"
#include "pingscheduler.h"
using namespace std;
+using namespace boost;
using namespace boost::asio;
using namespace boost::posix_time;
PingScheduler::PingScheduler(
boost::asio::io_service &io_service,
- const Host &host
+ const string &ping_address,
+ const uint ping_interval_in_sec
) :
IoService( io_service ),
Timer( io_service ),
TimeSentLastPing( microsec_clock::universal_time() ),
- DestinationHost( host )
+ IpList( ping_address ),
+ PingIntervalInSec( ping_interval_in_sec )
{
}
void PingScheduler::start_pinging()
{
- string destination = DestinationHost.get_address();
- uint ping_set_total = 1; // TODO configurable: amount of pings each time
- uint ping_set_count = 0;
- while ( ping_set_count < ping_set_total )
- {
- ping( destination );
-
- ping_set_count++;
- }
+ // try cyclic the hosts in the list
+ // if we get back to the front of the list, analyze the result
+ // if this X% fail is greater than the threshold, mark the host as down
+ // otherwise, the host is up
+ // advice the external system about the host situation
+
+ string destination_ip = IpList.get_next_ip();
+
+ ping( destination_ip );
}
void PingScheduler::ping( const string &destination )
{
BOOST_ASSERT( !destination.empty() );
+ io_service io_service;
uint echo_reply_timeout_in_sec = 5; // TODO configurable: this is the timeout to WAIT FOR the ping before considering a timeout
- boost::asio::io_service io_service;
BoostPinger pinger( io_service, echo_reply_timeout_in_sec );
uint times_to_ping = 1; // TODO configurable: this must be automatically selected
pinger.ping( destination, times_to_ping );
void PingScheduler::update_ping_statistics()
{
- ptime now = microsec_clock::universal_time(); // TODO
- cerr << "- Time elapsed since last ping = "
- << (now - TimeSentLastPing).total_seconds() << "s" << endl; // TODO
- TimeSentLastPing = microsec_clock::universal_time(); // TODO
+ ptime now = microsec_clock::universal_time();
+ cerr << "- Time elapsed since last ping: "
+ << (now - TimeSentLastPing).total_seconds() << "s" << endl; // TODO reformat this message
+
+ TimeSentLastPing = microsec_clock::universal_time();
}
void PingScheduler::schedule_next_ping()
{
- uint interval = DestinationHost.get_interval(); // TODO configurable:
- Timer.expires_from_now( seconds( interval ) );
- Timer.async_wait( boost::bind( &PingScheduler::handle_next_ping, this ) );
+ Timer.expires_from_now( seconds( PingIntervalInSec ) );
+ Timer.async_wait( bind( &PingScheduler::handle_next_ping, this ) );
}
void PingScheduler::handle_next_ping()
#include <boost/shared_ptr.hpp>
#include <string>
-#include "host.h"
+#include "dnsresolver.h"
//-----------------------------------------------------------------------------
// PingScheduler
public:
PingScheduler(
boost::asio::io_service &io_service,
- const Host &host
+ const std::string &ping_address,
+ const uint ping_interval_in_sec
);
virtual ~PingScheduler();
boost::asio::io_service &IoService;
boost::asio::deadline_timer Timer;
boost::posix_time::ptime TimeSentLastPing;
- Host DestinationHost;
+ DnsResolver IpList;
+ const uint PingIntervalInSec;
};