File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,10 +46,7 @@ def __init__(self):
4646 if not log .ThugOpts .elasticsearch_logging :
4747 return
4848
49- if not self .__init_elasticsearch ():
50- return
51-
52- self .enabled = True
49+ self .enabled = self .__init_elasticsearch ()
5350
5451 def __init_config (self ):
5552 self .opts = {}
@@ -76,16 +73,16 @@ def __init_elasticsearch(self):
7673
7774 self .es = elasticsearch .Elasticsearch (self .opts ["url" ])
7875
79- if not self .es .ping ():
80- log . warning ( "[WARNING] ElasticSearch instance not properly initialized" )
81- return False
76+ if self .es .ping (): # pragma: no cover
77+ self . es . options ( ignore_status = 404 ). indices . create ( index = self . opts [ "index" ] )
78+ return True
8279
83- self . es . options ( ignore_status = 404 ). indices . create ( index = self . opts [ "index" ] )
84- return True
80+ log . warning ( "[WARNING] ElasticSearch instance not properly initialized" )
81+ return False
8582
8683 def export (self , basedir ): # pylint:disable=unused-argument
87- if not self .enabled :
88- return None
84+ if self .enabled : # pragma: no cover
85+ res = self .es .index (index = self .opts ["index" ], document = self .data )
86+ return res ["_id" ]
8987
90- res = self .es .index (index = self .opts ["index" ], document = self .data )
91- return res ["_id" ]
88+ return None
You can’t perform that action at this time.
0 commit comments