Ejemplo n.º 1
0
 def save_output(self, data, renderedhtml, parsed):
     '''
     save output to file or database
     '''
     temp_id = None
     temp_es = None
     if len(data) > 0:
         if parsed.db_result:
             serialize_obj(data)
             #temp_id = add_item("tasks", "results", dataserialized)
             #if temp_id:
             #    log_string("JSON result added to db", "Yellow")
             #else:
             #    log_string("Unable to add JSON result to db", "Red")
         if parsed.db_dump_json:
             datajson = self.jsonmaker.dump_json_and_return(data)
             temp_id = add_item_fs(defaultdb["dbname"], defaultdb["reportscoll"], datajson, data["Details"]["Properties"]["md5"], data["Details"]["Properties"], parsed.uuid, "application/json", datetime.now())
             #temp_es = push_to_elastic(parsed.uuid, datajson["Details"])
             if temp_id:
                 log_string("JSON result dumped into db", "Yellow")
             else:
                 log_string("Unable to dump JSON result to db", "Red")
             if temp_es:
                 log_string("JSON result dumped into elastic", "Yellow")
             else:
                 log_string("Unable to dump JSON result to elastic", "Red")
         if parsed.db_dump_html:
             datajson = self.jsonmaker.dump_json_and_return(data)
             temp_id = add_item_fs(defaultdb["dbname"], defaultdb["reportscoll"], renderedhtml, data["Details"]["Properties"]["md5"], data["Details"]["Properties"], parsed.uuid, "text/html", datetime.now())
             if temp_id:
                 log_string("HTML result dumped into db", "Yellow")
             else:
                 log_string("Unable to dump HTML result to db", "Red")
Ejemplo n.º 2
0
def cancel_task_logger(task):
    log_string("Closing up task {} logger".format(task), "Yellow")
    dynamic.disabled = True
    logs = ""
    with open(path.join(json_settings[env_var]["logs_folder"], task),
              "rb") as f:
        logs = f.read()
    if len(logs) > 0:
        _id = add_item_fs(defaultdb["dbname"], defaultdb["taskfileslogscoll"],
                          logs, "log", None, task, "text/plain",
                          datetime.now())
        if _id:
            log_string("Logs result dumped into db", "Yellow")
        else:
            log_string("Unable to dump logs result to db", "Red")
    else:
        log_string("Unable to dump logs result to db", "Red")