if ( service )
{
ServiceHolder->add_service(service);
- Log->print_service_object("New Service object from command line options:", service->get_protocol(), service->get_hostname(), service->get_login() ,service->get_password(), service->get_update_interval(), service->get_max_updates_within_interval(), service->get_max_equal_updates_in_succession(), service->get_dns_cache_ttl() , service->get_actual_ip(), service->get_last_updates());
+ Log->print_service_object("New Service object from command line options:", service->get_protocol(), service->get_hostname(), service->get_login() ,service->get_password(), service->get_update_interval(), service->get_max_updates_within_interval(), service->get_max_equal_updates_in_succession(), service->get_dns_cache_ttl() , service->get_actual_ip(), service->get_last_updates(), service->get_activated());
}
else
{
if ( service )
{
ServiceHolder->add_service(service);
- Log->print_service_object("New Service object from config:", service->get_protocol(), service->get_hostname(), service->get_login() ,service->get_password(), service->get_update_interval(), service->get_max_updates_within_interval(), service->get_max_equal_updates_in_succession(), service->get_dns_cache_ttl() , service->get_actual_ip(), service->get_last_updates());
+ Log->print_service_object("New Service object from config:", service->get_protocol(), service->get_hostname(), service->get_login() ,service->get_password(), service->get_update_interval(), service->get_max_updates_within_interval(), service->get_max_equal_updates_in_succession(), service->get_dns_cache_ttl() , service->get_actual_ip(), service->get_last_updates(), service->get_activated());
}
else
{
* @param password Service's password.
* @param actual_ip Service's actual_ip.
* @param lastupdated Service's lastupdated.
+ * @param activated Service's activated.
*/
-void Logger::print_service_object(const string& message, const string& protocol, const string& hostname, const string& login, const string& password, const int update_interval, const int max_updates_within_interval, const int max_equal_updates_in_succession, const int dns_cache_ttl , const string& actual_ip, std::map<time_t,std::string> lastupdated) const
+void Logger::print_service_object(const string& message, const string& protocol, const string& hostname, const string& login, const string& password, const int update_interval, const int max_updates_within_interval, const int max_equal_updates_in_succession, const int dns_cache_ttl , const string& actual_ip, std::map<time_t,std::string> lastupdated, const bool activated) const
{
int level = 1;
if ( level <= Loglevel )
{
msg << "\t" << "Lastupdated: " << r_iter->first << " -> " << r_iter->second << endl;
}
+ msg << "\t" << "Activated: " << activated << endl;
log_notice(msg.str());
}
}
void print_deserialized_objects_success() const;
- void print_service_object(const std::string& message, const std::string& protocol, const std::string& hostname, const std::string& login, const std::string& password, const int update_interval, const int max_updates_within_interval, const int max_equal_updates_in_succession, const int dns_cache_ttl , const std::string& actual_ip, std::map<time_t,std::string> lastupdates) const;
+ void print_service_object(const std::string& message, const std::string& protocol, const std::string& hostname, const std::string& login, const std::string& password, const int update_interval, const int max_updates_within_interval, const int max_equal_updates_in_succession, const int dns_cache_ttl , const std::string& actual_ip, std::map<time_t,std::string> lastupdates, const bool activated) const;
void print_exception_serialize(const std::string& errMsg) const;
, Password("NOT SERIALIZED")
, ActualIP("0.0.0.0")
, ActualIPIsBurnt(false)
+ , Activated(false)
, UpdateInterval(15)
, MaxUpdatesWithinInterval(3)
, MaxEqualUpdatesInSuccession(2)
UpdateErrorCode update_res = perform_update(ip);
+ // If update result is other than Generic or NotAuth, we assume that the hostname is activated.
+ if ( (update_res != GenericError) && (update_res != NotAuth) )
+ set_activated();
+
if (update_res == UpdateOk)
{
// if update was successful, we need to set the Lastupdated and ActualIP base member.
{
DNSCacheTTL = _dns_cache_ttl;
}
+
+
+/**
+ * Get member Activated
+ * @return Activated
+ */
+bool Service::get_activated() const
+{
+ return Activated;
+}
+
+
+/**
+ * Set member Activated
+ * @param _activated Activated
+ */
+void Service::set_activated()
+{
+ Activated = true;
+}
std::string ActualIP;
bool ActualIPIsBurnt;
+ bool Activated;
int UpdateInterval;
int MaxUpdatesWithinInterval;
ar & MaxUpdatesWithinInterval;
ar & MaxEqualUpdatesInSuccession;
ar & DNSCacheTTL;
+ ar & Activated;
}
Logger::Ptr Log;
protected:
- enum UpdateErrorCode { UpdateOk=0, GenericError=1, NoChange=2, Blocked=3 };
+ enum UpdateErrorCode { UpdateOk=0, UpdateError=1, NoChange=2, Blocked=3, NotAuth=4, GenericError=4 };
virtual UpdateErrorCode perform_update(const std::string& ip) = 0;
+ // UpdateOk: Update was successful
+ // UpdateError: Unspecified error code returned from update server
+ // NoChange: IP was not changed_to_online
+ // Blocked: Client blocked due to abusive updates
+ // NotAuth: Authentication was not successful
+ // GenericError: Generic error. For example update server not reached, wrong hostname, not authenticated or network error.
+ // Generic error indicates that the update server couldn't associate the update request to any hostname.
+
public:
typedef boost::shared_ptr<Service> Ptr;
std::string get_service_name() const;
+ void set_activated();
+ bool get_activated() const;
+
bool operator== (const Service& other) const;
bool operator!= (const Service& other) const;
};
else
{
get_logger()->print_update_failure(url,curl_data);
+ return UpdateError;
}
}
else if ( http_status_code == 401 )
{
get_logger()->print_service_not_authorized(url,get_login(),get_password());
+ return NotAuth;
}
else
{
else if ( curl_data == "badauth" )
{
get_logger()->print_service_not_authorized(url,get_login(),get_password());
+ return NotAuth;
}
else
{
get_logger()->print_update_failure(url, curl_data);
+ return UpdateError;
}
}
else
else if ( status_code == "401" )
{
get_logger()->print_service_not_authorized(url,get_login(),get_password());
+ return NotAuth;
}
else
{
get_logger()->print_update_failure(url,curl_data);
+ return UpdateError;
}
}
else
else if ( status_code == "NOACCESS" )
{
get_logger()->print_service_not_authorized(url,get_login(),get_password());
+ return NotAuth;
}
else
{
get_logger()->print_update_failure(url, curl_data);
+ return UpdateError;
}
}
else
else if ( update_return_code == "1" )
{
get_logger()->print_service_not_authorized(url,get_login(),get_password());
+ return NotAuth;
}
else
{
get_logger()->print_update_failure(url,update_return_code);
+ return UpdateError;
}
}
else
// Login failed
get_logger()->print_service_not_authorized(UpdateServer,get_login(),get_password());
connection->close_connection(); /*lint !e534 */
- return GenericError;
+ return NotAuth;
}
else if ( status_code != "225" )
{
{
get_logger()->print_undefined_protocol_error("ODS",update_reply);
connection->close_connection(); /*lint !e534 */
- return GenericError;
+ return UpdateError;
}
}
else if ( status_code == "401" )
{
get_logger()->print_service_not_authorized(url,get_login(),get_password());
+ return NotAuth;
}
else
{
get_logger()->print_update_failure(url,curl_data);
+ return UpdateError;
}
}
else
else
{
get_logger()->print_update_failure(url,curl_data);
+ return UpdateError;
}
}
else if ( http_status_code == 401 )
{
get_logger()->print_service_not_authorized(url,get_login(),get_password());
+ return NotAuth;
}
else
{
BOOST_FOREACH(Service::Ptr &old_service, _old_services)
{
OldServices.push_back(old_service);
- Log->print_service_object("Deserialized following Service object:", old_service->get_protocol(), old_service->get_hostname(), old_service->get_login() ,old_service->get_password(), old_service->get_update_interval(), old_service->get_max_updates_within_interval(), old_service->get_max_equal_updates_in_succession(), old_service->get_dns_cache_ttl() , old_service->get_actual_ip(), old_service->get_last_updates());
+ Log->print_service_object("Deserialized following Service object:", old_service->get_protocol(), old_service->get_hostname(), old_service->get_login() ,old_service->get_password(), old_service->get_update_interval(), old_service->get_max_updates_within_interval(), old_service->get_max_equal_updates_in_succession(), old_service->get_dns_cache_ttl() , old_service->get_actual_ip(), old_service->get_last_updates(), old_service->get_activated());
BOOST_FOREACH(Service::Ptr &service, Services)
{
if ( *service == *old_service )
{
service->set_last_updates(old_service->get_last_updates());
service->set_actual_ip(old_service->get_actual_ip());
- Log->print_service_object("New Service object with adopted values:", service->get_protocol(), service->get_hostname(), service->get_login() ,service->get_password(), service->get_update_interval(), service->get_max_updates_within_interval(), service->get_max_equal_updates_in_succession(), service->get_dns_cache_ttl() , service->get_actual_ip(), service->get_last_updates());
+ if ( old_service->get_activated() )
+ service->set_activated();
+
+ Log->print_service_object("New Service object with adopted values:", service->get_protocol(), service->get_hostname(), service->get_login() ,service->get_password(), service->get_update_interval(), service->get_max_updates_within_interval(), service->get_max_equal_updates_in_succession(), service->get_dns_cache_ttl() , service->get_actual_ip(), service->get_last_updates(), service->get_activated());
// We have adopted the values of the old_service. Just set lastupdated and timeout to 0, so this old_service wont be serialized.
old_service->set_update_interval(0);
}
Log->print_cached_dns_entry(hostname, ip_dns_recheck, ip_last_update, ip_host);
// Test if the DNS-Record could not be found.
- if ( ip_dns_recheck.empty() )
+ // If DNS-Record was not found but service was not activated, the hostname could be deactivated, offline or not existent. In this case try a ordinary update.
+ if ( ip_dns_recheck.empty() && service->get_activated() )
{
Log->print_dns_lookup_failed(changed_to_online, hostname);
continue;
if ( ip_last_update != ip_host )
{
// Update
- Log->print_update_service(hostname, ip_dns_recheck, ip_last_update, ip_host, lastupdated);
+ if ( !ip_dns_recheck.empty() )
+ {
+ Log->print_update_service(hostname, ip_dns_recheck, ip_last_update, ip_host, lastupdated);
+ }
+ else
+ {
+ // Service gets updated the first time and no DNS-Record was found. This is either a initial update or the hostname is really not available.
+ Log->print_update_service(hostname, "<NO IP SET>", ip_last_update, ip_host, lastupdated);
+ }
+
service->update(ip_host, current_time, changed_to_online);
}
else