def resource_sync_host_to_zabbix(): if request.method == "POST": params = request.form.to_dict() hostids = params["hostids"].split(",") servers = db.session.query(Server).filter(Server.id.in_(hostids)).all() data = {} zb = Zabbix() flag = True for server in servers: print "*" * 40 ret = zb.create_zb_host(server.hostname, server.inner_ip, params["groupid"]) print server.hostname, server.inner_ip, params["groupid"] print "*" * 30 if isinstance(ret, dict) and ret.get("hostids", None): data[server.hostname] = True else: flag = False data[server.hostname] = ret rsync_zabbix_to_zbhost() rsync_server_to_zbhost() if flag: return "1" else: return json.dumps(data) return "500"
def resurce_sync_host_to_zabbix(): """<FRESHLY_INSERTED>""" if request.method == "POST": params = request.form.to_dict() # {'hostid': u'1,2', 'groupid': u'2'} hostids = params['hostids'].split(',') servers = db.session.query(Server).filter(Server.id.in_(hostids)).all() data = {} zb = Zabbix() flag = True for server in servers: ret = zb.create_zb_host(server.hostname, server.inner_ip, params['groupid']) # {u'hostids': [u'10108']} if isinstance(ret, dict) and ret.get("hostids", None): data[server.hostname] = True else: flag = False data[server.hostname] = ret # 同步到缓存表 rsync_zabbix_to_zbhost() rsync_server_to_zbhost() if flag: return "1" else: return json.dumps(data) return "500"
def monitor_unlink_zabbix_template(): if request.method == "POST": params = request.form.to_dict() zb = Zabbix() ret = zb.unlink_template(params["hostid"], params["templateid"]) if ret: return "1" else: return ret
def monitor_unlink_template(): if request.method == "POST": params = request.form.to_dict() zb = Zabbix() ret = zb.unlink_template(params["hostid"], params['templateid']) if ret: return "1" else: return ret
def monitor_unlink_zabbix_template(): if request.method == "POST": params = request.form.to_dict() # print params # {'hostid': u'10113', 'templateid': u'10115'} zb = Zabbix() ret = zb.unlink_template(params['hostid'], params['templateid']) if ret: return "1" else: return ret
def monitor_zabbix(): zb = Zabbix() templates = zb.zb.template.get(output=["templateid", "name"]) templates_data = [] for temp in templates: templates_data.append({"label": temp["name"], "value": temp["templateid"]}) tv = Treeview() treeview = tv.get() return render_template("monitor/monitor_zabbix.html", treeview = json.dumps(treeview), templates = json.dumps(templates_data))
def resource_sync_hosts_to_zabbix(): if request.method == "POST": params = request.form.to_dict() hostids = params['hostids'].split(',') servers = db.session.query(Server).filter(Server.id.in_(hostids)).all() data = {} zb = Zabbix() flag = True for server in servers: ret = zb.create_zb_host(server.hostname, server.inner_ip, params['groupid']) if isinstance(ret, dict) and ret.get("hostids", None): data[server.hostname] = True else: flag = False data[server.hostname] = ret rsync_zabbix_to_zbhost() rsync_server_to_zbhost() if flag: return "1" else: return json.dumps(data) return "500"
def monitor_zabbix(): zb = Zabbix() templates = zb.zb.template.get(output=["templateid", "name"]) # [{u'name': u'Template OS Linux', u'templateid': u'10001'},.......] #print templates templates_data = [] for temp in templates: templates_data.append({ "label": temp['name'], "value": temp['templateid'] }) tv = Treeview() treeview = tv.get() #[{'value': u'10001', 'label': u'Template OS Linux'},.......] #print templates_data #[{'text': u'ms', 'nodes': [{'text': u'app', 'pid': 1L, 'type': 'product', 'id': 3L}, {'text': u'web', 'pid': 1L, 'type': 'product', 'id': 2L}], 'type': 'service', 'id': 1L}] #print treeview return render_template("monitor/monitor_zabbix.html", treeview=json.dumps(treeview), templates=json.dumps(templates_data), show_zabbix=True, show_monitor=True)
def monitor_get_zabbix_host_groups(): zb = Zabbix() data = zb.get_hostgroup() return json.dumps(data)
def monitor_get_zabbix_host_groups(): zb = Zabbix() data = zb.get_hostgroup() return json.dumps(data)