当前位置: 首页>>代码示例>>Python>>正文


Python Database.delete_task方法代码示例

本文整理汇总了Python中lib.cuckoo.core.database.Database.delete_task方法的典型用法代码示例。如果您正苦于以下问题:Python Database.delete_task方法的具体用法?Python Database.delete_task怎么用?Python Database.delete_task使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lib.cuckoo.core.database.Database的用法示例。


在下文中一共展示了Database.delete_task方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: remove_pending

# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import delete_task [as 别名]
def remove_pending(request):
    db = Database()    
    tasks = db.list_tasks(status=TASK_PENDING)
    for task in tasks:
        db.delete_task(task.id)
        
    return redirect("analysis.views.pending")
开发者ID:AnyMaster,项目名称:el-jefe,代码行数:9,代码来源:views.py

示例2: remove

# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import delete_task [as 别名]
def remove(request, task_id):
    """Remove an analysis.
    @todo: remove folder from storage.
    """
    anals = results_db.analysis.find({"info.id": int(task_id)})

    # Checks if more analysis found with the same ID, like if process.py was run manually.
    if anals.count() > 1:
        message = "Multiple tasks with this ID deleted, thanks for all the fish. (The specified analysis was duplicated in mongo)"
    elif anals.count() == 1:
        message = "Task deleted, thanks for all the fish."

    if anals.count() > 0:
        # Delete dups too.
        for analysis in anals:
            # Delete sample if not used.
            if "file_id" in analysis["target"]:
                if results_db.analysis.find({"target.file_id": ObjectId(analysis["target"]["file_id"])}).count() == 1:
                    fs.delete(ObjectId(analysis["target"]["file_id"]))

            # Delete screenshots.
            for shot in analysis["shots"]:
                if results_db.analysis.find({"shots": ObjectId(shot)}).count() == 1:
                    fs.delete(ObjectId(shot))

            # Delete network pcap.
            if "pcap_id" in analysis["network"] and results_db.analysis.find({"network.pcap_id": ObjectId(analysis["network"]["pcap_id"])}).count() == 1:
                fs.delete(ObjectId(analysis["network"]["pcap_id"]))

            # Delete sorted pcap
            if "sorted_pcap_id" in analysis["network"] and results_db.analysis.find({"network.sorted_pcap_id": ObjectId(analysis["network"]["sorted_pcap_id"])}).count() == 1:
                fs.delete(ObjectId(analysis["network"]["sorted_pcap_id"]))

            # Delete dropped.
            for drop in analysis["dropped"]:
                if "object_id" in drop and results_db.analysis.find({"dropped.object_id": ObjectId(drop["object_id"])}).count() == 1:
                    fs.delete(ObjectId(drop["object_id"]))

            # Delete calls.
            for process in analysis.get("behavior", {}).get("processes", []):
                for call in process["calls"]:
                    results_db.calls.remove({"_id": ObjectId(call)})

            # Delete analysis data.
            results_db.analysis.remove({"_id": ObjectId(analysis["_id"])})
    else:
        return render_to_response("error.html",
                                  {"error": "The specified analysis does not exist"},
                                  context_instance=RequestContext(request))

    # Delete from SQL db.
    db = Database()
    db.delete_task(task_id)

    return render_to_response("success.html",
                              {"message": message},
                              context_instance=RequestContext(request))
开发者ID:453483289,项目名称:cuckoo,代码行数:59,代码来源:views.py

示例3: delete_all

# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import delete_task [as 别名]
def delete_all():  
    """Delete ALL tasks in Cuckoo's local processing queue."""
    
    db = Database()
    list = db.list_tasks()
    
    if not list:
        print(bold(red("Error")) + ": no tasks to be deleted")
    else: 
        for url in list:
            db.delete_task(db.count_tasks())
开发者ID:mcinco,项目名称:zombiebeatdown,代码行数:13,代码来源:taskhandler.py

示例4: drop_report_from_binary

# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import delete_task [as 别名]
def drop_report_from_binary(request,task_id,binary_sha1):
    """ 
    delete report and task
    """ 
    report = results_db.analysis.remove({"info.id": int(task_id)})
    
    if not report:
        db = Database()
        r = db.delete_task(task_id)
    
    return show_reports(request,binary_sha1) 
开发者ID:AnyMaster,项目名称:el-jefe,代码行数:13,代码来源:views.py

示例5: drop_report

# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import delete_task [as 别名]
def drop_report(request,task_id):
    """ 
    delete report and task
    """ 
    report = results_db.analysis.remove({"info.id": int(task_id)})
    
    if not report:
        db = Database()
        r = db.delete_task(task_id)
    
    return index(request) 
开发者ID:AnyMaster,项目名称:el-jefe,代码行数:13,代码来源:views.py

示例6: cuckoo_clean_failed_url_tasks

# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import delete_task [as 别名]
def cuckoo_clean_failed_url_tasks():
    """Clean up failed tasks 
    It deletes all stored data from file system and configured databases (SQL
    and MongoDB for failed tasks.
    """
    # Init logging.
    # This need to init a console logger handler, because the standard
    # logger (init_logging()) logs to a file which will be deleted.
    create_structure()
    init_console_logging()

    # Initialize the database connection.
    db = Database()

    # Check if MongoDB reporting is enabled and drop that if it is.
    cfg = Config("reporting")
    if cfg.mongodb and cfg.mongodb.enabled:
        from pymongo import MongoClient
        host = cfg.mongodb.get("host", "127.0.0.1")
        port = cfg.mongodb.get("port", 27017)
        mdb = cfg.mongodb.get("db", "cuckoo")
        try:
            results_db = MongoClient(host, port)[mdb]
        except:
            log.warning("Unable to connect MongoDB database: %s", mdb)
            return

        done = False
        while not done:
            rtmp = results_db.analysis.find({"info.category": "url", "network.http.0": {"$exists": False}},{"info.id": 1},sort=[("_id", -1)]).limit( 100 )
            if rtmp and rtmp.count() > 0:
                for e in rtmp:
                    if e["info"]["id"]:
                        print e["info"]["id"]
                        try:
                            results_db.suricata.remove({"info.id": int(e["info"]["id"])})
                        except:
                            print "failed to remove %s" % (e["info"]["id"])
                        if db.delete_task(e["info"]["id"]):
                            delete_folder(os.path.join(CUCKOO_ROOT, "storage", "analyses",
                                       "%s" % e["info"]["id"]))
                        else:
                            print "failed to remove %s" % (e["info"]["id"])
                        try:
                            results_db.analysis.remove({"info.id": int(e["info"]["id"])})
                        except:
                            print "failed to remove %s" % (e["info"]["id"])
                    else:
                        done = True
            else:
                done = True 
开发者ID:swackhamer,项目名称:cuckoo-modified,代码行数:53,代码来源:startup.py

示例7: terminate

# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import delete_task [as 别名]
def terminate(request, task_id):
    db = Database()

    task = db.view_task(task_id)
    db.delete_task(task_id)

    if task.status != TASK_PENDING:
        task_running = db.list_tasks(experiment=task.experiment_id, status=TASK_RUNNING)

        if task_running:
            # Ask the task to free the vm once done
            task_running.repeat = TASK_SINGLE
        else:
            # Free the vm assigned to this experiment
            db.unlock_machine_by_experiment(task.experiment_id)

    if len(db.list_tasks(experiment=task.experiment_id)) == 0:
        # No tasks attached to this experiment, no need to keep the experiment
        db.delete_experiment(task.experiment_id)

    return render_to_response("success.html",
        {"message": "Task terminated, thanks for all the fish."},
        context_instance=RequestContext(request))
开发者ID:jbremer,项目名称:longcuckoo,代码行数:25,代码来源:views.py

示例8: cuckoo_clean_before_day

# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import delete_task [as 别名]
def cuckoo_clean_before_day(days=None):
    """Clean up failed tasks 
    It deletes all stored data from file system and configured databases (SQL
    and MongoDB for tasks completed before now - days.
    """
    # Init logging.
    # This need to init a console logger handler, because the standard
    # logger (init_logging()) logs to a file which will be deleted.
    if not days:
        print "No days argument provided bailing"
        return
    create_structure()
    init_console_logging()

    # Initialize the database connection.
    db = Database()

    # Check if MongoDB reporting is enabled and drop that if it is.
    cfg = Config("reporting")
    if cfg.mongodb and cfg.mongodb.enabled:
        from pymongo import MongoClient
        host = cfg.mongodb.get("host", "127.0.0.1")
        port = cfg.mongodb.get("port", 27017)
        mdb = cfg.mongodb.get("db", "cuckoo")
        try:
            results_db = MongoClient(host, port)[mdb]
        except:
            log.warning("Unable to connect to MongoDB database: %s", mdb)
            return

        added_before = datetime.datetime.now() - datetime.timedelta(days=int(days))
        old_tasks = db.list_tasks(added_before=added_before)
        for e in old_tasks:
            new = e.to_dict()
            print int(new["id"])
            try:
                results_db.suricata.remove({"info.id": int(new["id"])})
            except:
                print "failed to remove suricata info (may not exist) %s" % (int(new["id"]))
            try:
                results_db.analysis.remove({"info.id": int(new["id"])})
            except:
                print "failed to remove analysis info (may not exist) %s" % (int(new["id"]))
            if db.delete_task(new["id"]):
                delete_folder(os.path.join(CUCKOO_ROOT, "storage", "analyses",
                       "%s" % int(new["id"])))
            else:
                print "failed to remove faile task %s from DB" % (int(new["id"]))
开发者ID:swackhamer,项目名称:cuckoo-modified,代码行数:50,代码来源:startup.py

示例9: cuckoo_clean_failed_tasks

# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import delete_task [as 别名]
def cuckoo_clean_failed_tasks():
    """Clean up failed tasks 
    It deletes all stored data from file system and configured databases (SQL
    and MongoDB for failed tasks.
    """
    # Init logging.
    # This need to init a console logger handler, because the standard
    # logger (init_logging()) logs to a file which will be deleted.
    create_structure()
    init_console_logging()

    # Initialize the database connection.
    db = Database()

    # Check if MongoDB reporting is enabled and drop that if it is.
    cfg = Config("reporting")
    if cfg.mongodb and cfg.mongodb.enabled:
        from pymongo import MongoClient
        host = cfg.mongodb.get("host", "127.0.0.1")
        port = cfg.mongodb.get("port", 27017)
        mdb = cfg.mongodb.get("db", "cuckoo")
        try:
            results_db = MongoClient(host, port)[mdb]
        except:
            log.warning("Unable to connect to MongoDB database: %s", mdb)
            return 

        failed_tasks_a = db.list_tasks(status=TASK_FAILED_ANALYSIS)
        failed_tasks_p = db.list_tasks(status=TASK_FAILED_PROCESSING)
        failed_tasks_r = db.list_tasks(status=TASK_FAILED_REPORTING)

        for e in failed_tasks_a,failed_tasks_p,failed_tasks_r:
            for el2 in e:
                new = el2.to_dict()
                print int(new["id"])
                try:
                    results_db.suricata.remove({"info.id": int(new["id"])})
                except:
                    print "failed to remove suricata info (may not exist) %s" % (int(new["id"]))
                try:
                    results_db.analysis.remove({"info.id": int(new["id"])})
                except:
                    print "failed to remove analysis info (may not exist) %s" % (int(new["id"]))
                if db.delete_task(new["id"]):
                    delete_folder(os.path.join(CUCKOO_ROOT, "storage", "analyses",
                            "%s" % int(new["id"])))
                else:
                    print "failed to remove faile task %s from DB" % (int(new["id"]))
开发者ID:swackhamer,项目名称:cuckoo-modified,代码行数:50,代码来源:startup.py

示例10: remove

# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import delete_task [as 别名]
def remove(request, task_id):
    """Remove an analysis.
    @todo: remove folder from storage.
    """
    analyses = results_db.analysis.find({"info.id": int(task_id)})

    # Checks if more analysis found with the same ID, like if process.py
    # was run manually.
    if analyses.count() > 1:
        message = (
            "Multiple tasks with this ID deleted, thanks for all the fish "
            "(the specified analysis was present multiple times in mongo)."
        )
    elif analyses.count() == 1:
        message = "Task deleted, thanks for all the fish."

    if not analyses.count():
        return render(request, "error.html", {
            "error": "The specified analysis does not exist",
        })

    for analysis in analyses:
        # Delete sample if not used.
        if "file_id" in analysis["target"]:
            if results_db.analysis.find({"target.file_id": ObjectId(analysis["target"]["file_id"])}).count() == 1:
                fs.delete(ObjectId(analysis["target"]["file_id"]))

        # Delete screenshots.
        for shot in analysis["shots"]:
            if results_db.analysis.find({"shots": ObjectId(shot)}).count() == 1:
                fs.delete(ObjectId(shot))

        # Delete network pcap.
        if "pcap_id" in analysis["network"] and results_db.analysis.find({"network.pcap_id": ObjectId(analysis["network"]["pcap_id"])}).count() == 1:
            fs.delete(ObjectId(analysis["network"]["pcap_id"]))

        # Delete sorted pcap
        if "sorted_pcap_id" in analysis["network"] and results_db.analysis.find({"network.sorted_pcap_id": ObjectId(analysis["network"]["sorted_pcap_id"])}).count() == 1:
            fs.delete(ObjectId(analysis["network"]["sorted_pcap_id"]))

        # Delete mitmproxy dump.
        if "mitmproxy_id" in analysis["network"] and results_db.analysis.find({"network.mitmproxy_id": ObjectId(analysis["network"]["mitmproxy_id"])}).count() == 1:
            fs.delete(ObjectId(analysis["network"]["mitmproxy_id"]))

        # Delete dropped.
        for drop in analysis.get("dropped", []):
            if "object_id" in drop and results_db.analysis.find({"dropped.object_id": ObjectId(drop["object_id"])}).count() == 1:
                fs.delete(ObjectId(drop["object_id"]))

        # Delete calls.
        for process in analysis.get("behavior", {}).get("processes", []):
            for call in process["calls"]:
                results_db.calls.remove({"_id": ObjectId(call)})

        # Delete analysis data.
        results_db.analysis.remove({"_id": ObjectId(analysis["_id"])})

    # Delete from SQL db.
    db = Database()
    db.delete_task(task_id)

    return render(request, "success.html", {
        "message": message,
    })
开发者ID:HarryR,项目名称:cuckoo,代码行数:66,代码来源:views.py

示例11: remove

# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import delete_task [as 别名]
def remove(request, task_id):
    """Remove an analysis.
    @todo: remove folder from storage.
    """
    if enabledconf["mongodb"]:
        analyses = results_db.analysis.find({"info.id": int(task_id)})
        # Checks if more analysis found with the same ID, like if process.py was run manually.
        if analyses.count() > 1:
            message = "Multiple tasks with this ID deleted."
        elif analyses.count() == 1:
            message = "Task deleted."

        if analyses.count() > 0:
            # Delete dups too.
            for analysis in analyses:
                # Delete sample if not used.
                if "file_id" in analysis["target"]:
                    if (
                        results_db.analysis.find({"target.file_id": ObjectId(analysis["target"]["file_id"])}).count()
                        == 1
                    ):
                        fs.delete(ObjectId(analysis["target"]["file_id"]))

                # Delete screenshots.
                for shot in analysis["shots"]:
                    if results_db.analysis.find({"shots": ObjectId(shot)}).count() == 1:
                        fs.delete(ObjectId(shot))

                # Delete network pcap.
                if (
                    "pcap_id" in analysis["network"]
                    and results_db.analysis.find({"network.pcap_id": ObjectId(analysis["network"]["pcap_id"])}).count()
                    == 1
                ):
                    fs.delete(ObjectId(analysis["network"]["pcap_id"]))

                # Delete sorted pcap
                if (
                    "sorted_pcap_id" in analysis["network"]
                    and results_db.analysis.find(
                        {"network.sorted_pcap_id": ObjectId(analysis["network"]["sorted_pcap_id"])}
                    ).count()
                    == 1
                ):
                    fs.delete(ObjectId(analysis["network"]["sorted_pcap_id"]))

                # Delete dropped.
                for drop in analysis["dropped"]:
                    if (
                        "object_id" in drop
                        and results_db.analysis.find({"dropped.object_id": ObjectId(drop["object_id"])}).count() == 1
                    ):
                        fs.delete(ObjectId(drop["object_id"]))
                # Delete calls.
                for process in analysis.get("behavior", {}).get("processes", []):
                    for call in process["calls"]:
                        results_db.calls.remove({"_id": ObjectId(call)})
                # Delete analysis data.
                results_db.analysis.remove({"_id": ObjectId(analysis["_id"])})
        else:
            return render_to_response(
                "error.html",
                {"error": "The specified analysis does not exist"},
                context_instance=RequestContext(request),
            )
    if enabledconf["elasticsearchdb"]:
        analyses = es.search(index=fullidx, doc_type="analysis", q='info.id: "%s"' % task_id)["hits"]["hits"]
        if len(analyses) > 1:
            message = "Multiple tasks with this ID deleted."
        elif len(analyses) == 1:
            message = "Task deleted."
        if len(analyses) > 0:
            for analysis in analyses:
                esidx = analysis["_index"]
                esid = analysis["_id"]
                # Check if behavior exists
                if analysis["_source"]["behavior"]:
                    for process in analysis["_source"]["behavior"]["processes"]:
                        for call in process["calls"]:
                            es.delete(index=esidx, doc_type="calls", id=call)
                # Delete the analysis results
                es.delete(index=esidx, doc_type="analysis", id=esid)

    # Delete from SQL db.
    db = Database()
    db.delete_task(task_id)

    return render_to_response("success_simple.html", {"message": message}, context_instance=RequestContext(request))
开发者ID:rubenespadas,项目名称:cuckoo-modified,代码行数:90,代码来源:views.py

示例12: cuckoo_clean_before_day

# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import delete_task [as 别名]
def cuckoo_clean_before_day(args):
    """Clean up failed tasks
    It deletes all stored data from file system and configured databases (SQL
    and MongoDB for tasks completed before now - days.
    """
    # Init logging.
    # This need to init a console logger handler, because the standard
    # logger (init_logging()) logs to a file which will be deleted.
    if not args.delete_older_than_days:
        print "No days argument provided bailing"
        return
    else:
        days = args.delete_older_than_days
    create_structure()
    init_console_logging()
    id_arr = []

    # Initialize the database connection.
    db = Database()

    # Check if MongoDB reporting is enabled and drop that if it is.
    cfg = Config("reporting")
    if cfg.mongodb and cfg.mongodb.enabled:
        from pymongo import MongoClient
        host = cfg.mongodb.get("host", "127.0.0.1")
        port = cfg.mongodb.get("port", 27017)
        mdb = cfg.mongodb.get("db", "cuckoo")
        try:
            results_db = MongoClient(host, port)[mdb]
        except:
            log.warning("Unable to connect to MongoDB database: %s", mdb)
            return

        added_before = datetime.now() - timedelta(days=int(days))
        if args.files_only_filter:
            print("file filter applied")
            old_tasks = db.list_tasks(added_before=added_before,category="file")
        elif args.urls_only_filter:
            print("url filter applied")
            old_tasks = db.list_tasks(added_before=added_before,category="url")
        else:
            old_tasks = db.list_tasks(added_before=added_before)

        for e in old_tasks:
            new = e.to_dict()
            print int(new["id"])
            id_arr.append({"info.id":(int(new["id"]))})

        print "number of matching records %s before suri/custom filter " % len(id_arr)
        if id_arr and args.suricata_zero_alert_filter:
            result = list(results_db.analysis.find({"suricata.alerts.alert": {"$exists": False}, "$or": id_arr},{"info.id":1}))
            tmp_arr =[]
            for entry in result:
                tmp_arr.append(entry["info"]["id"])
            id_arr = tmp_arr
        if id_arr and args.custom_include_filter:
            result = list(results_db.analysis.find({"info.custom": {"$regex": args.custom_include_filter},"$or": id_arr},{"info.id":1}))
            tmp_arr = []
            for entry in result:
                tmp_arr.append(entry["info"]["id"])
            id_arr = tmp_arr
        print "number of matching records %s" % len(id_arr)
        for e in id_arr:
            try:
                print "removing %s from analysis db" % (e)
                results_db.analysis.remove({"info.id": e})
            except:
                print "failed to remove analysis info (may not exist) %s" % (e)
            if db.delete_task(e):
                delete_folder(os.path.join(CUCKOO_ROOT, "storage", "analyses",
                       "%s" % e))
            else:
                print "failed to remove faile task %s from DB" % (e)
开发者ID:CIRCL,项目名称:cuckoo-modified,代码行数:75,代码来源:startup.py

示例13: remove

# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import delete_task [as 别名]
def remove(request, task_id):
    """Remove an analysis.
    @todo: remove folder from storage.
    """
    if enabledconf["mongodb"]:
        analyses = results_db.analysis.find({"info.id": int(task_id)})
        # Checks if more analysis found with the same ID, like if process.py was run manually.
        if analyses.count() > 1:
            message = "Multiple tasks with this ID deleted."
        elif analyses.count() == 1:
            message = "Task deleted."

        if analyses.count() > 0:
            # Delete dups too.
            for analysis in analyses:
                # Delete calls.
                for process in analysis.get("behavior", {}).get("processes", []):
                    for call in process["calls"]:
                        results_db.calls.remove({"_id": ObjectId(call)})
                # Delete analysis data.
                results_db.analysis.remove({"_id": ObjectId(analysis["_id"])})
        else:
            return render_to_response("error.html",
                                      {"error": "The specified analysis does not exist"},
                                      context_instance=RequestContext(request))
    if enabledconf["elasticsearchdb"]:
        analyses = es.search(
                       index=fullidx,
                       doc_type="analysis",
                       q="info.id: \"%s\"" % task_id
                   )["hits"]["hits"]
        if len(analyses) > 1:
            message = "Multiple tasks with this ID deleted."
        elif len(analyses) == 1:
            message = "Task deleted."
        if len(analyses) > 0:
            for analysis in analyses:
                esidx = analysis["_index"]
                esid = analysis["_id"]
                # Check if behavior exists
                if analysis["_source"]["behavior"]:
                    for process in analysis["_source"]["behavior"]["processes"]:
                        for call in process["calls"]:
                            es.delete(
                                index=esidx,
                                doc_type="calls",
                                id=call,
                            )
                # Delete the analysis results
                es.delete(
                    index=esidx,
                    doc_type="analysis",
                    id=esid,
                )

    # Delete from SQL db.
    db = Database()
    db.delete_task(task_id)

    return render_to_response("success_simple.html",
                              {"message": message},
                              context_instance=RequestContext(request))
开发者ID:hsheep,项目名称:cuckoo-modified,代码行数:64,代码来源:views.py

示例14: remove_task

# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import delete_task [as 别名]
def remove_task(task_id):
    #for this not to take eternity you need to create the following indexes
    #mongo
    #use cuckoo
    #db.analysis.createIndex({"shots":1},{"background":1})
    #db.analysis.createIndex({"network.pcap_id":1},{"background":1})
    #db.analysis.createIndex({"network.sorted_pcap_id":1},{"background":1})
    #db.analysis.createIndex({"dropped.object_id":1},{"background":1})
    #db.suricata.createIndex({"files.object_id":1},{"background":1})
    #db.analysis.createIndex({"info.custom":1},{"background":1})

    # Initialize the database connection.
    db = Database()
    
    # Check if MongoDB reporting is enabled and drop that if it is.
    cfg = Config("reporting")
    if cfg.mongodb and cfg.mongodb.enabled:
        from pymongo import MongoClient
        host = cfg.mongodb.get("host", "127.0.0.1")
        port = cfg.mongodb.get("port", 27017)
        mdb = cfg.mongodb.get("db", "cuckoo")
        from gridfs import GridFS
        try:
            results_db = MongoClient(host, port)[mdb]
        except:
            log.warning("Unable to connect to MongoDB database: %s", mdb)
            return
        
        analyses = results_db.analysis.find({"info.id": int(task_id)})
        suri = results_db.suricata.find({"info.id": int(task_id)})
        fs = GridFS(results_db)

        print "going to delete task id %s" % (task_id)
        # Checks if more analysis found with the same ID, like if process.py was run manually.
        if analyses.count() > 1:
            message = "Multiple tasks with this ID deleted."
        elif analyses.count() == 1:
            message = "Task deleted."

        if analyses.count() > 0:
            # Delete dups too.
            for analysis in analyses:
                print "deleting target"
                # Delete sample if not used.
                if "file_id" in analysis["target"]:
                    if results_db.analysis.find({"target.file_id": ObjectId(analysis["target"]["file_id"])}).count() == 1:
                        fs.delete(ObjectId(analysis["target"]["file_id"]))
                print "deleting screenshots"
                # Delete screenshots.
                for shot in analysis["shots"]:
                    if results_db.analysis.find({"shots": ObjectId(shot)}).count() == 1:
                        fs.delete(ObjectId(shot))
                print "deleting pcap"
                # Delete network pcap.
                if "pcap_id" in analysis["network"] and results_db.analysis.find({"network.pcap_id": ObjectId(analysis["network"]["pcap_id"])}).count() == 1:
                    fs.delete(ObjectId(analysis["network"]["pcap_id"]))

                print "deleting sorted_pcap"
                # Delete sorted pcap
                if "sorted_pcap_id" in analysis["network"] and results_db.analysis.find({"network.sorted_pcap_id": ObjectId(analysis["network"]["sorted_pcap_id"])}).count() == 1:
                    fs.delete(ObjectId(analysis["network"]["sorted_pcap_id"]))

                print "deleting dropped"
                # Delete dropped.
                for drop in analysis["dropped"]:
                    if "object_id" in drop and results_db.analysis.find({"dropped.object_id": ObjectId(drop["object_id"])}).count() == 1:
                        fs.delete(ObjectId(drop["object_id"]))               
                print "deleting calls"
                # Delete calls.
                for process in analysis.get("behavior", {}).get("processes", []):
                    for call in process["calls"]:
                        results_db.calls.remove({"_id": ObjectId(call)})
                print "remove analysis data"
                # Delete analysis data.
                results_db.analysis.remove({"_id": ObjectId(analysis["_id"])})
                # we may not have any suri entries
                if suri.count() > 0:
                    for suricata in suri:
                        if "files" in suricata.keys():
                            print "removing suri files"
                            for entry in suricata["files"]:
                                if "object_id" in entry and results_db.suricata.find({"files.object_id": ObjectId(entry["object_id"])}).count() == 1:
                                    fs.delete(ObjectId(entry["object_id"]))

                        results_db.suricata.remove({"_id": ObjectId(suricata["_id"])})
        print "remove task from db"
        result = db.delete_task(task_id)
        if not result:
            print "failed to remove from db"
        print "removing file structure"
        delete_folder(os.path.join(CUCKOO_ROOT, "storage", "analyses",
                      "%s" % int(task_id)))
开发者ID:HardlyHaki,项目名称:cuckoo-modified,代码行数:94,代码来源:startup.py


注:本文中的lib.cuckoo.core.database.Database.delete_task方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。