def api_group_hosts_json(grp_name): group = HostGroup.read(where='id = %s', params=[grp_name]) if not group: group = HostGroup.read(where='grp_name = %s', params=[grp_name]) if not group: return jsonify(msg='no such group %s' % grp_name) vs, _ = Host.query(1, 10000000, '', '0', group.id) names = [v.hostname for v in vs] return jsonify(msg='', data=names)
def api_group_hosts_json(grp_name): group = HostGroup.read(where='id = %s', params=[grp_name]) if not group: group = HostGroup.read(where='grp_name = %s', params=[grp_name]) if not group: return jsonify(msg='no such group %s' % grp_name) vs, _ = Host.query(1, 10000000, '', '0', group.id) names = [v.hostname for v in vs] return jsonify(msg='', data=names)
def group_hosts_list(group_id): g.xbox = request.args.get('xbox', '') group_id = int(group_id) group = HostGroup.read(where='id = %s', params=[group_id]) if not group: return jsonify(msg='no such group %s' % group_id) page = int(request.args.get('p', 1)) limit = int(request.args.get('limit', 10)) query = request.args.get('q', '') maintaining = request.args.get('maintaining', '0') vs, total = Host.query(page, limit, query, maintaining, group_id) return render_template( 'portal/host/index.html', data={ 'vs': vs, 'total': total, 'query': query, 'limit': limit, 'page': page, 'maintaining': maintaining, 'group': group, } )
def cluster_creator_get(group_id): group_id = int(group_id) group = HostGroup.read(where='id = %s', params=[group_id]) if not group: return jsonify(msg='no such group %s' % group_id) return render_template('portal/cluster/creator.html', **locals())
def variable_creator_post(group_id): group_id = int(group_id) group = HostGroup.read(where='id = %s', params=[group_id]) if not group: return jsonify(msg='no such group %s' % group_id) name = request.form['name'].strip() content = request.form['content'].strip() note = request.form['note'].strip() if Variable.exists('grp_id=%s and name=%s', [group_id, name]): return jsonify(msg='%s/%s is already existent' % (group['name'], name)) last_id = Variable.insert({ 'grp_id': group_id, 'name': name, 'content': content, 'note': note, 'create_user': g.user.name, }) if last_id > 0: return jsonify(msg='') else: return jsonify(msg='occur error')
def cluster_creator_get(group_id): group_id = int(group_id) group = HostGroup.read(where='id = %s', params=[group_id]) if not group: return jsonify(msg='no such group %s' % group_id) return render_template('portal/cluster/creator.html', **locals())
def host_add_post(): group_id = request.form['group_id'] if not group_id: return jsonify(msg='no group_id given') group_id = int(group_id) group = HostGroup.read('id = %s', [group_id]) if not group: return jsonify(msg='no such group') hosts = request.form['hosts'].strip() if not hosts: return jsonify(msg='hosts is blank') host_arr = hosts.splitlines() safe_host_arr = [h.strip() for h in host_arr if h] if not safe_host_arr: return jsonify(msg='hosts is blank') success = [] failure = [] for h in safe_host_arr: msg = GroupHost.bind(group_id, h) if not msg: success.append('%s<br>' % h) else: failure.append('%s %s<br>' % (h, msg)) data = '<div class="alert alert-danger" role="alert">failure:<hr>' + ''.join( failure) + '</div><div class="alert alert-success" role="alert">success:<hr>' + ''.join(success) + '</div>' return jsonify(msg='', data=data)
def cluster_list_get(group_id): group_id = int(group_id) group = HostGroup.read(where='id = %s', params=[group_id]) if not group: return jsonify(msg='no such group %s' % group_id) clusters = Cluster.select_vs(where='grp_id = %s', params=[group_id]) return render_template('portal/cluster/list.html', **locals())
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('portal/group/templates.html', group=grp, ts=ts)
def plugin_bind_post(): group_id = int(request.form['group_id'].strip()) plugin_dir = request.form['plugin_dir'].strip() group = HostGroup.read(where='id = %s', params=[group_id]) if not group: return jsonify(msg='no such group %s' % group_id) PluginDir.insert({'grp_id': group_id, 'dir': plugin_dir, 'create_user': g.user.name}) 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('portal/group/templates.html', group=grp, ts=ts)
def host_groups_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) groups = [HostGroup.read('id = %s', [group_id]) for group_id in group_ids] return render_template('portal/host/groups.html', groups=groups, host=h)
def cluster_list_get(group_id): group_id = int(group_id) group = HostGroup.read(where='id = %s', params=[group_id]) if not group: return jsonify(msg='no such group %s' % group_id) clusters = Cluster.select_vs(where='grp_id = %s', params=[group_id]) return render_template('portal/cluster/list.html', **locals())
def plugin_list_get(group_id): group_id = int(group_id) group = HostGroup.read(where='id = %s', params=[group_id]) if not group: return jsonify(msg='no such group %s' % group_id) plugins = PluginDir.select_vs(where='grp_id = %s', params=[group_id]) return render_template('portal/plugin/list.html', group=group, plugins=plugins)
def group_delete_get(group_id): group_id = int(group_id) group = HostGroup.read(where='id = %s', params=[group_id]) if not group: return jsonify(msg='no such group') if not group.writable(g.user): return jsonify(msg='no permission') return jsonify(msg=group_service.delete_group(group_id))
def group_delete_get(group_id): group_id = int(group_id) group = HostGroup.read(where='id = %s', params=[group_id]) if not group: return jsonify(msg='no such group') if not group.writable(g.user): return jsonify(msg='no permission') return jsonify(msg=group_service.delete_group(group_id))
def plugin_list_get(group_id): group_id = int(group_id) group = HostGroup.read(where='id = %s', params=[group_id]) if not group: return jsonify(msg='no such group %s' % group_id) plugins = PluginDir.select_vs(where='grp_id = %s', params=[group_id]) return render_template('portal/plugin/list.html', group=group, plugins=plugins)
def host_add_get(): group_id = request.args.get('group_id', '') if not group_id: return jsonify(msg='no group_id given') group_id = int(group_id) group = HostGroup.read('id = %s', [group_id]) if not group: return jsonify(msg='no such group') return render_template('portal/host/add.html', group=group)
def group_hosts_export(group_id): group_id = int(group_id) group = HostGroup.read(where='id = %s', params=[group_id]) if not group: return jsonify(msg='no such group %s' % group_id) vs, _ = Host.query(1, 10000000, '', '0', group_id) names = [v.hostname for v in vs] response = make_response('\n'.join(names)) response.headers["content-type"] = "text/plain" return response
def plugin_bind_post(): group_id = int(request.form['group_id'].strip()) plugin_dir = request.form['plugin_dir'].strip() group = HostGroup.read(where='id = %s', params=[group_id]) if not group: return jsonify(msg='no such group %s' % group_id) PluginDir.insert({ 'grp_id': group_id, 'dir': plugin_dir, 'create_user': g.user.name }) return jsonify(msg='')
def group_update_post(group_id): group_id = int(group_id) new_name = request.form['new_name'].strip() if not new_name: return jsonify(msg='new name is blank') group = HostGroup.read(where='id = %s', params=[group_id]) if not group: return jsonify(msg='no such group') if not group.writable(g.user): return jsonify(msg='no permission') HostGroup.update_dict({'grp_name': new_name}, 'id=%s', [group_id]) return jsonify(msg='')
def group_update_post(group_id): group_id = int(group_id) new_name = request.form['new_name'].strip() if not new_name: return jsonify(msg='new name is blank') group = HostGroup.read(where='id = %s', params=[group_id]) if not group: return jsonify(msg='no such group') if not group.writable(g.user): return jsonify(msg='no permission') HostGroup.update_dict({'grp_name': new_name}, 'id=%s', [group_id]) 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_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_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 cluster_node_post(group_id): group_id = int(group_id) group = HostGroup.read(where='id = %s', params=[group_id]) if not group: return jsonify(msg='no such group %s' % group_id) numerator = request.form['numerator'].strip() denominator = request.form['denominator'].strip() endpoint = request.form['endpoint'].strip() metric = request.form['metric'].strip() tags = request.form['tags'].strip() ds_type = 'GAUGE' step = request.form['step'].strip() msg = required_chk({ 'numerator': numerator, 'denominator': denominator, 'endpoint': endpoint, 'metric': metric, 'ds_type': ds_type, 'step': step, }) if msg: return jsonify(msg=msg) if Cluster.exists('endpoint=%s and metric=%s and tags=%s', [endpoint, metric, tags]): return jsonify(msg='%s/%s/%s is already existent' % (endpoint, metric, tags)) last_id = Cluster.insert({ 'grp_id': group_id, 'numerator': numerator, 'denominator': denominator, 'endpoint': endpoint, 'metric': metric, 'tags': tags, 'ds_type': ds_type, 'step': step, 'creator': g.user.name, }) if last_id > 0: return jsonify(msg='') else: return jsonify(msg='occur error')
def cluster_node_post(group_id): group_id = int(group_id) group = HostGroup.read(where='id = %s', params=[group_id]) if not group: return jsonify(msg='no such group %s' % group_id) numerator = request.form['numerator'].strip() denominator = request.form['denominator'].strip() endpoint = request.form['endpoint'].strip() metric = request.form['metric'].strip() tags = request.form['tags'].strip() ds_type = 'GAUGE' step = request.form['step'].strip() msg = required_chk({ 'numerator': numerator, 'denominator': denominator, 'endpoint': endpoint, 'metric': metric, 'ds_type': ds_type, 'step': step, }) if msg: return jsonify(msg=msg) if Cluster.exists('endpoint=%s and metric=%s and tags=%s', [endpoint, metric, tags]): return jsonify(msg='%s/%s/%s is already existent' % (endpoint, metric, tags)) last_id = Cluster.insert({ 'grp_id': group_id, 'numerator': numerator, 'denominator': denominator, 'endpoint': endpoint, 'metric': metric, 'tags': tags, 'ds_type': ds_type, 'step': step, 'creator': g.user.name, }) if last_id > 0: return jsonify(msg='') else: return jsonify(msg='occur error')
def variable_list_get(group_id): group_id = int(group_id) group = HostGroup.read(where='id = %s', params=[group_id]) if not group: return jsonify(msg='no such group %s' % group_id) variables = Variable.select_vs(where='grp_id = %s', params=[group_id]) new_vars = [] for v in variables: new_vars.append({ "name": v.name, "content": v.content, "note": v.note, "create_user": v.create_user }) return render_template('portal/variable/list.html', group=group, variables=new_vars)