("enable_ipv6",po::value<bool>()->default_value(false),"Try to use IPv6.")
("webcheck_url",po::value<string>()->default_value(""),"Use this URL to determine IP.")
("webcheck_url_alt",po::value<string>()->default_value(""),"Use this alternative URL to determine IP.")
- ("http_proxy",po::value<string>()->default_value(""),"Use this proxy for all http requests.")
- ("http_proxy_port",po::value<int>()->default_value(0),"Port of the proxy.")
+ ("http_proxy",po::value<string>(),"Use this proxy for all http requests.")
+ ("http_proxy_port",po::value<int>(),"Port of the proxy.")
;
// Define valid command line parameters
if ( VariablesMap.count("webcheck_url_alt") )
WebcheckIpUrlAlt = VariablesMap["webcheck_url_alt"].as<string>();
- if ( VariablesMap.count("http_proxy") )
+ if ( VariablesMap.count("http_proxy") && VariablesMap.count("http_proxy_port") )
+ {
Proxy = VariablesMap["http_proxy"].as<string>();
-
- if ( VariablesMap.count("http_proxy_port") )
ProxyPort = VariablesMap["http_proxy_port"].as<int>();
+ }
+ else if ( VariablesMap.count("http_proxy") || VariablesMap.count("http_proxy_port") )
+ {
+ Log->print_missing_cmd_proxy_option();
+ Log->print_usage(OptDescCmd);
+ return -1;
+ }
+
}
catch(po::unknown_option e)
protocol = ba::to_lower_copy(protocol);
int update_interval = 0;
- if ( VariablesMap.count("update_interval") )
+ if ( vm.count("update_interval") )
update_interval = VariablesMap["update_interval"].as<int>();
int max_updates_within_interval = 0;
- if ( VariablesMap.count("max_updates_within_interval") )
+ if ( vm.count("max_updates_within_interval") )
max_updates_within_interval = VariablesMap["max_updates_within_interval"].as<int>();
int dns_cache_ttl = 0;
- if ( VariablesMap.count("dns_cache_ttl") )
+ if ( vm.count("dns_cache_ttl") )
dns_cache_ttl = VariablesMap["dns_cache_ttl"].as<int>();
Service::Ptr service = create_service(protocol,host,login,password,update_interval,max_updates_within_interval,dns_cache_ttl);
else
return -1;
}
+ else if ( vm.count("protocol") || vm.count("host") || vm.count("login") || vm.count("password") )
+ {
+ service_config_file.close();
+ Log->print_missing_service_conf_option(full_filename);
+ return -1;
+ }
}
catch ( po::unknown_option e )
{
// unknown option in config file detected
service_config_file.close();
- Log->print_unknown_service_conf_option(e.what());
+ Log->print_unknown_service_conf_option(full_filename,e.what());
+ return -1;
+ }
+ catch(po::multiple_occurrences e)
+ {
+ service_config_file.close();
+ Log->print_multiple_service_conf_option(full_filename,e.what());
return -1;
}
service_config_file.close();
po::store(parsed_main_options,VariablesMap);
po::notify(VariablesMap);
- if ( VariablesMap.count("daemon_mode") )
- DaemonMode = VariablesMap["daemon_mode"].as<bool>();
+ if ( VariablesMap.count("daemon_mode") )
+ DaemonMode = VariablesMap["daemon_mode"].as<bool>();
- if ( VariablesMap.count("loglevel") )
- Loglevel = VariablesMap["loglevel"].as<int>();
+ if ( VariablesMap.count("loglevel") )
+ Loglevel = VariablesMap["loglevel"].as<int>();
- if ( VariablesMap.count("syslog") )
- Syslog = VariablesMap["syslog"].as<bool>();
+ if ( VariablesMap.count("syslog") )
+ Syslog = VariablesMap["syslog"].as<bool>();
- if ( VariablesMap.count("enable_ipv6") )
- EnableIPv6 = VariablesMap["enable_ipv6"].as<bool>();
-
- if ( VariablesMap.count("webcheck_url") )
- WebcheckIpUrl = VariablesMap["webcheck_url"].as<string>();
+ if ( VariablesMap.count("enable_ipv6") )
+ EnableIPv6 = VariablesMap["enable_ipv6"].as<bool>();
- if ( VariablesMap.count("webcheck_url_alt") )
- WebcheckIpUrlAlt = VariablesMap["webcheck_url_alt"].as<string>();
+ if ( VariablesMap.count("webcheck_url") )
+ WebcheckIpUrl = VariablesMap["webcheck_url"].as<string>();
- if ( VariablesMap.count("http_proxy") )
- Proxy = VariablesMap["http_proxy"].as<string>();
+ if ( VariablesMap.count("webcheck_url_alt") )
+ WebcheckIpUrlAlt = VariablesMap["webcheck_url_alt"].as<string>();
- if ( VariablesMap.count("http_proxy_port") )
- ProxyPort = VariablesMap["http_proxy_port"].as<int>();
+ if ( VariablesMap.count("http_proxy") && VariablesMap.count("http_proxy_port") )
+ {
+ Proxy = VariablesMap["http_proxy"].as<string>();
+ ProxyPort = VariablesMap["http_proxy_port"].as<int>();
+ }
+ else if ( VariablesMap.count("http_proxy") || VariablesMap.count("http_proxy_port") )
+ {
+ main_config_file.close();
+ Log->print_missing_conf_proxy_option(full_filename);
+ return -1;
+ }
}
catch ( po::unknown_option e ) // at the moment 04-08-2009 this exception is never thrown :-(
Log->print_unknown_main_conf_option(e.what());
return -1;
}
+ catch(po::multiple_occurrences e)
+ {
+ main_config_file.close();
+ Log->print_multiple_main_conf_option(full_filename,e.what());
+ return -1;
+ }
main_config_file.close();
}
else
* There is an unknown option in a service config file.
* @param unknown_option The unknown option.
*/
-void Logger::print_unknown_service_conf_option(const string& unknown_option) const
+void Logger::print_unknown_service_conf_option(const string& service_conf_file, const string& unknown_option) const
{
if ( 0 <= Loglevel )
{
ostringstream msg;
- msg << "Unknown option in service config file detected: " << unknown_option << endl;
+ msg << "Unknown option in service config file detected: " << service_conf_file << " Unknown option: " << unknown_option << endl;
log_error(msg.str());
}
}
/**
+ * Missing option in service config file.
+ * @param service_conf_file Service config file
+ */
+void Logger::print_missing_service_conf_option(const string& service_conf_file) const
+{
+ if ( 0 <= Loglevel )
+ {
+ ostringstream msg;
+ msg << "Missing option in service config file " << service_conf_file << " to initialize service. Protocol, host, login and password must be specified." << endl;
+ log_error(msg.str());
+ }
+}
+
+
+/**
* Process running as daemon.
* @param pid The pid of the daemon.
*/
* @param dns_cache_ttl DNS cache TTL
* @param current_time Current time
*/
-void Logger::print_recheck_dns_entry(const std::string& hostname, const int lastupdated, const int dns_cache_ttl, const int current_time) const
+void Logger::print_recheck_dns_entry(const string& hostname, const int lastupdated, const int dns_cache_ttl, const int current_time) const
{
if ( 1 <= Loglevel )
{
* @param hostname Hostname
* @param cached_dns_entry IP
*/
-void Logger::print_cached_dns_entry(const std::string& hostname, const std::string& cached_dns_entry, const std::string& lastupdated_ip) const
+void Logger::print_cached_dns_entry(const string& hostname, const string& cached_dns_entry, const string& lastupdated_ip) const
{
if ( 1 <= Loglevel )
{
log_notice(msg.str());
}
}
+
+
+/**
+ * Missing proxy option on command line.
+ */
+void Logger::print_missing_cmd_proxy_option() const
+{
+ if ( 0 <= Loglevel )
+ {
+ ostringstream msg;
+ msg << "Missing option to initialize proxy. http_proxy and http_proxy_port must be specified." << endl;
+ log_error(msg.str());
+ }
+}
+
+
+/**
+ * Multiple option in service config file.
+ * @param service_conf_file Service config file
+ * @param message Multiple option text
+ */
+void Logger::print_multiple_service_conf_option(const string& service_conf_file, const string& message) const
+{
+ if ( 0 <= Loglevel )
+ {
+ ostringstream msg;
+ msg << "Multiple occurrences of the same option in service config file detected: " << service_conf_file << " " << message << endl;
+ log_error(msg.str());
+ }
+}
+
+
+/**
+ * Multiple option in main config file.
+ * @param service_conf_file Service config file
+ * @param message Multiple option text
+ */
+void Logger::print_multiple_main_conf_option(const string& main_conf_file, const string& message) const
+{
+ if ( 0 <= Loglevel )
+ {
+ ostringstream msg;
+ msg << "Multiple occurrences of the same option in main config file detected: " << main_conf_file << " " << message << endl;
+ log_error(msg.str());
+ }
+}
+
+
+/**
+ * Missing proxy option in main config file.
+ */
+void Logger::print_missing_conf_proxy_option(const string& main_conf_filename) const
+{
+ if ( 0 <= Loglevel )
+ {
+ ostringstream msg;
+ msg << "Missing option to initialize proxy in main config file: " << main_conf_filename << " http_proxy and http_proxy_port must be specified." << endl;
+ log_error(msg.str());
+ }
+}
void print_load_main_conf(const std::string& filename) const;
- void print_unknown_service_conf_option(const std::string& unknown_option) const;
+ void print_unknown_service_conf_option(const std::string& service_conf_file, const std::string& unknown_option) const;
void print_unknown_main_conf_option(const std::string& unknown_option) const;
void print_missing_cmd_service_option() const;
+ void print_missing_service_conf_option(const std::string& service_conf_file) const;
+
void print_runnig_as_daemon(const int pid) const;
void print_daemon_mode(const bool daemon_mode) const;
void print_multiple_cmd_option(const std::string& message) const;
+ void print_multiple_service_conf_option(const std::string& service_conf_file, const std::string& message) const;
+
+ void print_multiple_main_conf_option(const std::string& main_conf_file, const std::string& message) const;
+
void print_update_not_allowed(const int current_time, const int old_time, const int MaxUpdatesWithinInterval, const std::string& service) const;
void print_update_service_failure(const std::string& service) const;
void print_recheck_dns_entry(const std::string& hostname, const int lastupdated, const int dns_cache_ttl, const int current_time) const;
void print_cached_dns_entry(const std::string& hostname, const std::string& cached_dns_entry, const std::string& lastupdated_ip) const;
+
+ void print_missing_cmd_proxy_option() const;
+
+ void print_missing_conf_proxy_option(const std::string& main_conf_filename) const;
};
#endif