Skip to content

Commit

Permalink
Merge pull request #6 from flant/link2kibana
Browse files Browse the repository at this point in the history
Добавил создание index_pattern, сделал возможным отключение проверки …
  • Loading branch information
uzhinskiy authored Mar 2, 2023
2 parents b73f32f + 41bf1f7 commit 8651272
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 13 deletions.
1 change: 1 addition & 0 deletions examples/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ elastic:
password: admin
ssl: false
insecure: true
is_s3: true
# Видим-ли в списке снапшотов системые (.kibana* / .opendistro* )
# значение по умолчанию = false, то-есть не видим
include_system: false
2 changes: 1 addition & 1 deletion front/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ <h5 class="modal-title" id="exampleModalLabel">X-tract indices from snapshot</h5

basket = '<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-folder2-open ' + done + '" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M1 3.5A1.5 1.5 0 0 1 2.5 2h2.764c.958 0 1.76.56 2.311 1.184C7.985 3.648 8.48 4 9 4h4.5A1.5 1.5 0 0 1 15 5.5v.64c.57.265.94.876.856 1.546l-.64 5.124A2.5 2.5 0 0 1 12.733 15H3.266a2.5 2.5 0 0 1-2.481-2.19l-.64-5.124A1.5 1.5 0 0 1 1 6.14V3.5zM2 6h12v-.5a.5.5 0 0 0-.5-.5H9c-.964 0-1.71-.629-2.174-1.154C6.374 3.334 5.82 3 5.264 3H2.5a.5.5 0 0 0-.5.5V6zm-.367 1a.5.5 0 0 0-.496.562l.64 5.124A1.5 1.5 0 0 0 3.266 14h9.468a1.5 1.5 0 0 0 1.489-1.314l.64-5.124A.5.5 0 0 0 14.367 7H1.633z"/></svg>';

str += "<li><a href='https://" + kibana_url + "/' target=_blank>" + basket + "&nbsp;" + k + "</a><span class='float-right'>" + bytesToSize(ts) + "&nbsp;&nbsp;" + del_button+ "</span>";
str += "<li><a href='https://" + kibana_url + "/app/discover#' target=_blank>" + basket + "&nbsp;" + k + "</a><span class='float-right'>" + bytesToSize(ts) + "&nbsp;&nbsp;" + del_button+ "</span>";
str += "<div class='progress' style='height: 3px;'>";
str += "<div class='progress-bar " + pc + "' role='progressbar' style='width: " + prc + "%;' aria-valuenow='" + prc + "' aria-valuemin='0' aria-valuemax='100'></div>";
str += "</div><br></li>";
Expand Down
1 change: 1 addition & 0 deletions modules/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Config struct {
ClientKey string `yaml:"client_key"`
InsecureSkipVerify bool `yaml:"insecure"`
Include bool `yaml:"include_system"`
IsS3 bool `yaml:"is_s3"`
} `yaml:"elastic"`
}

Expand Down
24 changes: 14 additions & 10 deletions modules/router/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,26 +179,30 @@ func (rt *Router) getNodes() ([]singleNode, error) {

}

func (rt *Router) Barrel(array IndicesInSnap) ([]string, []string) {
func (rt *Router) Barrel(ind_array IndicesInSnap, s3 bool) ([]string, []string) {
var (
k int
Sk int
a []string
b []string
)

for name, ind := range array {
for n := range rt.nodes.list {
for m := range ind.Shards {
k = rt.nodes.list[n] / ind.Shards[m]
Sk = Sk + k
for name, ind := range ind_array {
if !s3 {
for n := range rt.nodes.list {
for m := range ind.Shards {
k = rt.nodes.list[n] / ind.Shards[m]
Sk = Sk + k
}
}
}

if Sk > len(ind.Shards) {
a = append(a, name)
if Sk > len(ind.Shards) {
a = append(a, name)
} else {
b = append(b, name)
}
} else {
b = append(b, name)
a = append(a, name)
}
}
return a, b
Expand Down
16 changes: 15 additions & 1 deletion modules/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
}
}

index_list_for_restore, index_list_not_restore := rt.Barrel(indices)
index_list_for_restore, index_list_not_restore := rt.Barrel(indices, rt.conf.Elastic.IsS3)
t := time.Now()
req := map[string]interface{}{
"ignore_unavailable": false,
Expand All @@ -442,6 +442,20 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(msg))
}

ip_req := map[string]interface{}{
"type": "index-pattern",
"index-pattern": map[string]interface{}{
"title": "extracted*",
"timeFieldName": "timestamp"}}

ip_resp, err := rt.doPost(rt.conf.Elastic.Host+".kibana/_doc/index-pattern:123", ip_req)
if err != nil {
msg := fmt.Sprintf(`{"error":"%s"}`, err)
http.Error(w, msg, 500)
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", 500, "\t", err.Error(), "\t", ip_resp)
return
}

msg := fmt.Sprintf(`{"message":"Indices '%v' will be restored", "error":0}`, index_list_for_restore)
w.Write([]byte(msg))

Expand Down
2 changes: 1 addition & 1 deletion modules/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

package version

var Version = "extractor/v0.1.11"
var Version = "extractor/v0.1.12"

0 comments on commit 8651272

Please sign in to comment.