From: Thomas Jarosch Date: Wed, 20 Oct 2010 10:00:30 +0000 (+0200) Subject: Improve logging when IP update is not allowed (log once on log level 0 if we changed... X-Git-Tag: v1.1~35 X-Git-Url: http://developer.intra2net.com/git/?p=bpdyndnsd;a=commitdiff_plain;h=0ebcd4efc05fa4e11e9e7b2166a15a84c884bd45 Improve logging when IP update is not allowed (log once on log level 0 if we changed to online mode) --- diff --git a/src/logger.cpp b/src/logger.cpp index f26fb91..5ec6f35 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -1114,14 +1114,19 @@ void Logger::print_multiple_cmd_option(const string& message) const /** * An update would exceed the update interval. Prints out a warning message. + * @param override_log_level Override log level with zero if true * @param current_time Current time. * @param old_time Time of update #MaxUpdatesWithinInterval ago. * @param MaxUpdatesWithinInterval Number of allowed updates in one update interval. * @param service The service which exceeds update interval. */ -void Logger::print_update_not_allowed(const time_t current_time, const time_t old_time, const int MaxUpdatesWithinInterval, const string& service) +void Logger::print_update_not_allowed(bool override_log_level, const time_t current_time, const time_t old_time, const int MaxUpdatesWithinInterval, const string& service) { int level = 1; + + if (override_log_level) + level = 0; + if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) { ostringstream msg; diff --git a/src/logger.hpp b/src/logger.hpp index 26140fb..62e180c 100644 --- a/src/logger.hpp +++ b/src/logger.hpp @@ -192,7 +192,7 @@ public: void print_multiple_main_conf_option(const std::string& main_conf_file, const std::string& message) const; - void print_update_not_allowed(const time_t current_time, const time_t old_time, const int MaxUpdatesWithinInterval, const std::string& service); + void print_update_not_allowed(bool override_log_level, const time_t current_time, const time_t old_time, const int MaxUpdatesWithinInterval, const std::string& service); void print_update_service_failure(const std::string& service); diff --git a/src/service.cpp b/src/service.cpp index dcc7fa1..a8b52c6 100644 --- a/src/service.cpp +++ b/src/service.cpp @@ -207,9 +207,10 @@ bool Service::operator!= (const Service& other) const /** * Checks if update will exceed max update interval. * @param current_time Current time. + * @param changed_to_online True if we just changed to online, false if we were already online * @return True if update is allowed, false if update would exceed max update interval. */ -bool Service::update_allowed(const time_t current_time) +bool Service::update_allowed(const time_t current_time, bool changed_to_online) { list::iterator iter; int i=0; @@ -218,7 +219,7 @@ bool Service::update_allowed(const time_t current_time) { if ( (i == (MaxUpdatesWithinInterval-1)) && ( (*iter + ((time_t)UpdateInterval*60)) >= current_time ) ) { - Log->print_update_not_allowed(current_time,*iter,MaxUpdatesWithinInterval,get_service_name()); + Log->print_update_not_allowed(changed_to_online, current_time,*iter,MaxUpdatesWithinInterval,get_service_name()); return false; } i++; @@ -230,8 +231,10 @@ bool Service::update_allowed(const time_t current_time) /** * Service update method, common to each service. * @param ip The new ip to set for the hostname. + * @param current_time Current time + * @param changed_to_online True if we just changed to online, false if we were already online */ -void Service::update(const string& ip, const time_t current_time) +void Service::update(const string& ip, const time_t current_time, bool changed_to_online) { const std::string service_name = get_service_name(); @@ -242,11 +245,11 @@ void Service::update(const string& ip, const time_t current_time) return; } - Log->print_update_service(service_name); - // test if update is permitted by UpdateInterval Status - if ( update_allowed(current_time) ) + if ( update_allowed(current_time, changed_to_online) ) { + Log->print_update_service(service_name); + if ( perform_update(ip) == 0 ) { // if update was successful, we need to set the Lastupdated and ActualIP base member. diff --git a/src/service.hpp b/src/service.hpp index 1573bd7..fd5924f 100644 --- a/src/service.hpp +++ b/src/service.hpp @@ -69,9 +69,9 @@ public: virtual int perform_update(const std::string& ip) = 0; - void update(const std::string& ip, const time_t current_time); + void update(const std::string& ip, const time_t current_time, bool changed_to_online); - bool update_allowed(const time_t current_time); + bool update_allowed(const time_t current_time, bool changed_to_online); void set_last_update(const time_t current_time); diff --git a/src/updater.cpp b/src/updater.cpp index 875e03d..84247d5 100644 --- a/src/updater.cpp +++ b/src/updater.cpp @@ -271,7 +271,7 @@ void Updater::update_services(bool changed_to_online) const { // Update Log->print_update_service(hostname, ip_dns_recheck, ip_last_update, ip_host, lastupdated); - service->update(ip_host,current_time); + service->update(ip_host, current_time, changed_to_online); } else { @@ -281,7 +281,7 @@ void Updater::update_services(bool changed_to_online) const { // Update Log->print_update_service_ttl_expired(hostname, ip_dns_recheck, ip_last_update, ip_host, lastupdated, dns_cache_ttl, current_time); - service->update(ip_host,current_time); + service->update(ip_host, current_time, changed_to_online); } else {