From: Guilherme Maciel Ferreira Date: Fri, 25 Mar 2011 16:45:06 +0000 (+0100) Subject: Renamed StatusNotifier to LinkStatusAnalyzer X-Git-Tag: v1.0~108 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=fb469ffa0be4c250100a0c2ece78782c4c5453c9;p=pingcheck Renamed StatusNotifier to LinkStatusAnalyzer - 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 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fa0d756..d7f1891 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,7 +27,7 @@ set(SOURCES icmp/icmpheader.cpp icmp/icmppacket.cpp icmp/ipv4header.cpp - notify/statusnotifier.cpp + notify/linkstatusanalyzer.cpp notify/statusnotifiercommand.cpp ping/boostpinger.cpp ping/hoststatusanalyzer.cpp diff --git a/src/main.cpp b/src/main.cpp index 6ffff97..e9de4bc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,7 +6,7 @@ #include "config/configurationreader.h" #include "config/host.h" -#include "notify/statusnotifier.h" +#include "notify/linkstatusanalyzer.h" #include "ping/pingscheduler.h" using namespace std; @@ -29,8 +29,8 @@ int main( int argc, char* argv[] ) // 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 notifier( - new StatusNotifier( hosts_down_limit, status_notifier_cmd ) + shared_ptr link_analyzer( + new LinkStatusAnalyzer( hosts_down_limit, status_notifier_cmd ) ); // TODO init_pingers() @@ -43,7 +43,7 @@ int main( int argc, char* argv[] ) PingSchedulerItem scheduler( new PingScheduler( io_service, ping_address, ping_interval, - ping_fail_limit, notifier + ping_fail_limit, link_analyzer ) ); scheduler_list.push_back( scheduler ); diff --git a/src/notify/statusnotifier.cpp b/src/notify/linkstatusanalyzer.cpp similarity index 72% rename from src/notify/statusnotifier.cpp rename to src/notify/linkstatusanalyzer.cpp index b1bca0e..93f9023 100644 --- a/src/notify/statusnotifier.cpp +++ b/src/notify/linkstatusanalyzer.cpp @@ -1,4 +1,4 @@ -#include "notify/statusnotifier.h" +#include "notify/linkstatusanalyzer.h" #include @@ -7,10 +7,10 @@ using namespace std; //----------------------------------------------------------------------------- -// StatusNotifier +// LinkStatusAnalyzer //----------------------------------------------------------------------------- -StatusNotifier::StatusNotifier( +LinkStatusAnalyzer::LinkStatusAnalyzer( const int hosts_down_limit, const string &status_notifier_cmd ) : @@ -22,11 +22,11 @@ StatusNotifier::StatusNotifier( 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() ); @@ -36,14 +36,14 @@ void StatusNotifier::notify_host_up( const string &host_address ) 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() ); @@ -53,14 +53,14 @@ void StatusNotifier::notify_host_down( const string &host_address ) 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 ) { @@ -68,18 +68,18 @@ void StatusNotifier::add_host_up( const string &host_address ) } } -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, @@ -89,7 +89,7 @@ void StatusNotifier::notify_system_up() StatusNotifierCmd.execute(); } -void StatusNotifier::notify_system_down() +void LinkStatusAnalyzer::notify_link_down() { StatusNotifierCmd.set_token_value( StatusNotifierCommand::StatusToken, diff --git a/src/notify/statusnotifier.h b/src/notify/linkstatusanalyzer.h similarity index 68% rename from src/notify/statusnotifier.h rename to src/notify/linkstatusanalyzer.h index 6793c9f..dddc81a 100644 --- a/src/notify/statusnotifier.h +++ b/src/notify/linkstatusanalyzer.h @@ -1,5 +1,5 @@ -#ifndef STATUSNOTIFIER_H -#define STATUSNOTIFIER_H +#ifndef LINKSTATUSANALYZER_H +#define LINKSTATUSANALYZER_H #include #include @@ -7,22 +7,22 @@ #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 ); @@ -33,8 +33,8 @@ private: 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; @@ -43,4 +43,4 @@ private: }; -#endif /* STATUSNOTIFIER_H */ +#endif /* LINKSTATUSANALYZER_H */ diff --git a/src/ping/hoststatusanalyzer.cpp b/src/ping/hoststatusanalyzer.cpp index 47118ea..9d763af 100644 --- a/src/ping/hoststatusanalyzer.cpp +++ b/src/ping/hoststatusanalyzer.cpp @@ -4,8 +4,6 @@ #include -#include "notify/statusnotifier.h" - using namespace std; using namespace boost; @@ -17,15 +15,15 @@ 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 notifier + shared_ptr link_analyzer ) : HostAddress( host_address ), - Notifier( notifier ), + LinkAnalyzer( link_analyzer ), PingFailPercentageLimit( ping_fail_percentage_limit ), ResolvedIpCount( 0 ), PingsPerformedCount( 0 ), @@ -103,11 +101,11 @@ void HostStatusAnalyzer::analyze_ping_statistics() // 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 ); } } diff --git a/src/ping/hoststatusanalyzer.h b/src/ping/hoststatusanalyzer.h index c46cea6..d9e127f 100644 --- a/src/ping/hoststatusanalyzer.h +++ b/src/ping/hoststatusanalyzer.h @@ -5,7 +5,7 @@ #include -class StatusNotifier; +#include "notify/linkstatusanalyzer.h" //----------------------------------------------------------------------------- // HostStatusAnalyzer @@ -22,7 +22,7 @@ public: HostStatusAnalyzer( const std::string &host_address, const int ping_fail_percentage_limit, - boost::shared_ptr notifier + boost::shared_ptr link_analyzer ); virtual ~HostStatusAnalyzer(); @@ -40,7 +40,7 @@ private: private: std::string HostAddress; - boost::shared_ptr Notifier; + boost::shared_ptr LinkAnalyzer; int PingFailPercentageLimit; int ResolvedIpCount; int PingsPerformedCount; diff --git a/src/ping/pingscheduler.cpp b/src/ping/pingscheduler.cpp index 994a90f..47d916d 100644 --- a/src/ping/pingscheduler.cpp +++ b/src/ping/pingscheduler.cpp @@ -5,7 +5,7 @@ #include #include "dns/dnsresolver.h" -#include "notify/statusnotifier.h" +#include "notify/linkstatusanalyzer.h" #include "ping/boostpinger.h" using namespace std; @@ -22,7 +22,7 @@ PingScheduler::PingScheduler( const string &ping_address, const long ping_interval_in_sec, const int ping_fail_percentage_limit, - shared_ptr notifier + shared_ptr link_analyzer ) : IoService( io_service ), @@ -30,7 +30,7 @@ PingScheduler::PingScheduler( 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 ) { } @@ -60,7 +60,7 @@ bool PingScheduler::resolve_ping_address() } 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; } @@ -104,7 +104,7 @@ void PingScheduler::handle_next_ping() 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 @@ -116,7 +116,7 @@ void PingScheduler::update_ping_statistics( const bool ping_success ) 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(); diff --git a/src/ping/pingscheduler.h b/src/ping/pingscheduler.h index bc0caed..915e819 100644 --- a/src/ping/pingscheduler.h +++ b/src/ping/pingscheduler.h @@ -7,11 +7,10 @@ #include #include "dns/dnsresolver.h" +#include "notify/linkstatusanalyzer.h" #include "ping/hoststatusanalyzer.h" #include "ping/pinginterval.h" -class StatusNotifier; - //----------------------------------------------------------------------------- // PingScheduler //----------------------------------------------------------------------------- @@ -29,7 +28,7 @@ public: const std::string &ping_address, const long ping_interval_in_sec, const int ping_fail_percentage_limit, - boost::shared_ptr notifier + boost::shared_ptr link_analyzer ); virtual ~PingScheduler(); @@ -51,7 +50,7 @@ private: boost::posix_time::ptime TimeSentLastPing; PingInterval PingIntervalInSec; DnsResolver IpList; - HostStatusAnalyzer Analyzer; + HostStatusAnalyzer HostAnalyzer; };