| @@ -4,6 +4,7 @@ import ( | |||||
| "bytes" | "bytes" | ||||
| "encoding/base64" | "encoding/base64" | ||||
| "encoding/json" | "encoding/json" | ||||
| "fmt" | |||||
| "io/ioutil" | "io/ioutil" | ||||
| "net/http" | "net/http" | ||||
| @@ -113,13 +114,23 @@ func GetResultFromElk(resultInfo ResultInfo, jsonStr []byte) (loaded int, totalV | |||||
| client := &http.Client{} | client := &http.Client{} | ||||
| resp, err := client.Do(req) | resp, err := client.Do(req) | ||||
| if err != nil { | if err != nil { | ||||
| panic(err) | |||||
| // panic(err) | |||||
| return 0, 0, err | |||||
| } | } | ||||
| defer resp.Body.Close() | defer resp.Body.Close() | ||||
| body, _ := ioutil.ReadAll(resp.Body) | |||||
| errs := json.Unmarshal([]byte(string(body)), &resultInfo) | |||||
| log.Info("Get resultJson failed", errs) | |||||
| if resp.StatusCode != 200 { | |||||
| log.Error("ConnectToElk failed:%s", resp.Status) | |||||
| return 0, 0, fmt.Errorf("ConnectToElk failed:%s", resp.Status) | |||||
| } | |||||
| body, err := ioutil.ReadAll(resp.Body) | |||||
| if err != nil { | |||||
| return 0, 0, err | |||||
| } | |||||
| err = json.Unmarshal([]byte(string(body)), &resultInfo) | |||||
| if err != nil { | |||||
| log.Info("Get resultJson failed", err) | |||||
| return 0, 0, err | |||||
| } | |||||
| return resultInfo.Result.Loaded, resultInfo.Result.RawResponse.Hits.Total, err | return resultInfo.Result.Loaded, resultInfo.Result.RawResponse.Hits.Total, err | ||||
| } | } | ||||
| @@ -138,6 +149,7 @@ func ProjectViewInit(User string, Project string, Gte string, Lte string) (proje | |||||
| var timeRange Range | var timeRange Range | ||||
| timeRange.Timestamptest.Gte = Gte | timeRange.Timestamptest.Gte = Gte | ||||
| timeRange.Timestamptest.Lte = Lte | timeRange.Timestamptest.Lte = Lte | ||||
| timeRange.Timestamptest.Format = "strict_date_optional_time" | |||||
| inputStruct.Batch[0].Request.Params.Body.Query.BoolIn.Filter[0].Range = &timeRange | inputStruct.Batch[0].Request.Params.Body.Query.BoolIn.Filter[0].Range = &timeRange | ||||
| //限定用户 | //限定用户 | ||||
| var userName FilterMatchPhrase | var userName FilterMatchPhrase | ||||
| @@ -211,6 +223,7 @@ func ViewInfo(viewInfo InputInfo) (totalView int, err error) { | |||||
| jsons, errs := json.Marshal(viewInfo) | jsons, errs := json.Marshal(viewInfo) | ||||
| if errs != nil { | if errs != nil { | ||||
| log.Info("errs:", errs) | log.Info("errs:", errs) | ||||
| return 0, err | |||||
| } | } | ||||
| var jsonStr = []byte(jsons) | var jsonStr = []byte(jsons) | ||||
| var resultInfo ResultInfo | var resultInfo ResultInfo | ||||
| @@ -221,7 +234,6 @@ func ViewInfo(viewInfo InputInfo) (totalView int, err error) { | |||||
| if loaded == 0 { | if loaded == 0 { | ||||
| loaded_next, totalView, err := GetResultFromElk(resultInfo, jsonStr) | loaded_next, totalView, err := GetResultFromElk(resultInfo, jsonStr) | ||||
| time++ | time++ | ||||
| log.Info("time:", time) | |||||
| if loaded_next != 0 && time < 100 { | if loaded_next != 0 && time < 100 { | ||||
| return totalView, err | return totalView, err | ||||
| } | } | ||||