def host_unbind_get(): host_id = request.args.get('host_id', '').strip() if not host_id: return jsonify(msg='host_id is blank') group_id = request.args.get('group_id', '').strip() if not group_id: return jsonify(msg='group_id is blank') GroupHost.unbind(int(group_id), host_id) return jsonify(msg='')
def host_remove_post(): group_id = int(request.form['grp_id'].strip()) host_ids = request.form['host_ids'].strip() alarmAdUrl = config.JSONCFG['shortcut']['falconUIC'] + "/api/v1/alarmadjust/whenendpointunbind" GroupHost.unbind(group_id, host_ids) for host_id in host_ids.split(","): data = {'hostgroupId': group_id, 'hostId': host_id} respCode = post2FeUpdateEventCase(alarmAdUrl, data) if respCode != 200: log.error(alarmAdUrl + " got " + str(respCode) + " with " + str(data)) return jsonify(msg='delete host is failed , please try again!') return jsonify(msg='')
def host_remove_post(): group_id = int(request.form['grp_id'].strip()) host_ids = request.form['host_ids'].strip() alarmAdUrl = config.JSONCFG['shortcut'][ 'falconUIC'] + "/api/v1/alarmadjust/whenendpointunbind" GroupHost.unbind(group_id, host_ids) for host_id in host_ids.split(","): data = {'hostgroupId': group_id, 'hostId': host_id} respCode = post2FeUpdateEventCase(alarmAdUrl, data) if respCode != 200: log.error(alarmAdUrl + " got " + str(respCode) + " with " + str(data)) return jsonify(msg='delete host is failed , please try again!') return jsonify(msg='')
def host_unbind_get(): host_id = request.args.get('host_id', '').strip() data = {'hostgroupId': group_id, 'hostId': host_id} alarmAdUrl = config.JSONCFG['shortcut']['falconUIC'] + "/api/v1/alarmadjust/whenendpointunbind" if not host_id: return jsonify(msg='host_id is blank') group_id = request.args.get('group_id', '').strip() if not group_id: return jsonify(msg='group_id is blank') GroupHost.unbind(int(group_id), host_id) respCode = post2FeUpdateEventCase(alarmAdUrl, data) if respCode != 200: log.error(alarmAdUrl + " got " + str(respCode) + " with " + str(data)) return jsonify(msg='')
def host_unbind_get(): host_id = request.args.get('host_id', '').strip() data = {'hostgroupId': group_id, 'hostId': host_id} alarmAdUrl = config.JSONCFG['shortcut'][ 'falconUIC'] + "/api/v1/alarmadjust/whenendpointunbind" if not host_id: return jsonify(msg='host_id is blank') group_id = request.args.get('group_id', '').strip() if not group_id: return jsonify(msg='group_id is blank') GroupHost.unbind(int(group_id), host_id) respCode = post2FeUpdateEventCase(alarmAdUrl, data) if respCode != 200: log.error(alarmAdUrl + " got " + str(respCode) + " with " + str(data)) return jsonify(msg='')
def api_marathon_health(): marathon_stats = request.get_json() if marathon_stats["eventType"] == "deployment_success": action_type = marathon_stats["plan"]["steps"][-1]["actions"][-1]["type"] app = marathon_stats["plan"]["steps"][-1]["actions"][-1]["app"].lstrip("/") if action_type == "StopApplication": grp_id = HostGroup.query_grp_id(app) if grp_id > 0: group_service.delete_group(grp_id) else: grp_id = HostGroup.create(app,"root",1) if grp_id < 0: grp_id = HostGroup.query_grp_id(app) if grp_id < 0: return 'grp_name no exist' import requests,json r = requests.get(MARATHON_ADDRESS+"/v2/apps/"+app) app_info = json.loads(r.text) marathon_hosts = [] for i in app_info["app"]["tasks"]: marathon_hosts.append(i["host"]) vs,_ = Host.query(1, 10000000, '', '0', grp_id) of_names = [v.hostname for v in vs] of_names_set = set(of_names) marathon_hosts_set = set(marathon_hosts) delete_hosts = list(of_names_set - marathon_hosts_set) add_hosts = list(marathon_hosts_set - of_names_set) for h in add_hosts: msg = GroupHost.bind(grp_id,h) of_ids = [int(v.id) for v in vs if v.hostname in delete_hosts] if len(delete_hosts)>0: ids = ",".join('%s' % id for id in of_ids) msg = GroupHost.unbind(int(grp_id[0]),ids) return 'ok'
def host_remove_post(): group_id = int(request.form['grp_id'].strip()) host_ids = request.form['host_ids'].strip() GroupHost.unbind(group_id, host_ids) return jsonify(msg='')