/**
* TTL expired
+ * @param override_log_level Override log level with zero if true
* @param hostname Hostname
* @param ip_dns_recheck Cached DNS entry
* @param ip_last_update IP set in last update
* @param dns_cache_ttl DNS cache ttl
* @param current_time Current time
*/
-void Logger::print_update_service_ttl_not_expired(const string& hostname, const string& ip_dns_recheck, const string& ip_last_update, const string& ip_host, const time_t lastupdated, const int dns_cache_ttl, const time_t current_time) const
+void Logger::print_update_service_ttl_not_expired(bool override_log_level, const string& hostname, const string& ip_dns_recheck, const string& ip_last_update, const string& ip_host, const time_t lastupdated, const int dns_cache_ttl, const time_t current_time) const
{
int level = 1;
+
+ if (override_log_level)
+ level = 0;
+
if ( level <= Loglevel )
{
ostringstream msg;
/**
* No update needed
+ * @param override_log_level Override log level with zero if true
* @param hostname Hostname
* @param ip_dns_recheck Cached DNS entry
* @param ip_last_update IP set in last update
* @param ip_host Hosts IP
* @param lastupdated Last updated
*/
-void Logger::print_no_update_needed(const string& hostname, const string& ip_dns_recheck, const string& ip_last_update, const string& ip_host, const time_t lastupdated) const
+void Logger::print_no_update_needed(bool override_log_level, const string& hostname, const string& ip_dns_recheck, const string& ip_last_update, const string& ip_host, const time_t lastupdated) const
{
int level = 1;
+
+ if (override_log_level)
+ level = 0;
+
if ( level <= Loglevel )
{
ostringstream msg;
void print_update_service_ttl_expired(const std::string& hostname, const std::string& ip_dns_recheck, const std::string& ip_last_update, const std::string& ip_host, const time_t lastupdated, const int dns_cache_ttl, const time_t current_time) const;
- void print_update_service_ttl_not_expired(const std::string& hostname, const std::string& ip_dns_recheck, const std::string& ip_last_update, const std::string& ip_host, const time_t lastupdated, const int dns_cache_ttl, const time_t current_time) const;
+ void print_update_service_ttl_not_expired(bool override_log_level, const std::string& hostname, const std::string& ip_dns_recheck, const std::string& ip_last_update, const std::string& ip_host, const time_t lastupdated, const int dns_cache_ttl, const time_t current_time) const;
- void print_no_update_needed(const std::string& hostname, const std::string& ip_dns_recheck, const std::string& ip_last_update, const std::string& ip_host, const time_t lastupdated) const;
+ void print_no_update_needed(bool override_log_level, const std::string& hostname, const std::string& ip_dns_recheck, const std::string& ip_last_update, const std::string& ip_host, const time_t lastupdated) const;
void print_error_getting_local_wan_ip(const std::string& system_call, const std::string& error) const;
return -1;
// Should we start in offline mode?
+ bool old_online_state = false;
bool is_online = !updater->get_config()->get_start_offline();
bool webcheck_enabled = updater->get_config()->get_webcheck_enabled();
updater->get_config()->set_webcheck_enabled(webcheck_enabled);
// update all configured services
- updater->update_services();
+ updater->update_services(is_online != old_online_state);
}
else
{
updater->get_logger()->print_offline_mode();
}
+ // Keep old online state so we can determine
+ // if we switched from offline to online
+ old_online_state = is_online;
+
// Snore, snore... don't hog the cpu if we are in daemon_mode.
if ( !exit_now )
sleep(10); /*lint !e534 */
/**
* Update all configured services.
+ * @param changed_to_online True if we just changed to online, false if we were already online
*/
-void Updater::update_services() const
+void Updater::update_services(bool changed_to_online) const
{
// Get all services from the ServiceHolder.
list<Service::Ptr> services = ServiceHolder->get_services();
// Test if the actual DNS-Record differs from the host's IP.
if (ip_host == ip_dns_recheck )
{
- Log->print_no_update_needed(hostname, ip_dns_recheck, ip_last_update, ip_host, lastupdated);
+ Log->print_no_update_needed(changed_to_online, hostname, ip_dns_recheck, ip_last_update, ip_host, lastupdated);
// No update needed
continue;
}
else
{
// DNS cache TTL isn't expired
- Log->print_update_service_ttl_not_expired(hostname, ip_dns_recheck, ip_last_update, ip_host, lastupdated, dns_cache_ttl, current_time);
+ Log->print_update_service_ttl_not_expired(changed_to_online, hostname, ip_dns_recheck, ip_last_update, ip_host, lastupdated, dns_cache_ttl, current_time);
}
}
}
~Updater();
- void update_services() const;
+ void update_services(bool changed_to_online) const;
int init_config_from_cmd(int argc, char *argv[]) const;