当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.ElasticsearchException方法代码示例

本文整理汇总了Python中elasticsearch.exceptions.ElasticsearchException方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.ElasticsearchException方法的具体用法?Python exceptions.ElasticsearchException怎么用?Python exceptions.ElasticsearchException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在elasticsearch.exceptions的用法示例。


在下文中一共展示了exceptions.ElasticsearchException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_index_start

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import ElasticsearchException [as 别名]
def get_index_start(self, index, timestamp_field='@timestamp'):
        """ Query for one result sorted by timestamp to find the beginning of the index.

        :param index: The index of which to find the earliest event.
        :return: Timestamp of the earliest event.
        """
        query = {'sort': {timestamp_field: {'order': 'asc'}}}
        try:
            if self.thread_data.current_es.is_atleastsixsix():
                res = self.thread_data.current_es.search(index=index, size=1, body=query,
                                                         _source_includes=[timestamp_field], ignore_unavailable=True)
            else:
                res = self.thread_data.current_es.search(index=index, size=1, body=query, _source_include=[timestamp_field],
                                                         ignore_unavailable=True)
        except ElasticsearchException as e:
            self.handle_error("Elasticsearch query error: %s" % (e), {'index': index, 'query': query})
            return '1969-12-30T00:00:00Z'
        if len(res['hits']['hits']) == 0:
            # Index is completely empty, return a date before the epoch
            return '1969-12-30T00:00:00Z'
        return res['hits']['hits'][0][timestamp_field] 
开发者ID:Yelp,项目名称:elastalert,代码行数:23,代码来源:elastalert.py

示例2: get_dashboard

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import ElasticsearchException [as 别名]
def get_dashboard(self, rule, db_name):
        """ Download dashboard which matches use_kibana_dashboard from Elasticsearch. """
        es = elasticsearch_client(rule)
        if not db_name:
            raise EAException("use_kibana_dashboard undefined")
        query = {'query': {'term': {'_id': db_name}}}
        try:
            # TODO use doc_type = _doc
            res = es.deprecated_search(index='kibana-int', doc_type='dashboard', body=query, _source_include=['dashboard'])
        except ElasticsearchException as e:
            raise EAException("Error querying for dashboard: %s" % (e)).with_traceback(sys.exc_info()[2])

        if res['hits']['hits']:
            return json.loads(res['hits']['hits'][0]['_source']['dashboard'])
        else:
            raise EAException("Could not find dashboard named %s" % (db_name)) 
开发者ID:Yelp,项目名称:elastalert,代码行数:18,代码来源:elastalert.py

示例3: get_aggregated_matches

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import ElasticsearchException [as 别名]
def get_aggregated_matches(self, _id):
        """ Removes and returns all matches from writeback_es that have aggregate_id == _id """

        # XXX if there are more than self.max_aggregation matches, you have big alerts and we will leave entries in ES.
        query = {'query': {'query_string': {'query': 'aggregate_id:%s' % (_id)}}, 'sort': {'@timestamp': 'asc'}}
        matches = []
        try:
            if self.writeback_es.is_atleastsixtwo():
                res = self.writeback_es.search(index=self.writeback_index, body=query,
                                               size=self.max_aggregation)
            else:
                res = self.writeback_es.deprecated_search(index=self.writeback_index, doc_type='elastalert',
                                                          body=query, size=self.max_aggregation)
            for match in res['hits']['hits']:
                matches.append(match['_source'])
                if self.writeback_es.is_atleastsixtwo():
                    self.writeback_es.delete(index=self.writeback_index, id=match['_id'])
                else:
                    self.writeback_es.delete(index=self.writeback_index, doc_type='elastalert', id=match['_id'])
        except (KeyError, ElasticsearchException) as e:
            self.handle_error("Error fetching aggregated matches: %s" % (e), {'id': _id})
        return matches 
开发者ID:Yelp,项目名称:elastalert,代码行数:24,代码来源:elastalert.py

示例4: find_pending_aggregate_alert

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import ElasticsearchException [as 别名]
def find_pending_aggregate_alert(self, rule, aggregation_key_value=None):
        query = {'filter': {'bool': {'must': [{'term': {'rule_name': rule['name']}},
                                              {'range': {'alert_time': {'gt': ts_now()}}},
                                              {'term': {'alert_sent': 'false'}}],
                                     'must_not': [{'exists': {'field': 'aggregate_id'}}]}}}
        if aggregation_key_value:
            query['filter']['bool']['must'].append({'term': {'aggregation_key': aggregation_key_value}})
        if self.writeback_es.is_atleastfive():
            query = {'query': {'bool': query}}
        query['sort'] = {'alert_time': {'order': 'desc'}}
        try:
            if self.writeback_es.is_atleastsixtwo():
                res = self.writeback_es.search(index=self.writeback_index, body=query, size=1)
            else:
                res = self.writeback_es.deprecated_search(index=self.writeback_index, doc_type='elastalert', body=query, size=1)
            if len(res['hits']['hits']) == 0:
                return None
        except (KeyError, ElasticsearchException) as e:
            self.handle_error("Error searching for pending aggregated matches: %s" % (e), {'rule_name': rule['name']})
            return None

        return res['hits']['hits'][0] 
开发者ID:Yelp,项目名称:elastalert,代码行数:24,代码来源:elastalert.py

示例5: get_hits_count

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import ElasticsearchException [as 别名]
def get_hits_count(self, rule, starttime, endtime, index):
        """ Query Elasticsearch for the count of results and returns a list of timestamps
        equal to the endtime. This allows the results to be passed to rules which expect
        an object for each hit.

        :param rule: The rule configuration dictionary.
        :param starttime: The earliest time to query.
        :param endtime: The latest time to query.
        :return: A dictionary mapping timestamps to number of hits for that time period.
        """
        query = self.get_query(
            rule['filter'],
            starttime,
            endtime,
            timestamp_field=rule['timestamp_field'],
            sort=False,
            to_ts_func=rule['dt_to_ts'],
            five=rule['five']
        )

        try:
            res = self.thread_data.current_es.count(index=index, doc_type=rule['doc_type'], body=query, ignore_unavailable=True)
        except ElasticsearchException as e:
            # Elasticsearch sometimes gives us GIGANTIC error messages
            # (so big that they will fill the entire terminal buffer)
            if len(str(e)) > 1024:
                e = str(e)[:1024] + '... (%d characters removed)' % (len(str(e)) - 1024)
            self.handle_error('Error running count query: %s' % (e), {'rule': rule['name'], 'query': query})
            return None

        self.thread_data.num_hits += res['count']
        lt = rule.get('use_local_time')
        elastalert_logger.info(
            "Queried rule %s from %s to %s: %s hits" % (rule['name'], pretty_ts(starttime, lt), pretty_ts(endtime, lt), res['count'])
        )
        return {endtime: res['count']} 
开发者ID:Yelp,项目名称:elastalert,代码行数:38,代码来源:elastalert.py

示例6: get_starttime

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import ElasticsearchException [as 别名]
def get_starttime(self, rule):
        """ Query ES for the last time we ran this rule.

        :param rule: The rule configuration.
        :return: A timestamp or None.
        """
        sort = {'sort': {'@timestamp': {'order': 'desc'}}}
        query = {'filter': {'term': {'rule_name': '%s' % (rule['name'])}}}
        if self.writeback_es.is_atleastfive():
            query = {'query': {'bool': query}}
        query.update(sort)

        try:
            doc_type = 'elastalert_status'
            index = self.writeback_es.resolve_writeback_index(self.writeback_index, doc_type)
            if self.writeback_es.is_atleastsixtwo():
                if self.writeback_es.is_atleastsixsix():
                    res = self.writeback_es.search(index=index, size=1, body=query,
                                                   _source_includes=['endtime', 'rule_name'])
                else:
                    res = self.writeback_es.search(index=index, size=1, body=query,
                                                   _source_include=['endtime', 'rule_name'])
            else:
                res = self.writeback_es.deprecated_search(index=index, doc_type=doc_type,
                                                          size=1, body=query, _source_include=['endtime', 'rule_name'])
            if res['hits']['hits']:
                endtime = ts_to_dt(res['hits']['hits'][0]['_source']['endtime'])

                if ts_now() - endtime < self.old_query_limit:
                    return endtime
                else:
                    elastalert_logger.info("Found expired previous run for %s at %s" % (rule['name'], endtime))
                    return None
        except (ElasticsearchException, KeyError) as e:
            self.handle_error('Error querying for last run: %s' % (e), {'rule': rule['name']}) 
开发者ID:Yelp,项目名称:elastalert,代码行数:37,代码来源:elastalert.py

示例7: find_recent_pending_alerts

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import ElasticsearchException [as 别名]
def find_recent_pending_alerts(self, time_limit):
        """ Queries writeback_es to find alerts that did not send
        and are newer than time_limit """

        # XXX only fetches 1000 results. If limit is reached, next loop will catch them
        # unless there is constantly more than 1000 alerts to send.

        # Fetch recent, unsent alerts that aren't part of an aggregate, earlier alerts first.
        inner_query = {'query_string': {'query': '!_exists_:aggregate_id AND alert_sent:false'}}
        time_filter = {'range': {'alert_time': {'from': dt_to_ts(ts_now() - time_limit),
                                                'to': dt_to_ts(ts_now())}}}
        sort = {'sort': {'alert_time': {'order': 'asc'}}}
        if self.writeback_es.is_atleastfive():
            query = {'query': {'bool': {'must': inner_query, 'filter': time_filter}}}
        else:
            query = {'query': inner_query, 'filter': time_filter}
        query.update(sort)
        try:
            if self.writeback_es.is_atleastsixtwo():
                res = self.writeback_es.search(index=self.writeback_index, body=query, size=1000)
            else:
                res = self.writeback_es.deprecated_search(index=self.writeback_index,
                                                          doc_type='elastalert', body=query, size=1000)
            if res['hits']['hits']:
                return res['hits']['hits']
        except ElasticsearchException as e:
            logging.exception("Error finding recent pending alerts: %s %s" % (e, query))
        return [] 
开发者ID:Yelp,项目名称:elastalert,代码行数:30,代码来源:elastalert.py

示例8: _create_index_if_missing

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import ElasticsearchException [as 别名]
def _create_index_if_missing(self, name):
        try:
            if not self._es.indices.exists(name):
                self._es.indices.create(name)
        except ElasticsearchException as e:
            self._log_error(e) 
开发者ID:evernote,项目名称:zing,代码行数:8,代码来源:elasticsearch.py

示例9: _es_call

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import ElasticsearchException [as 别名]
def _es_call(self, cmd, *args, **kwargs):
        try:
            return getattr(self._es, cmd)(*args, **kwargs)
        except ElasticsearchException as e:
            self._log_error(e)
            return None 
开发者ID:evernote,项目名称:zing,代码行数:8,代码来源:elasticsearch.py

示例10: send

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import ElasticsearchException [as 别名]
def send(self, logentry):
        try:
            logentry.save()
        except ElasticsearchException as ex:
            logger.exception("ElasticsearchLogsProducer error sending log to Elasticsearch: %s", ex)
            raise LogSendException(
                "ElasticsearchLogsProducer error sending log to Elasticsearch: %s" % ex
            )
        except Exception as e:
            logger.exception(
                "ElasticsearchLogsProducer exception sending log to Elasticsearch: %s", e
            )
            raise LogSendException(
                "ElasticsearchLogsProducer exception sending log to Elasticsearch: %s" % e
            ) 
开发者ID:quay,项目名称:quay,代码行数:17,代码来源:elasticsearch_logs_producer.py

示例11: healthcheck

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import ElasticsearchException [as 别名]
def healthcheck(request):
    index = request.registry.settings["elasticsearch_index"]
    try:
        status = request.es.cluster.health(index=index)["status"]
    except exceptions.ElasticsearchException as exc:
        raise FailedHealthcheck("elasticsearch exception") from exc
    if status not in ("yellow", "green"):
        raise FailedHealthcheck("cluster status was {!r}".format(status))
    return {"status": "ok", "version": bouncer_version} 
开发者ID:hypothesis,项目名称:bouncer,代码行数:11,代码来源:views.py

示例12: test_perform_request_error

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import ElasticsearchException [as 别名]
def test_perform_request_error(self, mock_response):
        mock_response.return_value.status = 500
        connection = AwsHttpConnection(aws_access_key_id='access_key', aws_secret_access_key='secret')
        with self.assertRaises(ElasticsearchException):
            with patch('elasticsearch.connection.base.logger.debug') as mock_logger:
                connection.perform_request('get', 'http://example.com')
                self.assertGreater(mock_logger.call_count, 0) 
开发者ID:edx,项目名称:edx-analytics-pipeline,代码行数:9,代码来源:test_aws_elasticsearch_connection.py

示例13: load

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import ElasticsearchException [as 别名]
def load(self):
        """Loads the trained entity resolution model from disk."""
        try:
            if self._use_text_rel:
                scoped_index_name = get_scoped_index_name(
                    self._app_namespace, self._es_index_name
                )
                if not self._es_client.indices.exists(index=scoped_index_name):
                    self.fit()
            else:
                self.fit()

        except EsConnectionError as e:
            logger.error(
                "Unable to connect to Elasticsearch: %s details: %s", e.error, e.info
            )
            raise EntityResolverConnectionError(es_host=self._es_client.transport.hosts)
        except TransportError as e:
            logger.error(
                "Unexpected error occurred when sending requests to Elasticsearch: %s "
                "Status code: %s details: %s",
                e.error,
                e.status_code,
                e.info,
            )
            raise EntityResolverError
        except ElasticsearchException:
            raise EntityResolverError 
开发者ID:cisco,项目名称:mindmeld,代码行数:30,代码来源:entity_resolver.py

示例14: test_perform_request_error

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import ElasticsearchException [as 别名]
def test_perform_request_error(self, mock_response):
        mock_response.return_value.status = 500
        connection = BotoHttpConnection(aws_access_key_id='access_key', aws_secret_access_key='secret')
        with self.assertRaises(ElasticsearchException):
            with patch('elasticsearch.connection.base.logger.debug') as mock_logger:
                connection.perform_request('get', 'http://example.com')
                self.assertGreater(mock_logger.call_count, 0) 
开发者ID:edx,项目名称:edx-analytics-data-api,代码行数:9,代码来源:test_connections.py

示例15: log_indexing_error

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import ElasticsearchException [as 别名]
def log_indexing_error(cls, indexing_errors):
        """ Logs indexing errors and raises a general ElasticSearch Exception"""
        indexing_errors_log = []
        for indexing_error in indexing_errors:
            indexing_errors_log.append(str(indexing_error))
        raise exceptions.ElasticsearchException(', '.join(indexing_errors_log)) 
开发者ID:edx,项目名称:edx-search,代码行数:8,代码来源:elastic.py


注:本文中的elasticsearch.exceptions.ElasticsearchException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。