def test_kibanayaml_update_username(self): self.config_manager.elasticsearch_username = '******' self.config_manager.write_config() config_manager_read = config.ConfigManager(self.config_directory) assert (config_manager_read.elasticsearch_username == 'jamin123')
def test_kibanayaml_update_password(self): self.config_manager.elasticsearch_password = '******' self.config_manager.write_config() config_manager_read = config.ConfigManager(self.config_directory) assert (config_manager_read.elasticsearch_password == '!jamin111&^@1')
def test_kibanayaml_update_server_host(self): self.config_manager.server_host = 'localhost' self.config_manager.write_config() config_manager_read = config.ConfigManager(self.config_directory) assert (config_manager_read.server_host == 'localhost')
def test_kibanayaml_update_server_port(self): self.config_manager.server_port = 9999 self.config_manager.write_config() config_manager_read = config.ConfigManager(self.config_directory) assert (config_manager_read.server_port == 9999)
def _setup_default_kibana_configs(self): self.logger.info('Overwriting default configuration.') shutil.copy(os.path.join(const.DEFAULT_CONFIGS, 'kibana', 'kibana.yml'), self.configuration_directory) try: local_config = kibana_configs.ConfigManager(self.configuration_directory) except kibana_exceptions.ReadKibanaConfigError: raise kibana_exceptions.InstallKibanaError("Failed to read kibana config.") except Exception as e: raise kibana_exceptions.InstallKibanaError( "General error occurred while reading kibana configs; {}".format(e)) local_config.elasticsearch_hosts = ['http://{}:{}'.format(self.elasticsearch_host, self.elasticsearch_port)] local_config.server_host = self.host local_config.server_port = self.port local_config.elasticsearch_password = self.elasticsearch_password local_config.elasticsearch_username = '******' try: local_config.write_config() except kibana_exceptions.WriteKibanaConfigError: self.logger.error('Failed to write kibana config.') raise kibana_exceptions.InstallKibanaError("Failed to write kibana config.") except Exception as e: self.logger.error('General error occurred while writing kibana configs.') self.logger.debug('General error occurred while writing kibana configs; {}'.format(e)) raise kibana_exceptions.InstallKibanaError( "General error occurred while writing kibana configs; {}".format(e))
def setUp(self): self.config_root = '/etc/dynamite/test' self.config_directory = os.path.join(self.config_root, 'kibana') # Setup Test Space os.makedirs(self.config_directory, exist_ok=True) create_dummy_kibanayaml(self.config_directory) self.config_manager = config.ConfigManager( configuration_directory=self.config_directory)
def is_listening(self): if not self.kibana_config: return False if not os.path.exists(self.kibana_config): return False kb_config_obj = kibana_config.ConfigManager(configuration_directory=self.kibana_config) host = kb_config_obj.server_host port = kb_config_obj.server_port if host.strip() == '0.0.0.0': host = 'localhost' return utilities.check_socket(host, port)
def is_listening(self): """Check if Kibana is listening Returns: True, if listening """ if not self.kibana_config: return False if not os.path.exists(self.kibana_config): return False kb_config_obj = kibana_config.ConfigManager(configuration_directory=self.kibana_config) host = kb_config_obj.host port = kb_config_obj.port if host.strip() == '0.0.0.0': host = 'localhost' return utilities.check_socket(host, port)
from dynamite_nsm.services.kibana import config from dynamite_nsm.utilities import get_environment_file_dict from dynamite_nsm.cmd.service_interfaces import SimpleConfigManagerInterface env_vars = get_environment_file_dict() try: interface = \ SimpleConfigManagerInterface(config.ConfigManager(env_vars['KIBANA_PATH_CONF']), interface_name='Kibana Configuration', interface_description='Configure Kibana on this machine.', defaults=dict(configuration_directory=env_vars['KIBANA_PATH_CONF'], stdout=True) ) except KeyError: interface = None except FileNotFoundError: interface = None """ if not interface: print(f'Skipping kibana.config.main as it was never retrieved successfully') """
def setup(self, host: Optional[str] = None, port: Optional[int] = None, elasticsearch_targets: Optional[List[str]] = None) -> None: """Setup Kibana Args: host: The IP or hostname to listen on port: The port to listen on elasticsearch_targets: A list of Elasticsearch urls Returns: None """ sysctl = systemctl.SystemCtl() # Directory setup self.logger.debug( f'Creating directory: {self.configuration_directory}') utilities.makedirs(self.configuration_directory) self.logger.debug(f'Creating directory: {self.install_directory}') utilities.makedirs(self.install_directory) self.logger.debug(f'Creating directory: {self.log_directory}') utilities.makedirs(self.log_directory) self.copy_kibana_files_and_directories() self.create_update_kibana_environment_variables() self.copy_file_or_directory_to_destination( f'{const.DEFAULT_CONFIGS}/kibana/kibana.yml', self.configuration_directory) # Optimize Configurations kb_main_config = config.ConfigManager(self.configuration_directory) if not host: host = utilities.get_primary_ip_address() if not port: port = 5601 if not elasticsearch_targets: elasticsearch_targets = [ f'https://{utilities.get_primary_ip_address()}:9200' ] self.logger.debug(f'Elasticsearch Targets = {elasticsearch_targets}') kb_main_config.host = host kb_main_config.port = port self.logger.debug( f'Kibana will listen on {kb_main_config.host}:{kb_main_config.port}' ) kb_main_config.elasticsearch_targets = elasticsearch_targets self.logger.info('Applying configuration.') kb_main_config.commit() # Fix Permissions utilities.set_ownership_of_file(self.configuration_directory, user='******', group='dynamite') utilities.set_ownership_of_file(self.install_directory, user='******', group='dynamite') utilities.set_ownership_of_file(self.log_directory, user='******', group='dynamite') # Install and enable service self.logger.info( f'Installing service -> {const.DEFAULT_CONFIGS}/systemd/kibana.service' ) sysctl.install_and_enable( f'{const.DEFAULT_CONFIGS}/systemd/kibana.service') self.logger.info('Installing "BaseViews" Kibana package') task = install_dynamite_base_views.InstallKibanaDynamiteBaseViewsPackage( username='******', password='******', target=f"http://{host}:{port}") task.download_and_install()
def uninstall_kibana(prompt_user=True, stdout=True, verbose=False): """ Uninstall Kibana/ElastiFlow/Synesis Dashboards :param prompt_user: Print a warning before continuing :param stdout: Print the output to console :param verbose: Include detailed debug messages """ log_level = logging.INFO if verbose: log_level = logging.DEBUG logger = get_logger('KIBANA', level=log_level, stdout=stdout) env_file = os.path.join(const.CONFIG_PATH, 'environment') environment_variables = utilities.get_environment_file_dict() kb_profiler = kibana_profile.ProcessProfiler() if not kb_profiler.is_installed(): raise kibana_exceptions.UninstallKibanaError("Kibana is not installed.") configuration_directory = environment_variables.get('KIBANA_PATH_CONF') kb_config = kibana_configs.ConfigManager(configuration_directory) if prompt_user: sys.stderr.write( '\n\033[93m[-] WARNING! Removing Kibana will uninstall all visualizations and saved searches previously ' 'created.\033[0m\n') resp = utilities.prompt_input('\033[93m[?] Are you sure you wish to continue? ([no]|yes):\033[0m ') while resp not in ['', 'no', 'yes']: resp = utilities.prompt_input('\n\033[93m[?] Are you sure you wish to continue? ([no]|yes):\033[0m ') if resp != 'yes': if stdout: sys.stdout.write('\n[+] Exiting\n') exit(0) if kb_profiler.is_running(): kibana_process.ProcessManager().stop() try: shutil.rmtree(kb_config.kibana_path_conf) shutil.rmtree(kb_config.kibana_home) shutil.rmtree(kb_config.kibana_logs) shutil.rmtree(const.INSTALL_CACHE, ignore_errors=True) env_lines = '' with open(env_file) as env_fr: for line in env_fr.readlines(): if 'KIBANA_PATH_CONF' in line: continue elif 'KIBANA_HOME' in line: continue elif 'KIBANA_LOGS' in line: continue elif line.strip() == '': continue env_lines += line.strip() + '\n' with open(env_file, 'w') as env_fw: env_fw.write(env_lines) except Exception as e: logger.error("General error occurred while attempting to uninstall Kibana.".format(e)) logger.debug("General error occurred while attempting to uninstall Kibana; {}".format(e)) raise kibana_exceptions.UninstallKibanaError( "General error occurred while attempting to uninstall kibana; {}".format(e)) try: sysctl = systemctl.SystemCtl() except general_exceptions.CallProcessError: raise kibana_exceptions.UninstallKibanaError("Could not find systemctl.") sysctl.uninstall_and_disable('kibana')