Skip to content
This repository has been archived by the owner on Jun 17, 2023. It is now read-only.

Commit

Permalink
Update create index fixes#446 (#447)
Browse files Browse the repository at this point in the history
* fixes#431

* fixes#431 (#432)

* removing old packetmail feeds (#433)

* update MANIFEST.in to include html template files (#434)

* fix for cif-tokens delete for ES

* fixed manifest to include html template files

* fixes #446

* fix failing tests
  • Loading branch information
meetzoo authored and wesyoung committed Feb 27, 2019
1 parent b9cbebd commit f5c2b88
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cif/store/zelasticsearch/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, *args, **kwargs):
self.partition = PARTITION
self.idx = self._current_index()
self.last_index_check = datetime.now() - timedelta(minutes=5)
self.last_index_value = None
self.handle = connections.get_connection()
self.lockm = LockManager(self.handle, logger)

Expand All @@ -63,11 +64,12 @@ def _current_index(self):
def _create_index(self):
# https://github.com/csirtgadgets/massive-octo-spice/blob/develop/elasticsearch/observables.json
# http://elasticsearch-py.readthedocs.org/en/master/api.html#elasticsearch.Elasticsearch.bulk
idx = self._current_index()

# every time we check it does a HEAD req
if (datetime.utcnow() - self.last_index_check) < timedelta(minutes=2):
return idx
if self.last_index_value and (datetime.utcnow() - self.last_index_check) < timedelta(minutes=2):
return self.last_index_value

idx = self._current_index()

if not self.handle.indices.exists(idx):
index = Index(idx)
Expand All @@ -78,6 +80,7 @@ def _create_index(self):
self.handle.indices.flush(idx)

self.last_index_check = datetime.utcnow()
self.last_index_value = idx
return idx

def search(self, token, filters, sort='reporttime', raw=False, timeout=TIMEOUT):
Expand Down

0 comments on commit f5c2b88

Please sign in to comment.