Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mongodb drop table - connect_to_mongo was returning a Database ob… #20

Merged
merged 2 commits into from
Jan 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions utils/cleaners.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def connect_to_mongo():
username=user,
password=password,
authSource=mdb
)[mdb]
)
except Exception as e:
log.warning("Unable to connect to MongoDB database: {}, {}".format(mdb, e))

Expand Down Expand Up @@ -97,7 +97,8 @@ def delete_data(tid):

def delete_mongo_data(tid):
try:
results_db = connect_to_mongo()
mdb = rep_config.mongodb.get("db", "cuckoo")
results_db = connect_to_mongo()[mdb]
analyses = results_db.analysis.find({"info.id": int(tid)})
if analyses.count > 0:
for analysis in analyses:
Expand Down Expand Up @@ -145,10 +146,11 @@ def cuckoo_clean():
print("Can't connect to mongo")
return
try:
conn.drop_database(conn._Database__name)
mdb = rep_config.mongodb.get("db", "cuckoo")
conn.drop_database(mdb)
conn.close()
except:
log.warning("Unable to drop MongoDB database: %s", conn._Database__name)
log.warning("Unable to drop MongoDB database: %s", mdb)

if rep_config.elasticsearchdb and rep_config.elasticsearchdb.enabled and not rep_config.elasticsearchdb.searchonly:
es = False
Expand Down Expand Up @@ -269,8 +271,8 @@ def cuckoo_clean_failed_url_tasks():
# logger (init_logging()) logs to a file which will be deleted.
create_structure()
init_console_logging()

results_db = connect_to_mongo()
mdb = rep_config.mongodb.get("db", "cuckoo")
results_db = connect_to_mongo()[mdb]
if not results_db:
log.info("Can't connect to mongo")
return
Expand All @@ -295,7 +297,8 @@ def cuckoo_clean_lower_score(args):
init_console_logging()
id_arr = []

results_db = connect_to_mongo()
mdb = rep_config.mongodb.get("db", "cuckoo")
results_db = connect_to_mongo()[mdb]
if not results_db:
log.info("Can't connect to mongo")
return
Expand All @@ -322,7 +325,8 @@ def cuckoo_clean_before_day(args):
init_console_logging()
id_arr = []

results_db = connect_to_mongo()
mdb = rep_config.mongodb.get("db", "cuckoo")
results_db = connect_to_mongo()[mdb]
if not results_db:
log.info("Can't connect to mongo")
return
Expand Down Expand Up @@ -363,7 +367,8 @@ def cuckoo_clean_sorted_pcap_dump():
create_structure()
init_console_logging()

results_db = connect_to_mongo()
mdb = rep_config.mongodb.get("db", "cuckoo")
results_db = connect_to_mongo()[mdb]
if not results_db:
log.info("Can't connect to mongo")
return
Expand Down Expand Up @@ -400,7 +405,8 @@ def cuckoo_clean_pending_tasks():
create_structure()
init_console_logging()

results_db = connect_to_mongo()
mdb = rep_config.mongodb.get("db", "cuckoo")
results_db = connect_to_mongo()[mdb]
if not results_db:
log.info("Can't connect to mongo")
return
Expand Down