in src/plugins/brokers/kibbleES.py [0:0]
def __init__(self, config):
es_config = config['elasticsearch']
auth = None
if 'user' in es_config:
auth = (es_config['user'], es_config['password'])
pprint("Connecting to ElasticSearch database at %s:%i..." % (es_config['hostname'], es_config.get('port', 9200)))
es = elasticsearch.Elasticsearch([{
'host': es_config['hostname'],
'port': int(es_config.get('port', 9200)),
'use_ssl': es_config.get('ssl', False),
'verify_certs': False,
'url_prefix': es_config.get('uri', ''),
'http_auth': auth
}],
max_retries=5,
retry_on_timeout=True
)
es_info = es.info()
pprint("Connected!")
self.DB = es
self.oDB = es # Original ES class, always. the .DB may change
self.config = config
self.bitClass = KibbleBit
# This bit is required since ES 6.x and above don't like document types
self.noTypes = True if int(es_info['version']['number'].split('.')[0]) >= 6 else False
self.seven = True if int(es_info['version']['number'].split('.')[0]) >= 7 else False
if self.noTypes:
pprint("This is a type-less DB, expanding database names instead.")
if self.seven:
pprint("We're using ES >= 7.x, NO DOC_TYPE!")
es = KibbleESWrapperSeven(es)
else:
es = KibbleESWrapper(es)
self.DB = es
if not es.indices.exists(index = es_config['database'] + "_api"):
sys.stderr.write("Could not find database group %s_* in ElasticSearch!\n" % es_config['database'])
sys.exit(-1)
else:
pprint("This DB supports types, utilizing..")
if not es.indices.exists(index = es_config['database']):
sys.stderr.write("Could not find database %s in ElasticSearch!\n" % es_config['database'])
sys.exit(-1)
apidoc = es.get(index=es_config['database'], doc_type='api', id = 'current')['_source']
# We currently accept and know how to use DB versions 1 and 2.
if apidoc['dbversion'] not in ACCEPTED_DB_VERSIONS:
if apidoc['dbversion'] > KIBBLE_DB_VERSION:
sys.stderr.write("The database '%s' uses a newer structure format (version %u) than the scanners (version %u). Please upgrade your scanners.\n" % (es_config['database'], apidoc['dbversion'], KIBBLE_DB_VERSION))
sys.exit(-1)
if apidoc['dbversion'] < KIBBLE_DB_VERSION:
sys.stderr.write("The database '%s' uses an older structure format (version %u) than the scanners (version %u). Please upgrade your main Kibble server.\n" % (es_config['database'], apidoc['dbversion'], KIBBLE_DB_VERSION))
sys.exit(-1)