def show_at_page(): client = AiClothClient() all_deb_list = client.get_al_deb() deb_list = [] for i in all_deb_list: if i.startswith("flaw") or i.startswith("detection"): deb_list.append(i) push_deb_shell = 'python3 auto_push_deb.py --deb ' + i + ' --env prod' print(push_deb_shell) print()
def __init__(self, client: AiClothClient, machineId: str, check_version_key: str, target_version_value: str, deb_name: str, dry_run: bool): super().__init__() self.client = client self.machineId = machineId self.deb_name = deb_name self.check_version_key = check_version_key self.target_version_value = target_version_value self.displayName = client.get_display_name_from_cache(machineId) self.status = self.STATUS_JUST_STARTED self.errorCount = 0 self.dry_run = dry_run os.makedirs('logs', exist_ok=True) self.logger = logging.getLogger( 'DebAutoPusher_{}.log'.format(machineId)) self.logger.setLevel(logging.INFO) handler = TimedRotatingFileHandler( 'logs/DebAutoPusher_{}.log'.format(machineId), when='midnight', interval=1, backupCount=7) formatter = logging.Formatter( '%(asctime)s - %(levelname)s - %(message)s') handler.setFormatter(formatter) self.logger.propagate = False self.logger.addHandler(handler) self.logger.info('Started DebAutoPusher %s %s %s %s', machineId, check_version_key, target_version_value, deb_name)
def show_at_page(): client = AiClothClient() all_deb_list = client.get_al_deb() deb_list = [] for i in all_deb_list: if i.startswith("flaw") or i.startswith("detection"): deb_list.append(i) deb_xargs = 'false' if request.method == 'POST': ## request.form( ## post request.form deb_xargs = request.form['deb_xargs'] deb_xargs = deb_xargs.strip() if_to_push_deb = request.form['not_or_yes'] push_deb_shell = 'python3 auto_push_deb.py --deb ' + deb_xargs + ' --env prod' #status,out = subprocess.getstatusoutput(push_deb_shell) status = os.system(push_deb_shell) print(push_deb_shell) print(status) return render_template("push.html", **locals())
def loginVerification(env): if env == 'prod': print('Using prod server!') client = AiClothClient() else: print('Using dev server!') client = AiClothClient(base_url=AiClothClient.DEV_SERVER_BASE_URL, cookie_path='dev-cookie.txt') client.interactive_login() machine_list = client.get_machine_list() target_machines = machine_list['machines'] return client, target_machines
machine_alerts[machineId].append(x['metric']) supposed_running_machine = filter(lambda m:isMachineServiceDown(m, machine_alerts, alertkeywords), machine_list) supposed_running_machine = list(supposed_running_machine) print('alert machines: ', len(supposed_running_machine)) machine_id_list = [] for m in supposed_running_machine: machineAlias = m['aliasName'] machineId = m['Id'] if machineId in lastRestartTimeMap and time.time() - lastRestartTimeMap[machineId] < 300: print('{} is restarted in 5min, skip'.format(machineId)) continue lastRestartTimeMap[machineId] = time.time() alertinfo = machine_alerts[machineId] print ("\033[1;31m AliasName: \033[0m {}, \033[1;32mMachineId: \033[0m {}, \033[1;33m AlertInfo: \033[0m {}".format(machineAlias, machineId, alertinfo) ) # break # machine_id_list.append(machineId) #print('Calling restart for machines:', machine_id_list) print('done') if __name__ == '__main__': client = AiClothClient() #client = AiClothClient(base_url=AiClothClient.DEV_SERVER_BASE_URL, cookie_path='dev-cookie.txt') client.interactive_login() #alertkeywords is camera\cpu\mem\flaw_checker\frequency alertkeywords = sys.argv[1] checkMachinesAndAlertInfo(client, alertkeywords)
elif self.status == self.STARTING_SERVICE: # check serive is active current_service_status = info['FlawCheckerStatusString'] if current_service_status == "active": self.logger.info('Cool! Service is started.') self.status = self.STATUS_JUST_STARTED continue else: self.logger.info( 'The service is not started yet, current status: {}'. format(current_service_status)) continue if __name__ == '__main__': client = AiClothClient(base_url=AiClothClient.DEV_SERVER_BASE_URL, cookie_path='dev-cookie.txt') client.interactive_login() pushers = [] # The deb must be uploaded to server #deb_name = 'detection-machine-daemon-20190403_173250-1c7c490d-0.3.9-daemon-mk3.deb' deb_name = 'flaw_checker-0.9.16-net-camera-MK3-0-g3429257-20190409_040915.deb' target_version = '0.9.16-net-camera-MK3-0-g3429257-20190409_040915.deb' #deb_name = 'flaw_checker-0.9.17-net-camera-MK3-0-g0ddc32d-20190409_084431.deb' #target_version = '0.9.17-net-camera-MK3-0-g0ddc32d-20190409_084431.deb' # deb_name = 'detection-machine-daemon-20190407_145747-f3544586-0.3.10-daemon-mk3.deb' # target_version = '0.3.10-daemon-mk3-20190407_145747-f3544586' # MK3测试机 for machineId in ['0C-9D-92-CA-EC-8C']: #pusher = DebAutoPusher(client, machineId, DebAutoPusher.VERSION_KEY_DAEMON, target_version, deb_name, True)
from AiClothClient import AiClothClient, MachineInfo import json if __name__ == '__main__': # client = AiClothClient(base_url='http://localhost:8081') client = AiClothClient() client.interactive_login() # print("Machine Alias:", client.get_machine_alias()) for m in client.get_machine_list()['machines']: m = MachineInfo(m) print(m.getMachineId(), m.getDisplayName()) print(m.getTags()) print(m.keys()) print('-' * 30) # test_machine_id = '0C-9D-92-CA-EC-8C' # 60 ceshiji # response = client.get_config_yaml(test_machine_id) # # note that response['Content'] is still a string object in json format, please call json.loads(response['Content']) to pharse as an object # print("config.yaml:", response['Content']) # content = json.loads(response['Content']) # new_content = json.dumps(content) # client.upload_config_yaml(test_machine_id, new_content) print('done')