/**
* 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();
/**
* 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 = "";
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 );
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;
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;
/**
* 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
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());
}
}
list<Service::Ptr> 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);