Log if we don't update a service when switching from offline to online, otherwise...
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 6 Oct 2010 15:06:42 +0000 (17:06 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 6 Oct 2010 15:06:42 +0000 (17:06 +0200)
src/logger.cpp
src/logger.hpp
src/main.cpp
src/updater.cpp
src/updater.hpp

index fda6f85..bce5a27 100644 (file)
@@ -1720,6 +1720,7 @@ void Logger::print_update_service_ttl_expired(const string& hostname, const stri
 
 /**
  * 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
@@ -1728,9 +1729,13 @@ void Logger::print_update_service_ttl_expired(const string& hostname, const stri
  * @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;
@@ -1742,15 +1747,20 @@ void Logger::print_update_service_ttl_not_expired(const string& hostname, const
 
 /**
  * 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;
index 93be3e2..8e6d25a 100644 (file)
@@ -252,9 +252,9 @@ public:
 
     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;
 
index 715d06d..b00ee10 100644 (file)
@@ -304,6 +304,7 @@ int main(int argc, char *argv[])
         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();
 
@@ -364,7 +365,7 @@ int main(int argc, char *argv[])
                 updater->get_config()->set_webcheck_enabled(webcheck_enabled);
 
             // update all configured services
-            updater->update_services();
+            updater->update_services(is_online != old_online_state);
         }
         else
         {
@@ -372,6 +373,10 @@ int main(int argc, char *argv[])
             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 */
index eddcc48..028a152 100644 (file)
@@ -215,8 +215,9 @@ void Updater::init_log_facility() const
 
 /**
  * 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();
@@ -254,7 +255,7 @@ void Updater::update_services() const
         // 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;
         }
@@ -279,7 +280,7 @@ void Updater::update_services() const
             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);
             }
         }
     }
index 7d1da06..d752989 100644 (file)
@@ -38,7 +38,7 @@ public:
 
     ~Updater();
 
-    void update_services() const;
+    void update_services(bool changed_to_online) const;
 
     int init_config_from_cmd(int argc, char *argv[]) const;