2 * @brief The updater class implementation. This class implements the updater logic.
6 * @copyright Intra2net AG
12 #include <boost/foreach.hpp>
17 * Default constructor which initializes the member Conf.
20 : IPHelp(new IPHelper)
22 // Initialize program wide Logger, at this point we don't know where to log and with which loglevel.
23 Logger::Ptr _log(new Logger);
28 Config::Ptr _config(new Config(Log));
43 * Parse the command line arguments and initialize corresponding options.
44 * @param argc Number command line arguments.
45 * @param argv[] Array with arguments.
46 * @return 0 if cmd options successfully parsed, 1 if usage or version.
48 int Updater::init_config_from_cmd(int argc, char *argv[])
50 // Load the command line parameters
51 if( Conf->parse_cmd_line( argc, argv ) != 0)
54 // If we have loaded the cmd options we need to init the log facility immediately in case debugging is enabled from cmd.
58 Log->print_cmd_parsed();
64 * Load the main config and the service definition files in config path.
65 * @return 0 if all is fine,
67 int Updater::init_config_from_files()
69 // Load the main and service config files in config path
70 if ( Conf->load_config_from_files() != 0 )
73 // Re-init log facility, perhaps new config file options for logger are set.
74 // These config file options will only overwrite the cmd options if the SIGHUP (reload config) is caught.
77 // Here we are. All Service Objects should be initialized, so it is time to deserialize the old service objects and compare them.
78 if ( Conf->deserialize_services() != 0 )
82 Log->print_conf_files_parsed();
88 * Getter for member Config.
89 * @return Member Config.
91 Config::Ptr Updater::get_config() const
98 * Getter for member Logger.
99 * @return Member Logger.
101 Logger::Ptr Updater::get_logger() const
108 * Init the IPHelp member with needed values.
109 * @return 0 if all is fine, -1 otherwise.
111 int Updater::init_ip_helper()
113 // initialize IPHelper
114 IPHelper::Ptr _iphelp(new IPHelper(Log,Conf->get_webcheck_ip_url(),Conf->get_webcheck_ip_url_alt(),Conf->get_enable_ipv6()));
123 * Reloading the config. Delete all Service objects and then init new Service objects from config files.
125 int Updater::reload_config()
127 // serialize all service objects
128 if ( Conf->serialize_services() != 0 )
131 // delete all service objects
132 Conf->delete_services();
134 // delete the actual Variables_map, perhaps with old cmd options which would overwrite new config file options.
135 Conf->delete_variables_map();
137 // load only config files
138 if ( init_config_from_files() != 0 )
146 * Initialize the logging facility with loglevel and syslog.
148 void Updater::init_log_facility()
150 Log->set_log_facility(Conf->get_loglevel(),Conf->get_syslog());
151 Log->print_init_log_facility();
156 * Update all configured services.
158 void Updater::update_services()
160 list<Service::Ptr> services = this->Conf->get_services();
162 string ip = IPHelp->get_actual_ip();
166 BOOST_FOREACH(Service::Ptr &service, services )