예제 #1
0
    def get_analysis(self):
        """ Get protocol buffer version of remote analysis """
        while 1:
            try:
                logger.debug("Getting analysis list for Controller/%s" %
                             self.name)

                # Get reply
                cmd = LophiCommand(G.CTRL_CMD_PICKLE, args=["analysis"])
                analysis_buf = self.send_cmd(cmd)
                status = G.read_socket_data(self.SOCK)

                # unpack protocol buffer
                self.analysis = ProtoBuf.unpack_analysis_list(analysis_buf)

                return status
            except:
                self.connect()
예제 #2
0
    def get_machines(self):
        """ Get protocol buffer version of remote machines """
        while 1:
            try:
                logger.debug("Getting machine list for Controller/%s" %
                             self.name)

                # Get response
                cmd = LophiCommand(G.CTRL_CMD_PICKLE, args=["machines"])
                data = self.send_cmd(cmd)
                status = G.read_socket_data(self.SOCK)

                # Unpack our machine list
                #    (WARNING: This a subset of the objects at the server
                if data is not None:
                    self.machines = ProtoBuf.unpack_machine_list(data)
                else:
                    self.machines = []

                return status
            except:
                G.print_traceback()
                self.connect()
def get_incomplete_analysis(options,positionals):
    """
        Resubmit all incomplete analyses
    """

    out_queue = multiprocessing.Queue()
    ctrl_producer = rabbitmq.LOPHI_RabbitMQ_Producer(options.services_host,
                                                     out_queue,
                                                     G.RabbitMQ.CTRL_IN)
    ctrl_producer.start()

    uri = 'mongodb://'+options.services_host+':27017/'

    print "* Connecting to %s..."%uri

    # Initialize our database connections
    client = MongoClient(uri)

    # Loop over all of our analyses.
    db = client.lophi_db

    # Get a list of all of our samples
    samples_db = db.samples

    analyses = db.analyses

    samples = []
    for sample_entry in samples_db.find():

        has_completed = False
        cmd = None
        for analysis in analyses.find({"sample": sample_entry[
            'sample']}):

            if analysis['status'] == "COMPLETED":
                has_completed = True
            else:
                if analysis['machine_type'] == "":
                    analysis['machine_type'] = options.machine_type

                cmd = LophiCommand(cmd=G.CTRL_CMD_START,
                               analysis=analysis['analysis_script'],
                               machine_type=analysis['machine_type'],
                               machine=None,
                               volatility_profile=analysis['volatility_profile'],
                               sample_doc_id=analysis['sample'],
                               submitter=G.get_username_local())

        if not has_completed and cmd is not None:
            print "* Re-submitting sample (%s)"%sample_entry['sample']
            out_queue.put(str(cmd))


    # for analysis in analyses.find():
    #
    #
    #     if analysis['status'] != "COMPLETED":
    #
    #         print "* Resubmitting %s (Status: %s)" % (analysis['_id'],
    #                                                  analysis['status'])
    #
    #         if analysis['machine_type'] == "":
    #             continue
    #
    #         # # Prepare a job to send to the machine, using the sample doc id
    #         # cmd = LophiCommand(cmd=G.CTRL_CMD_START,
    #         #                    analysis=analysis['analysis_script'],
    #         #                    machine_type=analysis['machine_type'],
    #         #                    machine=None,
    #         #                    volatility_profile=analysis['volatility_profile'],
    #         #                    sample_doc_id=analysis['sample'],
    #         #                    submitter=G.get_username_local())
    #         #
    #         # out_queue.put(str(cmd))

    time.sleep(5)
    out_queue.put(G.CTRL_CMD_KILL)
    ctrl_producer.stop()