| | |
| | | type EsClusterInfo struct { |
| | | Ip string `json:"ip"` |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 比对数据查询 |
| | | // @Description 比对数据查询 |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "参数有误") |
| | | return |
| | | } |
| | | if searchBody.CompareNum !="" { |
| | | if searchBody.CompareNum != "" { |
| | | //二次搜索,不需要再比对了 |
| | | co := service.GetCompResultByNum(searchBody.CompareNum) |
| | | if co != nil { |
| | | //二次搜索和排序 |
| | | twiceM := GetCompareDataTwice(co,searchBody) |
| | | util.ResponseFormat(c,code.Success,twiceM) |
| | | twiceM := GetCompareDataTwice(co, searchBody) |
| | | util.ResponseFormat(c, code.Success, twiceM) |
| | | return |
| | | } else { |
| | | m :=make(map[string]interface{},0) |
| | | m := make(map[string]interface{}, 0) |
| | | m["compareNum"] = searchBody.CompareNum |
| | | m["total"] = 0 |
| | | m["totalList"] = []CompareResult{} |
| | | util.ResponseFormat(c,code.CompareResultGone,m) |
| | | util.ResponseFormat(c, code.CompareResultGone, m) |
| | | return |
| | | } |
| | | } |
| | | m :=make(map[string]interface{},0) |
| | | m := make(map[string]interface{}, 0) |
| | | m["compareNum"] = searchBody.CompareNum |
| | | m["total"] = 0 |
| | | m["totalList"] = []CompareResult{} |
| | | util.ResponseFormat(c,code.CompareResultGone,m) |
| | | util.ResponseFormat(c, code.CompareResultGone, m) |
| | | } |
| | | |
| | | func searchEsData(searchBody models.EsSearch) map[string]interface{} { |
| | |
| | | //使用es底层机制处理分页 |
| | | //请求头 |
| | | localConf, err2 := cache.GetServerInfo() |
| | | if err2 !=nil || localConf.AlarmIp == "" || localConf.ServerId == "" { |
| | | if err2 != nil || localConf.AlarmIp == "" || localConf.ServerId == "" { |
| | | logger.Debug("localConfig is wrong!!!") |
| | | return nil |
| | | } |
| | |
| | | nodeInfo := make(map[string]interface{}) |
| | | context := strings.Fields(infos[i]) |
| | | nodeIp := context[0] |
| | | Type := context[8] |
| | | Type := context[7] |
| | | var nodeType string |
| | | if Type == "*" { |
| | | if Type == "mdi" { |
| | | nodeType = "主节点" |
| | | } |
| | | if Type == "-" { |
| | | if Type == "di" { |
| | | nodeType = "从节点" |
| | | } |
| | | nodeInfo["ip"] = nodeIp |
| | |
| | | return msg, err |
| | | } |
| | | |
| | | //修改elasticsearch.yml映射文件 |
| | | // @Security ApiKeyAuth |
| | | // @Summary 修改es集群Ip |
| | | // @Description 修改es集群Ip |
| | | // @Accept json |
| | | // @Produce json |
| | | // @Tags es |
| | | // @Param obj body controllers.Hosts true "修改es集群Ip参数" |
| | | // @Success 200 {string} json "{"code":200, msg:"", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"", success:false}" |
| | | // @Router /data/api-v/es/updateEsHosts [POST] |
| | | func (em *EsManagementController) UpdateEsHosts(c *gin.Context) { |
| | | var hosts Hosts |
| | | c.BindJSON(&hosts) |
| | | nodeInfos, err := getEsClusterInfors(hosts.OldIp) |
| | | var nodeType string |
| | | if err != nil { |
| | | logger.Fatal(err) |
| | | } |
| | | newMasterHosts := make([]string, 0) |
| | | allHosts := make([]string, 0) |
| | | for _, val := range nodeInfos { |
| | | ip := val["ip"].(string) |
| | | tmpType := val["nodeType"].(string) |
| | | if ip == hosts.OldIp { |
| | | nodeType = tmpType |
| | | } |
| | | if tmpType == "master" { |
| | | newMasterHosts = append(newMasterHosts, ip) |
| | | } |
| | | if ip != hosts.OldIp { |
| | | allHosts = append(allHosts, ip) |
| | | } |
| | | } |
| | | |
| | | if nodeType == "master" { |
| | | str1 := "sed -ie 's/network.host: " + hosts.OldIp + "/network.host: " + hosts.NewIp + "/g' /opt/elasticsearch/config/elasticsearch.yml" |
| | | runScript(str1) |
| | | for i, host := range newMasterHosts { |
| | | if host == hosts.OldIp { |
| | | newMasterHosts[i] = hosts.NewIp |
| | | } |
| | | } |
| | | for i, val := range newMasterHosts { |
| | | val = "\\\"" + val + ":9300\\\"" |
| | | newMasterHosts[i] = val |
| | | } |
| | | newUnicastHost := strings.Replace(strings.Trim(fmt.Sprint(newMasterHosts), ""), " ", ",", -1) |
| | | |
| | | tmpStr := "cat /opt/elasticsearch/config/elasticsearch.yml | grep discovery.zen.ping.unicast.hosts:" |
| | | rs := runScript(tmpStr) |
| | | ts := strings.Split(rs, "\n")[0] |
| | | ots := strings.Split(ts, " ")[1] |
| | | outs := strings.Replace(ots, "\"", "\\\"", -1) |
| | | oldUnicastHost := "\\" + strings.Replace(outs, "]", "\\]", -1) |
| | | str2 := "sed -ie 's/discovery.zen.ping.unicast.hosts: " + oldUnicastHost + "/discovery.zen.ping.unicast.hosts: " + newUnicastHost + "/g' /opt/elasticsearch/config/elasticsearch.yml" |
| | | runScript(str2) |
| | | for _, host := range allHosts { |
| | | str3 := "sshpass -p \"123\" ssh basic@" + host + " \"cd /opt/elasticsearch/config ; " + str2 + " ; cat elasticsearch.yml\"" |
| | | runScript(str3) |
| | | } |
| | | } else { |
| | | str1 := "sed -ie 's/network.host: " + hosts.OldIp + "/network.host: " + hosts.NewIp + "/g' /opt/elasticsearch/config/elasticsearch.yml" |
| | | runScript(str1) |
| | | } |
| | | } |
| | | |
| | | type Hosts struct { |
| | | NewIp string `json:newIp` |
| | | OldIp string `json:oldIp` |
| | | } |
| | | |
| | | func forwardCommand() { |
| | | |
| | | } |
| | | |
| | | //func AddEsCluster(hosts []string) (string){ |
| | | // msg := "加入失败" |
| | | // for i,val := range hosts{ |