From: Christian Herdtweck Date: Wed, 6 May 2015 13:27:19 +0000 (+0200) Subject: made link status analyzer more talkative X-Git-Url: http://developer.intra2net.com/git/?p=pingcheck;a=commitdiff_plain;h=f5ffc5df4bf89f403a6c0b7966191dca54520b9d made link status analyzer more talkative --- diff --git a/src/link/linkstatus.cpp b/src/link/linkstatus.cpp index fa500a6..defea52 100644 --- a/src/link/linkstatus.cpp +++ b/src/link/linkstatus.cpp @@ -82,9 +82,16 @@ void LinkStatus::notify_host_up( const string &host_address ) { BOOST_ASSERT( !host_address.empty() ); - GlobalLogger.info() << "- Host up: " << host_address << endl; + bool has_changed = add_host_up( host_address ); - add_host_up( host_address ); + if (has_changed) + GlobalLogger.notice() << "Status (" << HostsDownList.size() + << "/" << HostsDownLimit << " down): now up again is " + << host_address << endl; + else // less important so log only at info level + GlobalLogger.info() << "Status (" << HostsDownList.size() + << "/" << HostsDownLimit << " down): still up is " + << host_address << endl; if ( !exceeded_host_down_limit() ) { @@ -107,10 +114,13 @@ void LinkStatus::notify_host_down( const string &host_address ) { BOOST_ASSERT( !host_address.empty() ); - GlobalLogger.info() << "- Host down: " << host_address << endl; - add_host_down( host_address ); + // report this always at notice level + GlobalLogger.notice() << "Status (" << HostsDownList.size() + << "/" << HostsDownLimit << " down): down is " + << host_address << endl; + if ( exceeded_host_down_limit() ) { notify_link_down(); @@ -120,14 +130,20 @@ void LinkStatus::notify_host_down( const string &host_address ) BOOST_ASSERT( HostsDownList.count( host_address ) == 1 ); } //lint !e1788 -void LinkStatus::add_host_up( const string &host_address ) +// returns true if this did change something (i.e. host had been down) +bool LinkStatus::add_host_up( const string &host_address ) { if ( HostsDownList.count( host_address ) > 0 ) { size_t erased_host_count = HostsDownList.erase( host_address ); BOOST_ASSERT( erased_host_count == 1 ); + + return true; } + else + return false; + } void LinkStatus::add_host_down( const string &host_address ) @@ -158,6 +174,8 @@ void LinkStatus::notify_link_up() "up" ); //lint !e534 + GlobalLogger.notice() << "Status (" << HostsDownList.size() + << "/" << HostsDownLimit << " down): report link up" << endl; bool executed = StatusNotifierCmd->execute(); if ( executed ) @@ -178,6 +196,8 @@ void LinkStatus::notify_link_down() BOOST_ASSERT( CurrentLinkStatus == Status_Down ); BOOST_ASSERT( CurrentNotificationStatus == NotificationStatus_NotReported ); + GlobalLogger.notice() << "Status (" << HostsDownList.size() + << "/" << HostsDownLimit << " down): report link down" << endl; StatusNotifierCmd->set_token_value( StatusNotifierCommand::StatusToken, "down" diff --git a/src/link/linkstatus.h b/src/link/linkstatus.h index 30d247c..6353f6c 100644 --- a/src/link/linkstatus.h +++ b/src/link/linkstatus.h @@ -75,7 +75,7 @@ public: // Methods // - void add_host_up( const std::string &host_address ); + bool add_host_up( const std::string &host_address ); void add_host_down( const std::string &host_address ); bool exceeded_host_down_limit() const;