From 12dfa9c7f1b700235acdcf45a0f0af5d4566f28e Mon Sep 17 00:00:00 2001 From: Boris Date: Thu, 31 Oct 2024 23:25:22 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D1=81?= =?UTF-8?q?=20=D0=B4=D0=B2=D1=83=D0=BC=D1=8F=20=D0=BA=D0=BB=D0=B0=D1=81?= =?UTF-8?q?=D1=82=D0=B5=D1=80=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/assets/js/app-search.js | 4 +-- modules/router/methods.go | 12 ++++++--- modules/router/router.go | 50 ++++++++++++++++++++++++----------- modules/version/version.go | 2 +- 4 files changed, 46 insertions(+), 22 deletions(-) diff --git a/front/assets/js/app-search.js b/front/assets/js/app-search.js index 30c8f24..65e0841 100644 --- a/front/assets/js/app-search.js +++ b/front/assets/js/app-search.js @@ -42,8 +42,8 @@ $(document).ready(function(){ var str = ""; for(var k in data) { name = data[k].Name; - host = data[k].Host; - $('#clusters').append(new Option(name, host,false,false)); + ctype = data[k].Type; + $('#clusters').append(new Option(name, ctype,false,false)); } } }); diff --git a/modules/router/methods.go b/modules/router/methods.go index 874ec92..93cc6f2 100644 --- a/modules/router/methods.go +++ b/modules/router/methods.go @@ -217,15 +217,21 @@ func (rt *Router) getNodes() ([]singleNode, error) { } -func (rt *Router) getIndexGroups() ([]indexGroup, error) { +func (rt *Router) getIndexGroups(cluster string) ([]indexGroup, error) { var igs, igresp []indexGroup - + var host string re := regexp.MustCompile(`^([\w\d\-_]+)-(\d{4}\.\d{2}\.\d{2}(-\d{2})*)`) // rt.nodes.RLock() // defer rt.nodes.RUnlock() t := time.Now() - response, err := rt.doGet(rt.conf.Snapshot.Host+"_cat/indices/*-"+t.Format("2006.01.02")+"*,-.*/?format=json&h=index", "Search") + if cluster == "Snapshot" { + host = rt.conf.Snapshot.Host + } else if cluster == "Search" { + host = rt.conf.Search.Host + } + + response, err := rt.doGet(host+"_cat/indices/*-"+t.Format("2006.01.02")+"*,-.*/?format=json&h=index", cluster) if err != nil { return nil, err } diff --git a/modules/router/router.go b/modules/router/router.go index ff27e3b..5623f4b 100644 --- a/modules/router/router.go +++ b/modules/router/router.go @@ -133,6 +133,7 @@ type indexGroup struct { type Cluster struct { Name string Host string + Type string } type snapList []struct { @@ -558,9 +559,17 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) { } /* ---- search --- */ + case "get_clusters": + { + var cl []Cluster + cl = append(cl, Cluster{rt.conf.Snapshot.Name, rt.conf.Snapshot.Host, "Snapshot"}) + cl = append(cl, Cluster{rt.conf.Search.Name, rt.conf.Search.Host, "Search"}) + j, _ := json.Marshal(cl) + w.Write(j) + } case "get_index_groups": { - response, err := rt.getIndexGroups() + response, err := rt.getIndexGroups(request.Search.Cluster) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", http.StatusInternalServerError, "\t", err.Error()) @@ -576,10 +585,15 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) { var ( fullm map[string]interface{} m map[string]interface{} + host string ) - + if request.Search.Cluster == "Snapshot" { + host = rt.conf.Snapshot.Host + } else if request.Search.Cluster == "Search" { + host = rt.conf.Search.Host + } flatMap := make(map[string]string) - response, err := rt.doGet(request.Search.Cluster+request.Search.Index+t.Format("2006.01.02")+"/_mapping", "Search") + response, err := rt.doGet(host+request.Search.Index+t.Format("2006.01.02")+"/_mapping", "Search") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", http.StatusInternalServerError, "\t", err.Error()) @@ -605,15 +619,6 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) { w.Write(j) } - case "get_clusters": - { - var cl []Cluster - cl = append(cl, Cluster{rt.conf.Snapshot.Name, rt.conf.Snapshot.Host}) - cl = append(cl, Cluster{rt.conf.Search.Name, rt.conf.Search.Host}) - j, _ := json.Marshal(cl) - w.Write(j) - } - case "search": { var ( @@ -628,7 +633,13 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) { tf string fields string req map[string]interface{} + host string ) + if request.Search.Cluster == "Snapshot" { + host = rt.conf.Snapshot.Host + } else if request.Search.Cluster == "Search" { + host = rt.conf.Search.Host + } ds, _ := time.Parse("2006-01-02 15:04:05 (MST)", request.Search.DateStart+" (MSK)") de, _ := time.Parse("2006-01-02 15:04:05 (MST)", request.Search.DateEnd+" (MSK)") @@ -676,7 +687,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) { if request.Search.Count { _ = json.Unmarshal([]byte("{"+query+"}"), &req) - cresponse, err := rt.doPost(request.Search.Cluster+request.Search.Index+"/_count", req, "Search") + cresponse, err := rt.doPost(host+request.Search.Index+"/_count", req, "Search") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", http.StatusInternalServerError, "\t", err.Error()) @@ -685,7 +696,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) { w.Write(cresponse) } else { _ = json.Unmarshal([]byte(full_query), &req) - sresponse, err := rt.doPost(request.Search.Cluster+request.Search.Index+"/_search", req, "Search") + sresponse, err := rt.doPost(host+request.Search.Index+"/_search", req, "Search") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", http.StatusInternalServerError, "\t", err.Error()) @@ -713,8 +724,15 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) { req map[string]interface{} scrollresponse scrollResponse fields_list []string + host string ) + if request.Search.Cluster == "Snapshot" { + host = rt.conf.Snapshot.Host + } else if request.Search.Cluster == "Search" { + host = rt.conf.Search.Host + } + ds, _ := time.Parse("2006-01-02 15:04:05 (MST)", request.Search.DateStart+" (MSK)") de, _ := time.Parse("2006-01-02 15:04:05 (MST)", request.Search.DateEnd+" (MSK)") @@ -767,7 +785,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) { log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", http.StatusInternalServerError, "\t", err.Error()) return } - sresponse, err := rt.doPost(request.Search.Cluster+request.Search.Index+"/_search?scroll=10m", req, "Search") + sresponse, err := rt.doPost(host+request.Search.Index+"/_search?scroll=10m", req, "Search") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", http.StatusInternalServerError, "\t", err.Error()) @@ -843,7 +861,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) { if scrollresponse.ScrollID != "" { scroll := map[string]interface{}{"scroll": "10m", "scroll_id": scrollresponse.ScrollID} for i := 0; i < rt.conf.Search.FileLimit.Rows/10000; i++ { - sresponse, err := rt.doPost(request.Search.Cluster+"_search/scroll", scroll, "Search") + sresponse, err := rt.doPost(host+"_search/scroll", scroll, "Search") if err != nil { log.Println("Failed to get scroll batch: ", err) return diff --git a/modules/version/version.go b/modules/version/version.go index b8a1740..de7742a 100644 --- a/modules/version/version.go +++ b/modules/version/version.go @@ -13,4 +13,4 @@ package version -var Version = "extractor/v0.2.6" +var Version = "extractor/v0.2.7"