elilogs

2 min read

Background

I created this tool to solve 2 problems I’ve had with using Elasticsearch. There is no easy way to list the health information of a cluster/nodes/indexes and there is no way to multi-index search when using Kibana. The way that I usually do it is by building a decently long curl command, but that has potential to leak credentials if using basic authentication.

I used Cobra as the CLI framework and Viper to handle configuration.

The elilogs list command has 2 subcommands to list cluster or index information. The program’s exit status can be used as an alternative to parsing the output to ease the burden of using the tool in automations. For the cluster subcommand, there are flags that can be used to select only certain sections of: clusters, nodes, pending tasks, and snapshots. For the index subcommand, the user can enter a comma separated string of index names to return that status and health. Exit status of 0 means that all health/status in the output is green. All responses for these requests returned slices of string maps.

The elilogs search command is able to search all or a subset of indexes for a query string. The index flag takes a comma separated string of index names, similar to the elilogs list index command. Results are returned by index name and document. The search command required its own function to handle the response, as the response for a search request is different from the “Cat” requests.

I created multiple structs to unmarshal the json response into. These can be found in the internal/models/response.go file. These return as a map, and therefore; returned fields are not sorted in any deterministic order.

To Use

The easiest way to use this is to download the correct binary for your distribution at https://github.com/harvey-earth/elilogs/releases and then unzip/untar it. Then copy the contents at https://raw.githubusercontent.com/harvey-earth/elilogs/main/default-config.yml to a file named config.yml. This config.yml file can be located in the same directory as the binary, or in the /etc/elilogs/ or $HOME/.elilogs/ directories. Environment variables can also be used with the prefix ELILOGS, for example ELILOGS_CORE_PASSWORD.

Further Improvements

  • Add testing. One of my favorite traits of Ruby and RSpec/Minitest/etc. is how easy it makes TDD and BDD. Tests need to be added before any refactoring can be done.
  • Add quiet flag to suppress output.
  • Add flag to output search results to a file.
  • Refactor rest of print output into functions in utils.

Repository

The code for this is hosted at:

Next mood