From: Bjoern Sikora Date: Tue, 25 Aug 2009 14:56:42 +0000 (+0200) Subject: Improved logging and added code to handle failed dns lookup of cached dns record. X-Git-Tag: v1.1~216 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=0541cd71893db32b5183bddae38d3bf9cb059d16;p=bpdyndnsd Improved logging and added code to handle failed dns lookup of cached dns record. --- diff --git a/src/logger.cpp b/src/logger.cpp index 96797bd..a45b42a 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -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()); + } +} diff --git a/src/logger.h b/src/logger.h index 1a08f15..085ed67 100644 --- a/src/logger.h +++ b/src/logger.h @@ -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 diff --git a/src/updater.cpp b/src/updater.cpp index 6bc1239..484444d 100644 --- a/src/updater.cpp +++ b/src/updater.cpp @@ -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);