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 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"