def test_engine_invalid(self): a_config = popup_handler.PopupHandlerConfigModel() a_config.popup_engine = "NOT-EXISTING" with self.assertRaises(configuration.ConfigurationException): a_handler = popup_handler.PopupHandler(p_config=a_config) self.assertIsNotNone(a_handler) a_handler.notify(p_text=TEXT)
def test_engine_zenity_init(self): a_config = popup_handler.PopupHandlerConfigModel() a_config.popup_engine = popup_handler.POPUP_ENGINE_ZENITY a_handler = popup_handler.PopupHandler(p_config=a_config) self.assertIsNotNone(a_handler) a_handler.notify(p_text=TEXT)
def test_engine_xmessage_init(self): a_config = popup_handler.PopupHandlerConfigModel() a_config.popup_engine = popup_handler.POPUP_ENGINE_XMESSAGE a_handler = popup_handler.PopupHandler(p_config=a_config) self.assertIsNotNone(a_handler) a_handler.notify(p_text=TEXT)
def test_engine_yad_init(self): a_config = popup_handler.PopupHandlerConfigModel() a_config.popup_engine = popup_handler.POPUP_ENGINE_YAD a_handler = popup_handler.PopupHandler(p_config=a_config) self.assertIsNotNone(a_handler) a_handler.notify(p_text="yad: " + TEXT)
def test_engine_bash_shell_init(self): a_config = popup_handler.PopupHandlerConfigModel() a_config.popup_engine = popup_handler.POPUP_ENGINE_SHELL_ECHO a_handler = popup_handler.PopupHandler(p_config=a_config) self.assertIsNotNone(a_handler) a_handler.notify(p_text="bash:" + TEXT)
def prepare_services(self, p_full_startup=True): super().prepare_services(p_full_startup=p_full_startup) # TODO: Activate in memory sqlite backend for slaves self._persistence = persistence.Persistence( p_config=self._config[persistence.SECTION_NAME]) if not p_full_startup: return if self.is_master(): self._rule_handler = rule_handler.RuleHandler( p_config=self._config[rule_handler.SECTION_NAME], p_persistence=self._persistence) self._master_connector = master_connector.MasterConnector( p_config=self._config[master_connector.SECTION_NAME]) config = self._config[audio_handler.SECTION_NAME] if config.is_active(): self._notification_handlers.append( audio_handler.AudioHandler(p_config=config)) config = self._config[popup_handler.SECTION_NAME] if config.is_active(): self._notification_handlers.append( popup_handler.PopupHandler(p_config=config)) self.check_migrations() process_handler = client_process_handler.ClientProcessHandler( p_config=self._config[client_process_handler.SECTION_NAME], p_process_iterator_factory=ProcessIteratorFactory()) self._client_device_handler = client_device_handler.ClientDeviceHandler( p_config=self._config[client_device_handler.SECTION_NAME], p_persistence=self._persistence) self._process_handlers = { process_handler.id: process_handler, self._client_device_handler.id: self._client_device_handler } config = self._config[prometheus.SECTION_NAME] if config.is_active(): self._prometheus_client = prometheus.PrometheusClient( p_logger=self._logger, p_config=config) unix_user_handler_config = self._config[unix_user_handler.SECTION_NAME] status_server_config = self._config[status_server.SECTION_NAME] self.init_babel(p_localeselector=self.get_request_locale) localedir = os.path.join(os.path.dirname(__file__), "translations") a_locale_helper = locale_helper.LocaleHelper( p_locale_selector=self.get_request_locale, p_locale_dir=localedir) self.add_locale_helper(a_locale_helper) if self.is_master(): if status_server_config.is_active(): if status_server_config.admin_password is not None: msg = "admin_user and admin_password in section [StatusSever] " \ "should be moved to section [UnixUserHandler]" self._logger.warning(msg) if not unix_user_handler_config.is_active(): unix_user_handler_config.admin_username = status_server_config.admin_username unix_user_handler_config.admin_password = status_server_config.admin_password if self.is_master( ) and not unix_user_handler_config.is_active(): msg = "admin_user and admin_password must be supplied in section [UnixUserHandler]" raise configuration.ConfigurationException(msg) if unix_user_handler_config.is_active(): self._user_handler = unix_user_handler.UnixUserHandler( p_config=unix_user_handler_config, p_exclude_user_list=[constants.APPLICATION_USER]) else: self._user_handler = unix_user_handler.UnixUserHandler( p_config=unix_user_handler_config) self._login_mapping = login_mapping.LoginMapping() self._login_mapping.read_from_configuration( p_login_mapping_section_handler=self._login_mapping_section_handler ) self._app_control = app_control.AppControl( p_config=self._config[app_control.SECTION_NAME], p_debug_mode=self._app_config.debug_mode, p_process_handlers=self._process_handlers, p_device_handler=self._client_device_handler, p_persistence=self._persistence, p_rule_handler=self._rule_handler, p_notification_handlers=self._notification_handlers, p_master_connector=self._master_connector, p_prometheus_client=self._prometheus_client, p_user_handler=self._user_handler, p_locale_helper=self.locale_helper, p_login_mapping=self._login_mapping) if self._config[app_control.SECTION_NAME].scan_active: task = base_app.RecurringTask( p_name="app_control.scan_processes(ProcessHandler)", p_handler_method=lambda: self._app_control.scan_processes( p_process_handler=process_handler), p_interval=process_handler.check_interval) self.add_recurring_task(p_recurring_task=task) else: fmt = "Process scanning for this host has been deactivated in configuration" self._logger.warning(fmt) if self._client_device_handler: task = base_app.RecurringTask( p_name="app_control.scan_processes(DeviceHandler)", p_handler_method=lambda: self._app_control.scan_processes( p_process_handler=self._client_device_handler), p_interval=self._client_device_handler.check_interval) self.add_recurring_task(p_recurring_task=task) if status_server_config.is_active(): self._status_server = status_server.StatusServer( p_config=self._config[status_server.SECTION_NAME], p_package_name=PACKAGE_NAME, p_app_control=self._app_control, p_master_connector=self._master_connector, p_persistence=self._persistence, p_is_master=self.is_master(), p_locale_helper=self._locale_helper, p_base_gettext=self.gettext, p_languages=constants.LANGUAGES, p_user_handler=self._user_handler) elif self.is_master(): msg = "Master instance requires port number for web server" raise configuration.ConfigurationException(msg) else: msg = "Slave instance will not start web server due to missing port number" self._logger.warn(msg) task = base_app.RecurringTask( p_name="app_control.check", p_handler_method=self._app_control.check, p_interval=self._app_control.check_interval) self.add_recurring_task(p_recurring_task=task)
def prepare_services(self, p_full_startup=True): device_handler = None if self.is_master(): self._persistence = persistence.Persistence( p_config=self._config[persistence.SECTION_NAME]) if not p_full_startup: return if self.is_master(): self._rule_handler = rule_handler.RuleHandler( p_config=self._config[rule_handler.SECTION_NAME], p_rule_set_configs=self._rule_set_section_handler. rule_set_configs) self._master_connector = master_connector.MasterConnector( p_config=self._config[master_connector.SECTION_NAME]) config = self._config[audio_handler.SECTION_NAME] if config.is_active(): self._notification_handlers.append( audio_handler.AudioHandler(p_config=config)) config = self._config[popup_handler.SECTION_NAME] if config.is_active(): self._notification_handlers.append( popup_handler.PopupHandler(p_config=config)) process_handler = client_process_handler.ClientProcessHandler( p_config=self._config[client_process_handler.SECTION_NAME], p_process_iterator_factory=ProcessIteratorFactory()) self._process_handlers = {process_handler.id: process_handler} client_device_configs = self._client_device_section_handler.client_device_configs if len(client_device_configs) > 0: fmt = "Found {count} client device configuration entry/ies -> activating client device handler" self._logger.info(fmt.format(count=len(client_device_configs))) device_handler = client_device_handler.ClientDeviceHandler( p_config=self._config[client_device_handler.SECTION_NAME], p_client_device_configs=client_device_configs) self._process_handlers[device_handler.id] = device_handler self._app_control = app_control.AppControl( p_config=self._config[app_control.SECTION_NAME], p_debug_mode=self._app_config.debug_mode, p_process_handlers=self._process_handlers, p_persistence=self._persistence, p_rule_handler=self._rule_handler, p_notification_handlers=self._notification_handlers, p_rule_set_configs=self._rule_set_section_handler.rule_set_configs, p_master_connector=self._master_connector) task = base_app.RecurringTask( p_name="app_control.scan_processes(ProcessHandler)", p_handler_method=lambda: self._app_control.scan_processes( p_process_handler=process_handler), p_interval=process_handler._config.check_interval) self.add_recurring_task(p_recurring_task=task) if device_handler: task = base_app.RecurringTask( p_name="app_control.scan_processes(DeviceHandler)", p_handler_method=lambda: self._app_control.scan_processes( p_process_handler=device_handler), p_interval=device_handler._config.check_interval) self.add_recurring_task(p_recurring_task=task) if self._config[status_server.SECTION_NAME].is_active(): self._status_server = status_server.StatusServer( p_config=self._config[status_server.SECTION_NAME], p_package_name=PACKAGE_NAME, p_app_control=self._app_control, p_master_connector=self._master_connector, p_is_master=self.is_master()) elif self.is_master(): msg = "Master instance requires port number for webserver" raise configuration.ConfigurationException(msg) else: msg = "Slave instance will not start webserver due to missing port number" self._logger.warn(msg) task = base_app.RecurringTask( p_name="app_control.check", p_handler_method=self._app_control.check, p_interval=self._app_control._config.check_interval) self.add_recurring_task(p_recurring_task=task)