improved information content of logs: in LinkAnalyzer messages add cname chain
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Fri, 29 May 2015 08:30:51 +0000 (10:30 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Fri, 29 May 2015 08:30:51 +0000 (10:30 +0200)
unfortunately this means a dependency of LinkAnalzer from DNS, so had to change
CMake for test_linkstatus quite a bit

src/dns/dnscache.cpp
src/dns/dnscache.h
src/dns/dnsmaster.cpp
src/dns/dnsmaster.h
src/host/pingscheduler.cpp
src/link/linkstatus.cpp
test/CMakeLists.test_linkstatus.txt
test/CMakeLists.txt

index bf68129..d766f7a 100644 (file)
@@ -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();
+}
index e1ed495..9dc0bc7 100644 (file)
@@ -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:
index c6bca7f..83f6613 100644 (file)
@@ -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;
+}
index 6b2a8b9..a90a8ca 100644 (file)
@@ -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;
index d259f2e..c014db5 100644 (file)
@@ -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;
 
index defea52..51dcb1e 100644 (file)
@@ -23,6 +23,8 @@ on this file might be covered by the GNU General Public License.
 
 #include <logfunc.hpp>
 
+#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() )
     {
index d4f8c7c..35269f9 100644 (file)
@@ -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
index 7404ed2..8162a05 100644 (file)
@@ -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})