From: Thomas Jarosch Date: Thu, 14 Oct 2010 08:53:49 +0000 (+0200) Subject: Skip webcheck idle period check if we just went online. Improve webcheck logging X-Git-Tag: v1.1~50 X-Git-Url: http://developer.intra2net.com/git/?p=bpdyndnsd;a=commitdiff_plain;h=3c4705d9f8c93514349fb0a98d9a7f130f1d9ae5 Skip webcheck idle period check if we just went online. Improve webcheck logging --- diff --git a/src/ip_addr_helper.cpp b/src/ip_addr_helper.cpp index 56100bb..8628cb9 100644 --- a/src/ip_addr_helper.cpp +++ b/src/ip_addr_helper.cpp @@ -179,14 +179,15 @@ bool IPAddrHelper::is_local_ipv4(const string ip) const /** * Get the actual IP of this host through a conventional DNS query or through a IP webcheck URL if configured so. + * @param changed_to_online Indicates if we just went online * @return A string representation of the actual IP in dotted format or an empty string if something went wrong. */ -string IPAddrHelper::get_actual_ip( bool use_webcheck ) +string IPAddrHelper::get_actual_ip( bool use_webcheck, bool changed_to_online ) { string ip; if ( !WebcheckIpUrl.empty() && use_webcheck ) - ip = webcheck_ip(); + ip = webcheck_ip(changed_to_online); else ip = get_local_wan_nic_ip(); @@ -370,9 +371,10 @@ string IPAddrHelper::dns_query(const string& _hostname) const /** * Get the actual IP of this host through a IP webcheck URL. + * @param changed_to_online Indicates if we just went online * @return A string representation of the actual IP in dotted format or an empty string if something went wrong. */ -string IPAddrHelper::webcheck_ip() +string IPAddrHelper::webcheck_ip(bool changed_to_online) { // Init IPAddress with a empty string. string ip_addr = ""; @@ -381,7 +383,8 @@ string IPAddrHelper::webcheck_ip() time_t current_time = time(NULL); // Test if webcheck is allowed due to webcheck_interval. - if ( (LastWebcheck + ((time_t)WebcheckInterval*60)) >= current_time ) + // Ignored if we just went online. + if ( !changed_to_online && (LastWebcheck + ((time_t)WebcheckInterval*60)) >= current_time ) { // Webcheck not allowed, log it and return empty string. Log->print_webcheck_exceed_interval( LastWebcheck, (WebcheckInterval*60), current_time ); diff --git a/src/ip_addr_helper.hpp b/src/ip_addr_helper.hpp index d1439a6..8615148 100644 --- a/src/ip_addr_helper.hpp +++ b/src/ip_addr_helper.hpp @@ -43,7 +43,7 @@ private: bool is_local_ipv4(const std::string ip) const; bool is_local_ipv6(const std::string ip) const; - std::string webcheck_ip(); + std::string webcheck_ip(bool changed_to_online); CURL * init_curl(std::string& curl_writedata_buff, char* curl_err_buff) const; int perform_curl_operation(CURL * curl_easy_handle, const char* curl_err_buff, const std::string& actual_url) const; std::string parse_ipv4(const std::string& data) const; @@ -61,7 +61,7 @@ public: std::string dns_query(const std::string& _hostname) const; - std::string get_actual_ip( bool use_webcheck ); + std::string get_actual_ip( bool use_webcheck, bool changed_to_online ); std::string get_local_wan_nic_ip() const; diff --git a/src/logger.cpp b/src/logger.cpp index b548b96..3b00e56 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -1664,7 +1664,7 @@ void Logger::print_error_parsing_cmd(const string& error) const /** * The webcheck interval was exceeded, so webcheck not allowed. * @param last_webcheck Time of last webcheck. - * @param webcheck_interval Webcheck interval time. + * @param webcheck_interval Webcheck interval time in seconds. * @param current_time Current system time. */ void Logger::print_webcheck_exceed_interval( const time_t last_webcheck, const int webcheck_interval, const time_t current_time ) const @@ -1673,7 +1673,8 @@ void Logger::print_webcheck_exceed_interval( const time_t last_webcheck, const i if ( level <= Loglevel ) { ostringstream msg; - msg << "Exceeding webcheck interval: LastWebcheck " << last_webcheck << " + WebcheckInterval(sec) " << webcheck_interval << " >= CurrentTime " << current_time << endl; + msg << "Skipped webcheck in idle period (" << (last_webcheck+webcheck_interval)-current_time << " more seconds"; + msg << ", last_webcheck: " << last_webcheck << ", webcheck_interval(sec): " << webcheck_interval << ")" << endl; log_notice(msg.str()); } } diff --git a/src/updater.cpp b/src/updater.cpp index 852b46b..875e03d 100644 --- a/src/updater.cpp +++ b/src/updater.cpp @@ -223,7 +223,7 @@ void Updater::update_services(bool changed_to_online) const list services = ServiceHolder->get_services(); // Get the actual IP of this host. - string ip_host = IPAddrHelp->get_actual_ip(Conf->get_webcheck_enabled()); + string ip_host = IPAddrHelp->get_actual_ip(Conf->get_webcheck_enabled(), changed_to_online); if ( ip_host.empty() ) { Log->print_no_wan_ip(changed_to_online);