コード例 #1
0
    def _connect_tenants(self, host, connection_data):
        """
        Connect to the tenants

        Args:
            host (str): Host of the HANA database
            connection_data (dict): Data retrieved from _get_connection_data
        """
        for database, tenant_port in self._get_tenants_port():
            conn = hdb_connector.HdbConnector()
            # If userkey is used database name must be added to connect to tenants
            if connection_data.get('userkey'):
                connection_data['databaseName'] = database
            conn.connect(host, tenant_port, **connection_data)
            self._db_connectors.append(conn)
コード例 #2
0
ファイル: app.py プロジェクト: ayoub-belarbi/hanadb_exporter
def main():
    logging.basicConfig(level=logging.INFO)
    config = parse_config(CONFIG_FILE)

    connector = hdb_connector.HdbConnector()
    try:
        hana_config = config.get('hana')
        connector.connect(hana_config.get('host'),
                          hana_config.get('port', 30015),
                          user=hana_config.get('user'),
                          password=hana_config.get('password'))
    except KeyError as err:
        raise KeyError('Configuration file {} is malformed: {}'.format(
            CONFIG_FILE, err))
    collector = hanadb_exporter.SapHanaExporter.create(
        exporter_type='prometheus', hdb_connector=connector)
    REGISTRY.register(collector)
    start_http_server(config.get('exposition_port', 30015), '0.0.0.0')
    while True:
        time.sleep(1)
コード例 #3
0
def wait_for_connection(host, port, user, password, timeout=60, interval=5):
    '''
    Wait until HANA is ready trying to connect to the database

    host
        Host where HANA is running
    port
        HANA database port
    user
        User to connect to the databse
    password
        Password to connect to the database
    timeout
        Timeout to try to connect to the database
    interval
        Interval to try the connection

    CLI Example:

    .. code-block:: bash

        salt '*' hana.wait_for_hana 192.168.10.15 30015 SYSTEM pass
    '''
    connector = hdb_connector.HdbConnector()
    current_time = time.time()
    current_timeout = current_time + timeout
    while current_time <= current_timeout:
        try:
            connector.connect(host, port, user=user, password=password)
            connector.disconnect()
            break

        except base_connector.ConnectionError:
            time.sleep(interval)
            current_time = time.time()
    else:
        raise exceptions.CommandExecutionError(
            'HANA database not available after {} seconds in {}:{}'.format(
                timeout, host, port))
コード例 #4
0
def run():
    """
    Main execution
    """
    args = parse_arguments()
    config = parse_config(args.config)

    if config.get('logging', None):
        setup_logging(config)
    else:
        logging.basicConfig(level=args.verbosity or logging.INFO)

    logger = logging.getLogger(__name__)
    metrics = args.metrics
    connector = hdb_connector.HdbConnector()
    try:
        hana_config = config['hana']
        connector.connect(hana_config['host'],
                          hana_config.get('port', 30015),
                          user=hana_config['user'],
                          password=hana_config['password'])
    except KeyError as err:
        raise KeyError(
            'Configuration file {} is malformed: {} not found'.format(
                args.config, err))

    collector = exporter_factory.SapHanaExporter.create(
        exporter_type='prometheus',
        metrics_file=metrics,
        hdb_connector=connector)
    REGISTRY.register(collector)
    logger.info('exporter sucessfully registered')
    logger.info('starting to serve metrics')
    start_http_server(config.get('exposition_port', 8001), '0.0.0.0')
    while True:
        time.sleep(1)
コード例 #5
0
 def __init__(self):
     self._logger = logging.getLogger(__name__)
     self._system_db_connector = hdb_connector.HdbConnector()
     self._db_connectors = []
コード例 #6
0
ファイル: init_test.py プロジェクト: stefanotorresi/shaptools
 def test_error(self):
     from shaptools import hdb_connector
     with self.assertRaises(base_connector.DriverNotAvailableError) as err:
         hdb_connector.HdbConnector()
     self.assertTrue('dbapi nor pyhdb are installed' in str(err.exception))