def __init__(self, config, options): self.options = options self.config = config self.logCollector = LogCollector(self.config['device_name'], self.config['logs']) self.forceStopped = False self.device = DeviceOperator(self.config['work_dir']) self.device.pushBinary(self.config['orangutan']) # generate scripts self.script_folder = self.config['script_repo'] if options.gen_scripts: if options.gen_scripts_output: self.script_folder = options.gen_scripts_output if not int(options.gen_scripts_amount ): #if has argv, type will become a string logger.info("Generate script for amount: %d" % self.config['script_amount']) else: logger.info("Generate script for amount: %d" % int(options.gen_scripts_amount)) self.script_folder += '/' + GenRandomSC().gen_random_sc() logger.info("Get scripts from script folder: %s" % self.script_folder) self.scripts = self.getScripts(self.script_folder) # Push binary and scripts onto device logger.info("Orangutan binary: %s" % self.config['orangutan']) logger.info("Orangutan work directory: %s" % self.config['work_dir'])
def start_log_collection(): db = sqlite3.connect(DATABASE_NAME) db_cursor = db.cursor() while True: for client, username in db_cursor.execute( 'select ip, username from {};'.format(CLIENTS_TABLE_NAME)): for paths_as_json in db_cursor.execute('select paths from {} '\ 'where ip="{}";'.format( FILES_TABLE_NAME, client)): paths = json.loads(paths_as_json[0])['paths'] log_collector = LogCollector(username, client, paths) log_collector.collect() time.sleep(LOG_COLLECT_INTERVAL)
def __init__(self, config, options): self.options = options self.config = config self.logCollector = LogCollector(self.config['device_name'], self.config['logs']) self.forceStopped = False self.device = DeviceOperator(self.config['work_dir']) self.device.pushBinary(self.config['orangutan']) # generate scripts self.script_folder = self.config['script_repo'] if options.gen_scripts: if options.gen_scripts_output: self.script_folder = options.gen_scripts_output if not int(options.gen_scripts_amount): #if has argv, type will become a string logger.info("Generate script for amount: %d" % self.config['script_amount']) else: logger.info("Generate script for amount: %d" % int(options.gen_scripts_amount)) self.script_folder += '/'+GenRandomSC().gen_random_sc() logger.info("Get scripts from script folder: %s" % self.script_folder) self.scripts = self.getScripts(self.script_folder) # Push binary and scripts onto device logger.info("Orangutan binary: %s" % self.config['orangutan']) logger.info("Orangutan work directory: %s" % self.config['work_dir'])
class Runner(object): def __init__(self, config, options): self.options = options self.config = config self.logCollector = LogCollector(self.config['device_name'], self.config['logs']) self.forceStopped = False self.device = DeviceOperator(self.config['work_dir']) self.device.pushBinary(self.config['orangutan']) # generate scripts self.script_folder = self.config['script_repo'] if options.gen_scripts: if options.gen_scripts_output: self.script_folder = options.gen_scripts_output if not int(options.gen_scripts_amount): #if has argv, type will become a string logger.info("Generate script for amount: %d" % self.config['script_amount']) else: logger.info("Generate script for amount: %d" % int(options.gen_scripts_amount)) self.script_folder += '/'+GenRandomSC().gen_random_sc() logger.info("Get scripts from script folder: %s" % self.script_folder) self.scripts = self.getScripts(self.script_folder) # Push binary and scripts onto device logger.info("Orangutan binary: %s" % self.config['orangutan']) logger.info("Orangutan work directory: %s" % self.config['work_dir']) def getScripts(self, script_repo): scripts = [] for dir_path, dir_names, dir_files in os.walk(script_repo): for f in dir_files: if f.endswith(".sc"): scripts.append(f) self.device.pushScript(os.path.join(dir_path, f)) logger.debug("script %s is in queue now" % f) return scripts def run(self, infinity=False): orng = os.path.join('/data/', os.path.basename(self.config['orangutan'])) command = ['adb', 'shell', orng, self.config['tevent']+'$'+ self.config['hevent']+'$'+ self.config['pevent']+'$'+ self.config['vuevent']+'$'+ self.config['vdevent'], 'script_place_holder'] logger.debug("sciprt queue: %s" % self.scripts) for script in self.scripts: if not self.forceStopped: logger.info("Trigger Script: " + script) command[-1] = os.path.join(self.config['work_dir'], script) logger.info("command: %s" % ' '.join(command)) self.currentProcess = subprocess.Popen(command) self.currentProcess.wait() if infinity: logger.info("check crash") crash, crashTime = self.logCollector.checkCrashReport() if crash: logger.critical("Crashed at: %s" % crashTime) self.forceStopped = True break if not self.scripts.index(script) % 3: self.collectLog() self.collectLog() self.collectCrash() self.logCollector.genReport() def stopRunning(self, signum=None, frame=None): self.forceStopped = True self.currentProcess.terminate() logger.info("Force Stop") os.system("adb shell ps | grep orng | awk '{print $2}' | xargs adb shell kill") self.collectLog() self.collectCrash() self.logCollector.genReport() def collectLog(self): logger.info("Collect Logs") self.logCollector.getLogs() def collectCrash(self): logger.info("Collect Crash Reports") self.logCollector.getCrashReport()
class Runner(object): def __init__(self, config, options): self.options = options self.config = config self.logCollector = LogCollector(self.config['device_name'], self.config['logs']) self.forceStopped = False self.device = DeviceOperator(self.config['work_dir']) self.device.pushBinary(self.config['orangutan']) # generate scripts self.script_folder = self.config['script_repo'] if options.gen_scripts: if options.gen_scripts_output: self.script_folder = options.gen_scripts_output if not int(options.gen_scripts_amount ): #if has argv, type will become a string logger.info("Generate script for amount: %d" % self.config['script_amount']) else: logger.info("Generate script for amount: %d" % int(options.gen_scripts_amount)) self.script_folder += '/' + GenRandomSC().gen_random_sc() logger.info("Get scripts from script folder: %s" % self.script_folder) self.scripts = self.getScripts(self.script_folder) # Push binary and scripts onto device logger.info("Orangutan binary: %s" % self.config['orangutan']) logger.info("Orangutan work directory: %s" % self.config['work_dir']) def getScripts(self, script_repo): scripts = [] for dir_path, dir_names, dir_files in os.walk(script_repo): for f in dir_files: if f.endswith(".sc"): scripts.append(f) self.device.pushScript(os.path.join(dir_path, f)) logger.debug("script %s is in queue now" % f) return scripts def run(self, infinity=False): orng = os.path.join('/data/', os.path.basename(self.config['orangutan'])) command = [ 'adb', 'shell', orng, self.config['tevent'] + '$' + self.config['hevent'] + '$' + self.config['pevent'] + '$' + self.config['vuevent'] + '$' + self.config['vdevent'], 'script_place_holder' ] logger.debug("sciprt queue: %s" % self.scripts) for script in self.scripts: if not self.forceStopped: logger.info("Trigger Script: " + script) command[-1] = os.path.join(self.config['work_dir'], script) logger.info("command: %s" % ' '.join(command)) self.currentProcess = subprocess.Popen(command) self.currentProcess.wait() if infinity: logger.info("check crash") crash, crashTime = self.logCollector.checkCrashReport() if crash: logger.critical("Crashed at: %s" % crashTime) self.forceStopped = True break if not self.scripts.index(script) % 3: self.collectLog() self.collectLog() self.collectCrash() self.logCollector.genReport() def stopRunning(self, signum=None, frame=None): self.forceStopped = True self.currentProcess.terminate() logger.info("Force Stop") os.system( "adb shell ps | grep orng | awk '{print $2}' | xargs adb shell kill" ) self.collectLog() self.collectCrash() self.logCollector.genReport() def collectLog(self): logger.info("Collect Logs") self.logCollector.getLogs() def collectCrash(self): logger.info("Collect Crash Reports") self.logCollector.getCrashReport()