Skip to content

profile

Profile Elasticsearch processes to ensure they are running and installed properly.

To import...

from dynamite_nsm.services.elasticsearch import profile as elasticsearch_profile

ProcessProfiler

__init__(self) special

Get information about the Elasticsearch service

Source code in dynamite_nsm/services/elasticsearch/profile.py
def __init__(self):
    """
    Get information about the Elasticsearch service
    """
    self.env_file = os.path.join(const.CONFIG_PATH, 'environment')
    self.env_dict = utilities.get_environment_file_dict()
    self.elasticsearch_home = self.env_dict.get('ES_HOME')
    self.elasticsearch_config = self.env_dict.get('ES_PATH_CONF')

    profile.BaseProcessProfiler.__init__(self,
                                         install_directory=self.elasticsearch_home,
                                         config_directory=self.elasticsearch_config,
                                         required_install_files=['bin', 'data', 'lib', 'modules'],
                                         required_config_files=['elasticsearch.yml', 'jvm.options']
                                         )

is_listening(self)

Check if Elasticsearch is listening

Returns:

Type Description
bool

True, if Elasticsearch HTTP service is listening

Source code in dynamite_nsm/services/elasticsearch/profile.py
def is_listening(self) -> bool:
    """ Check if Elasticsearch is listening
    Returns:
        True, if Elasticsearch HTTP service is listening

    """
    if not self.elasticsearch_config:
        return False
    if not os.path.exists(self.elasticsearch_config):
        return False

    es_config_obj = elastic_configs.ConfigManager(configuration_directory=self.elasticsearch_config)
    host = es_config_obj.network_host
    port = es_config_obj.http_port
    return utilities.check_socket(host, port)

is_running(self)

Check if Elasticsearch is running

Returns:

Type Description
bool

True, if running

Source code in dynamite_nsm/services/elasticsearch/profile.py
def is_running(self) -> bool:
    """Check if Elasticsearch is running
    Returns:
        True, if running
    """
    if self.elasticsearch_home:
        try:
            return elastic_process.ProcessManager().status()['running']
        except KeyError:
            return elastic_process.ProcessManager().status()['RUNNING']
    return False