From e638894d4f1654b4c81c3fb8286ba78ec218f185 Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Fri, 29 May 2015 10:30:51 +0200 Subject: [PATCH] improved information content of logs: in LinkAnalyzer messages add cname chain unfortunately this means a dependency of LinkAnalzer from DNS, so had to change CMake for test_linkstatus quite a bit --- src/dns/dnscache.cpp | 29 +++++++++++++++++++++++++++++ src/dns/dnscache.h | 1 + src/dns/dnsmaster.cpp | 8 ++++++++ src/dns/dnsmaster.h | 3 +++ src/host/pingscheduler.cpp | 3 ++- src/link/linkstatus.cpp | 8 +++++--- test/CMakeLists.test_linkstatus.txt | 9 +++++++++ test/CMakeLists.txt | 2 +- 8 files changed, 58 insertions(+), 5 deletions(-) diff --git a/src/dns/dnscache.cpp b/src/dns/dnscache.cpp index bf68129..d766f7a 100644 --- a/src/dns/dnscache.cpp +++ b/src/dns/dnscache.cpp @@ -511,3 +511,32 @@ std::string DnsCache::get_first_outdated_cname(const std::string &hostname, // --> all are up-to-date return ""; } + +std::string DnsCache::get_cname_chain_str(const std::string &hostname) +{ + std::stringstream temp; + temp << hostname; + std::string current_host = hostname; + Cname current_cname; + int n_recursions = 0; + int max_recursion_count = DnsMaster::get_instance() + ->get_max_recursion_count(); + while (true) + { + if (n_recursions >= max_recursion_count) + { + temp << "..."; + break; + } + + current_cname = get_cname(current_host, false); + if (current_cname.Host.empty()) + break; + else + { + current_host = current_cname.Host; + temp << "-->" << current_host; + } + } + return temp.str(); +} diff --git a/src/dns/dnscache.h b/src/dns/dnscache.h index e1ed495..9dc0bc7 100644 --- a/src/dns/dnscache.h +++ b/src/dns/dnscache.h @@ -76,6 +76,7 @@ public: const bool check_up_to_date=false); std::string get_first_outdated_cname(const std::string &hostname, const uint32_t ttl_thresh); + std::string get_cname_chain_str(const std::string &hostname); // variables private: diff --git a/src/dns/dnsmaster.cpp b/src/dns/dnsmaster.cpp index c6bca7f..83f6613 100644 --- a/src/dns/dnsmaster.cpp +++ b/src/dns/dnsmaster.cpp @@ -217,3 +217,11 @@ int DnsMaster::get_max_recursion_count() const return MaxRecursionCount; } +std::string DnsMaster::get_cname_chain_str(const std::string &hostname) +{ + DnsMasterItem master = get_instance(); + if (master) + return master->Cache->get_cname_chain_str(hostname); + else + return hostname; +} diff --git a/src/dns/dnsmaster.h b/src/dns/dnsmaster.h index 6b2a8b9..a90a8ca 100644 --- a/src/dns/dnsmaster.h +++ b/src/dns/dnsmaster.h @@ -115,6 +115,9 @@ public: int get_max_address_resolution_attempts() const; int get_max_recursion_count() const; + // access to Cache + static std::string get_cname_chain_str(const std::string &hostname); + // variables private: IoServiceItem IoService; diff --git a/src/host/pingscheduler.cpp b/src/host/pingscheduler.cpp index d259f2e..c014db5 100644 --- a/src/host/pingscheduler.cpp +++ b/src/host/pingscheduler.cpp @@ -417,7 +417,8 @@ void PingScheduler::update_ping_number() NPingers.increase(); GlobalLogger.notice() << LogPrefix << "No reply from host, " - << "switching to burst ping mode with longer timeouts"; + << "switching to burst ping mode with longer timeouts (" + << DnsMaster::get_cname_chain_str(DestinationAddress) << ")"; GlobalLogger.debug() << LogPrefix << "- Increasing ping number to: " << NPingers; diff --git a/src/link/linkstatus.cpp b/src/link/linkstatus.cpp index defea52..51dcb1e 100644 --- a/src/link/linkstatus.cpp +++ b/src/link/linkstatus.cpp @@ -23,6 +23,8 @@ on this file might be covered by the GNU General Public License. #include +#include "dns/dnsmaster.h" + #include "boost_assert_handler.h" using namespace std; @@ -87,11 +89,11 @@ void LinkStatus::notify_host_up( const string &host_address ) if (has_changed) GlobalLogger.notice() << "Status (" << HostsDownList.size() << "/" << HostsDownLimit << " down): now up again is " - << host_address << endl; + << DnsMaster::get_cname_chain_str(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; + << DnsMaster::get_cname_chain_str(host_address) << endl; if ( !exceeded_host_down_limit() ) { @@ -119,7 +121,7 @@ void LinkStatus::notify_host_down( const string &host_address ) // report this always at notice level GlobalLogger.notice() << "Status (" << HostsDownList.size() << "/" << HostsDownLimit << " down): down is " - << host_address << endl; + << DnsMaster::get_cname_chain_str(host_address) << endl; if ( exceeded_host_down_limit() ) { diff --git a/test/CMakeLists.test_linkstatus.txt b/test/CMakeLists.test_linkstatus.txt index d4f8c7c..35269f9 100644 --- a/test/CMakeLists.test_linkstatus.txt +++ b/test/CMakeLists.test_linkstatus.txt @@ -3,6 +3,15 @@ add_executable(test_linkstatus test_linkstatus ${CMAKE_SOURCE_DIR}/src/boost_assert_handler.cpp ${CMAKE_SOURCE_DIR}/src/link/linkstatus.cpp + ${CMAKE_SOURCE_DIR}/src/dns/hostaddress.cpp + ${CMAKE_SOURCE_DIR}/src/dns/timetolive.cpp + ${CMAKE_SOURCE_DIR}/src/host/pinger.cpp + ${CMAKE_SOURCE_DIR}/src/host/pingprotocol.cpp + ${CMAKE_SOURCE_DIR}/src/dns/dnsipprotocol.cpp + ${CMAKE_SOURCE_DIR}/src/dns/dnscache.cpp + ${CMAKE_SOURCE_DIR}/src/dns/resolverbase.cpp + ${CMAKE_SOURCE_DIR}/src/dns/dnsresolver.cpp + ${CMAKE_SOURCE_DIR}/src/dns/dnsmaster.cpp ) # linker: link the program against the libraries diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7404ed2..8162a05 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -5,7 +5,7 @@ include(FindPkgConfig) set(Boost_USE_STATIC_LIBS OFF) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) -find_package(Boost 1.44 COMPONENTS unit_test_framework system program_options REQUIRED) +find_package(Boost 1.44 COMPONENTS unit_test_framework system program_options date_time serialization REQUIRED) include_directories(${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) -- 1.7.1