diff --git a/README.md b/README.md index eb61ef7..d0ec507 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Elktail major versions follow ElasticSearch versions. Here's the table indicatin | Elktail | ElasticSearch | | ------------- | ------------- | +| v6.x.x | >= 6.x.x | | v5.x.x | >= 5.x.x | | v1.x.x | 1.x.x, 2.x.x | diff --git a/configuration.go b/configuration.go index 573d8be..006544f 100644 --- a/configuration.go +++ b/configuration.go @@ -5,17 +5,18 @@ */ package main + import ( - "runtime" - "os" "encoding/json" + "github.com/urfave/cli" "io/ioutil" - "github.com/codegangsta/cli" + "os" + "runtime" ) type SearchTarget struct { Url string - TunnelUrl string `json:"-"` + TunnelUrl string `json:"-"` IndexPattern string } @@ -23,22 +24,22 @@ type QueryDefinition struct { Terms []string Format string TimestampField string - AfterDateTime string `json:"-"` - BeforeDateTime string `json:"-"` + AfterDateTime string `json:"-"` + BeforeDateTime string `json:"-"` } type Configuration struct { SearchTarget SearchTarget QueryDefinition QueryDefinition InitialEntries int - ListOnly bool `json:"-"` + ListOnly bool `json:"-"` User string - Password string `json:"-"` - Verbose bool `json:"-"` - MoreVerbose bool `json:"-"` - TraceRequests bool `json:"-"` + Password string `json:"-"` + Verbose bool `json:"-"` + MoreVerbose bool `json:"-"` + TraceRequests bool `json:"-"` SSHTunnelParams string - SaveQuery bool `json:"-"` + SaveQuery bool `json:"-"` } var confDir = ".elktail" @@ -47,8 +48,6 @@ var defaultConfFile = "default.json" //When changing this array, make sure to also make appropriate changes in CopyConfigRelevantSettingsTo var configRelevantFlags = []string{"url", "f", "i", "t", "u", "ssh"} - - func userHomeDir() string { if runtime.GOOS == "windows" { home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH") @@ -95,58 +94,60 @@ func (c *Configuration) CopyNonConfigRelevantSettingsTo(dest *Configuration) { dest.TraceRequests = c.TraceRequests } - - func (c *Configuration) SaveDefault() { - confDirPath := userHomeDir() + string(os.PathSeparator) + confDir; + confDirPath := userHomeDir() + string(os.PathSeparator) + confDir if _, err := os.Stat(confDirPath); os.IsNotExist(err) { //conf directory doesn't exist, let's create it err := os.Mkdir(confDirPath, 0700) - if (err != nil) { + if err != nil { Error.Printf("Failed to create configuration directory %s, %s\n", confDirPath, err) return } } confJson, err := json.MarshalIndent(c, "", " ") - if (err != nil) { + if err != nil { Error.Printf("Failed to marshall configuration to json: %s.\n", err) return } - confFile := confDirPath + string(os.PathSeparator) + defaultConfFile; + confFile := confDirPath + string(os.PathSeparator) + defaultConfFile err = ioutil.WriteFile(confFile, confJson, 0700) - if (err != nil) { + if err != nil { Error.Printf("Failed to save configuration to file %s, %s\n", confFile, err) return } } -func LoadDefault() (conf *Configuration, err error) { - confDirPath := userHomeDir() + string(os.PathSeparator) + confDir; +func LoadDefault() (conf *Configuration, err error) { + confDirPath := userHomeDir() + string(os.PathSeparator) + confDir if _, err := os.Stat(confDirPath); os.IsNotExist(err) { //conf directory doesn't exist, let's create it err := os.Mkdir(confDirPath, 0700) - if (err != nil) { + if err != nil { return nil, err } } - confFile := confDirPath + string(os.PathSeparator) + defaultConfFile; + confFile := confDirPath + string(os.PathSeparator) + defaultConfFile var config *Configuration confBytes, err := ioutil.ReadFile(confFile) - if (err != nil) { + if err != nil { return nil, err } err = json.Unmarshal(confBytes, &config) - if (err != nil) { + if err != nil { return nil, err } return config, nil } - func (config *Configuration) Flags() []cli.Flag { - cli.VersionFlag.Usage = "Print the version" - cli.HelpFlag.Usage = "Show help" - return []cli.Flag { + cli.VersionFlag = cli.BoolFlag{ + Name: "print-version, V", + Usage: "Print version only", + } + cli.HelpFlag = cli.BoolFlag{ + Name: "Show help", + } + return []cli.Flag{ cli.StringFlag{ Name: "url", Value: "http://127.0.0.1:9200", @@ -248,4 +249,3 @@ func IsConfigRelevantFlagSet(c *cli.Context) bool { } return false } - diff --git a/elktail.go b/elktail.go index b062726..597aebf 100644 --- a/elktail.go +++ b/elktail.go @@ -9,10 +9,10 @@ package main import ( "encoding/json" "fmt" - "github.com/codegangsta/cli" + "github.com/urfave/cli" "golang.org/x/crypto/ssh/terminal" "golang.org/x/net/context" - "gopkg.in/olivere/elastic.v5" + "gopkg.in/olivere/elastic.v6" "io/ioutil" "net/url" "os" @@ -111,10 +111,14 @@ func NewTail(configuration *Configuration) *Tail { // Selects appropriate indices in EL based on configuration. This basically means that if query is date filtered, // then it attempts to select indices in the filtered date range, otherwise it selects the last index. func (tail *Tail) selectIndices(configuration *Configuration) { - indices, err := tail.client.IndexNames() + result, err := tail.client.CatIndices().Do(context.TODO()) if err != nil { Error.Fatalln("Could not fetch available indices.", err) } + indices := make([]string, len(result)) + for i, response := range result { + indices[i] = response.Index + } if configuration.QueryDefinition.IsDateTimeFiltered() { startDate := configuration.QueryDefinition.AfterDateTime @@ -267,7 +271,6 @@ func (tail *Tail) printResult(entry map[string]interface{}) { value, _ := EvaluateExpression(entry, f[1:]) result = strings.Replace(result, f, value, -1) } - fmt.Println(result) } func (tail *Tail) buildSearchQuery() elastic.Query { @@ -469,7 +472,6 @@ func main() { tail := NewTail(config) //If we don't exit here we can save the defaults configToSave.SaveDefault() - tail.Start(!config.IsListOnly(), config.InitialEntries) }