- the main purpose of this class is to decide whether the link is down or up, by keeping track the amount of hosts down.
- renamed the variable Analyzer to HostAnalyzer to avoid confusion with the LinkAnalyzer
icmp/icmpheader.cpp
icmp/icmppacket.cpp
icmp/ipv4header.cpp
- notify/statusnotifier.cpp
+ notify/linkstatusanalyzer.cpp
notify/statusnotifiercommand.cpp
ping/boostpinger.cpp
ping/hoststatusanalyzer.cpp
#include "config/configurationreader.h"
#include "config/host.h"
-#include "notify/statusnotifier.h"
+#include "notify/linkstatusanalyzer.h"
#include "ping/pingscheduler.h"
using namespace std;
// TODO init_notifier and get_notifier
int hosts_down_limit = config.get_hosts_down_limit();
string status_notifier_cmd = config.get_status_notifier_cmd();
- shared_ptr<StatusNotifier> notifier(
- new StatusNotifier( hosts_down_limit, status_notifier_cmd )
+ shared_ptr<LinkStatusAnalyzer> link_analyzer(
+ new LinkStatusAnalyzer( hosts_down_limit, status_notifier_cmd )
);
// TODO init_pingers()
PingSchedulerItem scheduler(
new PingScheduler(
io_service, ping_address, ping_interval,
- ping_fail_limit, notifier
+ ping_fail_limit, link_analyzer
)
);
scheduler_list.push_back( scheduler );
-#include "notify/statusnotifier.h"
+#include "notify/linkstatusanalyzer.h"
#include <iostream>
using namespace std;
//-----------------------------------------------------------------------------
-// StatusNotifier
+// LinkStatusAnalyzer
//-----------------------------------------------------------------------------
-StatusNotifier::StatusNotifier(
+LinkStatusAnalyzer::LinkStatusAnalyzer(
const int hosts_down_limit,
const string &status_notifier_cmd
) :
BOOST_ASSERT( !status_notifier_cmd.empty() );
}
-StatusNotifier::~StatusNotifier()
+LinkStatusAnalyzer::~LinkStatusAnalyzer()
{
}
-void StatusNotifier::notify_host_up( const string &host_address )
+void LinkStatusAnalyzer::notify_host_up( const string &host_address )
{
BOOST_ASSERT( !host_address.empty() );
if ( !exceeded_host_down_limit() )
{
- notify_system_up();
+ notify_link_up();
}
// removed from the list?
BOOST_ASSERT( HostsDownList.count( host_address ) == 0 );
}
-void StatusNotifier::notify_host_down( const string &host_address )
+void LinkStatusAnalyzer::notify_host_down( const string &host_address )
{
BOOST_ASSERT( !host_address.empty() );
if ( exceeded_host_down_limit() )
{
- notify_system_down();
+ notify_link_down();
}
// inserted in the list?
BOOST_ASSERT( HostsDownList.count( host_address ) == 1 );
}
-void StatusNotifier::add_host_up( const string &host_address )
+void LinkStatusAnalyzer::add_host_up( const string &host_address )
{
if ( HostsDownList.count( host_address ) > 0 )
{
}
}
-void StatusNotifier::add_host_down( const string &host_address )
+void LinkStatusAnalyzer::add_host_down( const string &host_address )
{
HostsDownList.insert( host_address );
}
-bool StatusNotifier::exceeded_host_down_limit() const
+bool LinkStatusAnalyzer::exceeded_host_down_limit() const
{
int host_down_count = HostsDownList.size();
return ( host_down_count > HostsDownLimit );
}
-void StatusNotifier::notify_system_up()
+void LinkStatusAnalyzer::notify_link_up()
{
StatusNotifierCmd.set_token_value(
StatusNotifierCommand::StatusToken,
StatusNotifierCmd.execute();
}
-void StatusNotifier::notify_system_down()
+void LinkStatusAnalyzer::notify_link_down()
{
StatusNotifierCmd.set_token_value(
StatusNotifierCommand::StatusToken,
-#ifndef STATUSNOTIFIER_H
-#define STATUSNOTIFIER_H
+#ifndef LINKSTATUSANALYZER_H
+#define LINKSTATUSANALYZER_H
#include <set>
#include <string>
#include "notify/statusnotifiercommand.h"
//-----------------------------------------------------------------------------
-// StatusNotifier
+// LinkStatusAnalyzer
//-----------------------------------------------------------------------------
/**
- * @brief This class is responsible for notify when the system is down, by
- * keeping track of the number of hosts down.
+ * @brief This class analyzes and notifies the link status, through keeping
+ * track of the amount of hosts down.
* Scope: one object for many hosts.
*/
-class StatusNotifier
+class LinkStatusAnalyzer
{
public:
- StatusNotifier(
+ LinkStatusAnalyzer(
const int hosts_down_limit,
const std::string &status_notifier_cmd
);
- virtual ~StatusNotifier();
+ virtual ~LinkStatusAnalyzer();
void notify_host_up( const std::string &host_address );
void notify_host_down( const std::string &host_address );
bool exceeded_host_down_limit() const;
- void notify_system_up();
- void notify_system_down();
+ void notify_link_up();
+ void notify_link_down();
private:
const int HostsDownLimit;
};
-#endif /* STATUSNOTIFIER_H */
+#endif /* LINKSTATUSANALYZER_H */
#include <boost/assert.hpp>
-#include "notify/statusnotifier.h"
-
using namespace std;
using namespace boost;
* @param host_address the address of the host it has to analyze.
* @param ping_fail_percentage_limit the percentage threshold of pings that can
* fail.
- * @param notifier the object used to notify the status of the host.
+ * @param link_analyzer the object used to notify the status of the host.
*/
HostStatusAnalyzer::HostStatusAnalyzer(
const string &host_address,
const int ping_fail_percentage_limit,
- shared_ptr<StatusNotifier> notifier
+ shared_ptr<LinkStatusAnalyzer> link_analyzer
) :
HostAddress( host_address ),
- Notifier( notifier ),
+ LinkAnalyzer( link_analyzer ),
PingFailPercentageLimit( ping_fail_percentage_limit ),
ResolvedIpCount( 0 ),
PingsPerformedCount( 0 ),
// notify if the amount of pings that failed exceed the limit
if ( exceeded_ping_failed_limit() )
{
- Notifier->notify_host_down( HostAddress );
+ LinkAnalyzer->notify_host_down( HostAddress );
}
else
{
- Notifier->notify_host_up( HostAddress );
+ LinkAnalyzer->notify_host_up( HostAddress );
}
}
#include <boost/shared_ptr.hpp>
-class StatusNotifier;
+#include "notify/linkstatusanalyzer.h"
//-----------------------------------------------------------------------------
// HostStatusAnalyzer
HostStatusAnalyzer(
const std::string &host_address,
const int ping_fail_percentage_limit,
- boost::shared_ptr<StatusNotifier> notifier
+ boost::shared_ptr<LinkStatusAnalyzer> link_analyzer
);
virtual ~HostStatusAnalyzer();
private:
std::string HostAddress;
- boost::shared_ptr<StatusNotifier> Notifier;
+ boost::shared_ptr<LinkStatusAnalyzer> LinkAnalyzer;
int PingFailPercentageLimit;
int ResolvedIpCount;
int PingsPerformedCount;
#include <boost/bind.hpp>
#include "dns/dnsresolver.h"
-#include "notify/statusnotifier.h"
+#include "notify/linkstatusanalyzer.h"
#include "ping/boostpinger.h"
using namespace std;
const string &ping_address,
const long ping_interval_in_sec,
const int ping_fail_percentage_limit,
- shared_ptr<StatusNotifier> notifier
+ shared_ptr<LinkStatusAnalyzer> link_analyzer
) :
IoService( io_service ),
TimeSentLastPing( microsec_clock::universal_time() ),
PingIntervalInSec( ping_interval_in_sec ),
IpList( ping_address ),
- Analyzer( ping_address, ping_fail_percentage_limit, notifier )
+ HostAnalyzer( ping_address, ping_fail_percentage_limit, link_analyzer )
{
}
}
int resolved_ip_count = IpList.get_resolved_ip_count();
- Analyzer.set_resolved_ip_count( resolved_ip_count );
+ HostAnalyzer.set_resolved_ip_count( resolved_ip_count );
return true;
}
void PingScheduler::update_ping_statistics( const bool ping_success )
{
- Analyzer.update_ping_statistics( ping_success );
+ HostAnalyzer.update_ping_statistics( ping_success );
// TODO you must call the method bellow AFTER update_ping_statistics
// Fix this method, once it has a semantic dependency with the
void PingScheduler::update_ping_interval()
{
// must to ping more often?
- if ( Analyzer.exceeded_ping_failed_limit() )
+ if ( HostAnalyzer.exceeded_ping_failed_limit() )
{
PingIntervalInSec.speed_up();
#include <boost/shared_ptr.hpp>
#include "dns/dnsresolver.h"
+#include "notify/linkstatusanalyzer.h"
#include "ping/hoststatusanalyzer.h"
#include "ping/pinginterval.h"
-class StatusNotifier;
-
//-----------------------------------------------------------------------------
// PingScheduler
//-----------------------------------------------------------------------------
const std::string &ping_address,
const long ping_interval_in_sec,
const int ping_fail_percentage_limit,
- boost::shared_ptr<StatusNotifier> notifier
+ boost::shared_ptr<LinkStatusAnalyzer> link_analyzer
);
virtual ~PingScheduler();
boost::posix_time::ptime TimeSentLastPing;
PingInterval<long> PingIntervalInSec;
DnsResolver IpList;
- HostStatusAnalyzer Analyzer;
+ HostStatusAnalyzer HostAnalyzer;
};