mirror of https://github.com/jumpserver/jumpserver
				
				
				
			fix: 添加无效的 es 命令记录存储时,抛出错误提示
							parent
							
								
									9fe5496ce9
								
							
						
					
					
						commit
						fd203c67c3
					
				| 
						 | 
				
			
			@ -7,6 +7,7 @@ import pytz
 | 
			
		|||
from uuid import UUID
 | 
			
		||||
import inspect
 | 
			
		||||
 | 
			
		||||
from django.utils.translation import gettext_lazy as _
 | 
			
		||||
from django.db.models import QuerySet as DJQuerySet
 | 
			
		||||
from elasticsearch import Elasticsearch
 | 
			
		||||
from elasticsearch.helpers import bulk
 | 
			
		||||
| 
						 | 
				
			
			@ -14,12 +15,18 @@ from elasticsearch.exceptions import RequestError
 | 
			
		|||
 | 
			
		||||
from common.utils.common import lazyproperty
 | 
			
		||||
from common.utils import get_logger
 | 
			
		||||
from common.exceptions import JMSException
 | 
			
		||||
from .models import AbstractSessionCommand
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
logger = get_logger(__file__)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class InvalidElasticsearch(JMSException):
 | 
			
		||||
    default_code = 'invalid_elasticsearch'
 | 
			
		||||
    default_detail = _('Invalid elasticsearch config')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class CommandStore():
 | 
			
		||||
    def __init__(self, config):
 | 
			
		||||
        hosts = config.get("HOSTS")
 | 
			
		||||
| 
						 | 
				
			
			@ -33,6 +40,8 @@ class CommandStore():
 | 
			
		|||
        self.es = Elasticsearch(hosts=hosts, max_retries=0, **kwargs)
 | 
			
		||||
 | 
			
		||||
    def pre_use_check(self):
 | 
			
		||||
        if not self.ping(timeout=3):
 | 
			
		||||
            raise InvalidElasticsearch
 | 
			
		||||
        self._ensure_index_exists()
 | 
			
		||||
 | 
			
		||||
    def _ensure_index_exists(self):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue