def group_bind_template_get(): tpl_id = request.args.get('tpl_id', '').strip() grp_id = request.args.get('grp_id', '').strip() if not tpl_id: return jsonify(msg="tpl id is blank") if not grp_id: return jsonify(msg="grp id is blank") GrpTpl.bind(grp_id, tpl_id, g.user_name) return jsonify(msg='')
def template_unbind_group_get(): tpl_id = request.args.get('tpl_id', '') grp_id = request.args.get('grp_id', '') if not tpl_id: return jsonify(msg="tpl_id is blank") if not grp_id: return jsonify(msg="grp_id is blank") GrpTpl.unbind(grp_id, tpl_id) return jsonify(msg='')
def template_bind_node_post(): node = request.form['node'].strip() tpl_id = request.form['tpl_id'].strip() if not node: return jsonify(msg='node is blank') if not tpl_id: return jsonify(msg='tpl id is blank') hg = HostGroup.read('grp_name=%s', [node]) if not hg: return jsonify(msg='no such node') GrpTpl.bind(hg.id, tpl_id, g.user_name) return jsonify(msg="")
def template_unbind_grp_name_get(): tpl_id = request.args.get('tpl_id', '') if not tpl_id: return jsonify(msg="tpl_id is blank") grp_name = request.args.get('grp_name', '') if not grp_name: return jsonify(msg='grp_name is blank') hg = HostGroup.read('grp_name=%s', [grp_name]) if not hg: return jsonify(msg='no such host group') GrpTpl.unbind(hg.id, tpl_id) return jsonify(msg='')
def template_unbind_group_get(): tpl_id = request.args.get('tpl_id', '') grp_id = request.args.get('grp_id', '') data = {'templateId': tpl_id, 'hostgroupId': grp_id} alarmAdUrl = config.JSONCFG['shortcut'][ 'falconUIC'] + "/api/v1/alarmadjust/whentempleteunbind" if not tpl_id: return jsonify(msg="tpl_id is blank") if not grp_id: return jsonify(msg="grp_id is blank") GrpTpl.unbind(grp_id, tpl_id) respCode = post2FeUpdateEventCase(alarmAdUrl, data) if respCode != 200: log.error(alarmAdUrl + " got " + str(respCode) + " with " + str(data)) return jsonify(msg='')
def template_delete_get(tpl_id): tpl_id = int(tpl_id) t = Template.get(tpl_id) if not t: return jsonify(msg='no such template') if not t.writable(g.user_name): return jsonify(msg='no permission') Template.delete_one(tpl_id) action_id = t.action_id if action_id: Action.delete_one(action_id) Strategy.delete('tpl_id = %s', [tpl_id]) GrpTpl.unbind_tpl(tpl_id) return jsonify(msg='')
def group_templates_get(grp_id): grp_id = int(grp_id) grp = HostGroup.read(where='id = %s', params=[grp_id]) if not grp: return jsonify(msg='no such group') ts = GrpTpl.tpl_list(grp_id) return render_template('group/templates.html', group=grp, ts=ts, uic_address=UIC_ADDRESS['external'])
def template_binds_get(tpl_id): g.menu = 'templates' tpl_id = int(tpl_id) t = Template.get(tpl_id) if not t: return jsonify(msg='no such template') groups = GrpTpl.grp_list(tpl_id) return render_template('template/groups.html', data={ "gs": groups, "tpl": t, "uic_address": UIC_ADDRESS['external'], })
def host_templates_get(host_id): host_id = int(host_id) h = Host.read('id = %s', params=[host_id]) if not h: return jsonify(msg='no such host') group_ids = GroupHost.group_ids(h.id) templates = GrpTpl.tpl_set(group_ids) for v in templates: v.parent = Template.get(v.parent_id) return render_template('host/templates.html', config=config, **locals())
def host_templates_get(host_id): host_id = int(host_id) h = Host.read('id = %s', params=[host_id]) if not h: return jsonify(msg='no such host') group_ids = GroupHost.group_ids(h.id) templates = GrpTpl.tpl_set(group_ids) for v in templates: v.parent = Template.get(v.parent_id) return render_template('host/templates.html', **locals())
def template_delete_get(tpl_id): tpl_id = int(tpl_id) t = Template.get(tpl_id) data = {'templateId': tpl_id} alarmAdUrl = config.JSONCFG['shortcut'][ 'falconUIC'] + "/api/v1/alarmadjust/whentempletedeleted" if not t: return jsonify(msg='no such template') if not t.writable(g.user_name): return jsonify(msg='no permission') Template.delete_one(tpl_id) action_id = t.action_id if action_id: Action.delete_one(action_id) Strategy.delete('tpl_id = %s', [tpl_id]) GrpTpl.unbind_tpl(tpl_id) respCode = post2FeUpdateEventCase(alarmAdUrl, data) if respCode != 200: log.error(alarmAdUrl + " got " + str(respCode) + " with " + str(data)) return jsonify(msg='')
def host_templates_get(host_id, host_name): if not os.path.exists( str(EXTERNAL_NODES) ): host_id = int(host_id) h = Host.read('id = %s', params=[host_id]) if not h: return jsonify(msg='no such host') group_ids = GroupHost.group_ids(h.id) else: (status, output) = commands.getstatusoutput(EXTERNAL_NODES + " GetHostGroupByHost " + host_id ) group_ids = [] if status == 0: decodejson = json.loads( output ) gname = "1" for i in decodejson: gname = gname + ",'" + decodejson[i] + "'" groupMsg = HostGroup.select(cols="id,grp_name", where="grp_name in (%s)" % gname) for m in groupMsg: group_ids.append( m[0] ) templates = GrpTpl.tpl_set(group_ids) for v in templates: v.parent = Template.get(v.parent_id) return render_template('host/templates.html', **locals())