def _get_connection(self, key, host, port, user, password, use_cached=True):
        if key in self.dbs and use_cached:
            return self.dbs[key]

        elif host != "" and user != "":
            try:
                if host == 'localhost' and password == '':
                    # Use ident method
                    connection = pg.connect("user=%s dbname=%s" % (user, self.DB_NAME))
                elif port != '':
                    connection = pg.connect(host=host, port=port, user=user,
                                            password=password, database=self.DB_NAME)
                else:
                    connection = pg.connect(host=host, user=user, password=password,
                                            database=self.DB_NAME)

                connection.set_isolation_level(pg.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
                self.log.debug('pgbouncer status: %s' % AgentCheck.OK)

            except Exception:
                message = u'Cannot establish connection to pgbouncer://%s:%s/%s' % (host, port, self.DB_NAME)
                self.service_check(self.SERVICE_CHECK_NAME, AgentCheck.CRITICAL,
                                   tags=self._get_service_checks_tags(host, port),
                                   message=message)
                self.log.debug('pgbouncer status: %s' % AgentCheck.CRITICAL)
                raise
        else:
            if not host:
                raise CheckException("Please specify a PgBouncer host to connect to.")
            elif not user:
                raise CheckException("Please specify a user to connect to PgBouncer as.")

        self.dbs[key] = connection
        return connection
:param k: Metadata header name string.
dataset/ETHPy150Open serverdensity/sd-agent/checks.d/pgbouncer.py/PgBouncer._get_connection--crossover with--dataset/ETHPy150Open dahlia/wand/wand/image.py/Metadata.__getitem__