Skip to content

Commit ab575a2

Browse files
committed
bugfix: recreate geoip index on missing
1 parent a240f5a commit ab575a2

File tree

6 files changed

+45
-2
lines changed

6 files changed

+45
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
## Bug Fixes
33
- Enhanced the Log Explorer UI to improve usability by refining the display of Refresh, Save Query, Load Query, and Add Filter actions for a more intuitive user experience..
44

5+
- Recreating geoip opensearch index if missing

correlation/aaa/rules/system

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 58317e8e2665c7fc7609b7756870ae6f5d60f9aa

correlation/system

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 58317e8e2665c7fc7609b7756870ae6f5d60f9aa

installer/cloud.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,13 @@ func Cloud(c *types.Config, update bool) error {
212212
fmt.Println("Initializing User Auditor database [OK]")
213213
}
214214

215-
if utils.GetLock(7, stack.LocksDir) {
215+
indexURL := "http://localhost:9200/.utm-geoip?pretty"
216+
indexExists, err := utils.CheckIndexExists(indexURL)
217+
if err != nil {
218+
return err
219+
}
220+
221+
if !indexExists || utils.GetLock(7, stack.LocksDir) {
216222
fmt.Println("Initializing OpenSearch. This may take a while.")
217223
if err := InitOpenSearch(); err != nil {
218224
return err

installer/master.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,13 @@ func Master(c *types.Config) error {
200200
fmt.Println("Initializing User Auditor database [OK]")
201201
}
202202

203-
if utils.GetLock(7, stack.LocksDir) {
203+
indexURL := "http://localhost:9200/.utm-geoip?pretty"
204+
indexExists, err := utils.CheckIndexExists(indexURL)
205+
if err != nil {
206+
return err
207+
}
208+
209+
if !indexExists || utils.GetLock(7, stack.LocksDir) {
204210
fmt.Println("Initializing OpenSearch. This may take a while.")
205211
if err := InitOpenSearch(); err != nil {
206212
return err

installer/utils/elastic.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package utils
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
)
7+
8+
// CheckIndexExists checks if the given Elasticsearch index exists by sending an HTTP GET
9+
// request to the provided URL. It returns true if the index exists, false otherwise.
10+
func CheckIndexExists(url string) (bool, error) {
11+
resp, err := http.Get(url)
12+
if err != nil {
13+
return false, err
14+
}
15+
defer resp.Body.Close()
16+
17+
switch resp.StatusCode {
18+
case http.StatusOK:
19+
// The index exists.
20+
return true, nil
21+
case http.StatusNotFound:
22+
// The index does not exist.
23+
return false, nil
24+
default:
25+
// For any other status code, return an error.
26+
return false, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
27+
}
28+
}

0 commit comments

Comments
 (0)