Improved logging and added code to handle failed dns lookup of cached dns record.
authorBjoern Sikora <bjoern.sikora@intra2net.com>
Tue, 25 Aug 2009 14:56:42 +0000 (16:56 +0200)
committerBjoern Sikora <bjoern.sikora@intra2net.com>
Tue, 25 Aug 2009 14:56:42 +0000 (16:56 +0200)
src/logger.cpp
src/logger.h
src/updater.cpp

index 96797bd..a45b42a 100644 (file)
@@ -975,3 +975,37 @@ void Logger::print_starting_shutdown_parent() const
         log_notice(msg.str());
     }
 }
+
+
+/**
+ * DNS cache record timeout
+ * @param hostname Hostname
+ * @param lastupdated Lastupdated
+ * @param dns_cache_ttl DNS cache TTL
+ * @param current_time Current time
+ */
+void Logger::print_recheck_dns_entry(const std::string& hostname, const int lastupdated, const int dns_cache_ttl, const int current_time) const
+{
+    if ( 1 <= Loglevel )
+    {
+        ostringstream msg;
+        msg << "DNS cache record for host <" << hostname << "> expired: Lastupdated: " << lastupdated << " DNS cache ttl: " << dns_cache_ttl << " Current time: " << current_time << " Checking current DNS cache status." << endl;
+        log_notice(msg.str());
+    }
+}
+
+
+/**
+ * Found following cached DNS record
+ * @param hostname Hostname
+ * @param cached_dns_entry IP
+ */
+void Logger::print_cached_dns_entry(const std::string& hostname, const std::string& cached_dns_entry, const std::string& lastupdated_ip) const
+{
+    if ( 1 <= Loglevel )
+    {
+        ostringstream msg;
+        msg << "Cached DNS record for host <" << hostname << "> : " << cached_dns_entry << " Last updated IP: " << lastupdated_ip << endl;
+        log_notice(msg.str());
+    }
+}
index 1a08f15..085ed67 100644 (file)
@@ -160,6 +160,10 @@ public:
     void print_shutdown_parent_succeeded() const;
 
     void print_starting_shutdown_parent() const;
+
+    void print_recheck_dns_entry(const std::string& hostname, const int lastupdated, const int dns_cache_ttl, const int current_time) const;
+
+    void print_cached_dns_entry(const std::string& hostname, const std::string& cached_dns_entry, const std::string& lastupdated_ip) const;
 };
 
 #endif
index 6bc1239..484444d 100644 (file)
@@ -189,7 +189,13 @@ void Updater::update_services()
                 lastupdated = service->get_last_updates()->front();
 
             if ( (lastupdated != 0) && ((lastupdated + service->get_dns_cache_ttl()) < current_time) )
-                dns_recheck_ip = IPHelp->dns_query(service->get_hostname());
+            {
+                Log->print_recheck_dns_entry(service->get_hostname(),lastupdated,service->get_dns_cache_ttl(),current_time);
+                string _dns_recheck_ip = IPHelp->dns_query(service->get_hostname());
+                Log->print_cached_dns_entry(service->get_hostname(), _dns_recheck_ip, service->get_actual_ip());
+                if (!_dns_recheck_ip.empty())
+                    dns_recheck_ip = _dns_recheck_ip;
+            }
 
             if ( (service->get_actual_ip() != ip) || (dns_recheck_ip != ip)  )
                 service->update(ip,current_time);