From 7fbea7f5570be78d234ac3bf5a557d27db049d4c Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Mon, 28 Nov 2022 16:41:43 +0100 Subject: [PATCH] Update help texts and README --- .gitignore | 2 ++ README.md | 66 +++++++++++++++++++++++++++++++++------------------ cmd/health.go | 6 ++--- cmd/query.go | 6 ++--- cmd/root.go | 10 ++++---- 5 files changed, 56 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index 4699957..387a966 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .idea /dist/ +coverage.html +coverage.out check_elasticsearch* diff --git a/README.md b/README.md index 3c6cca1..332d4d0 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,27 @@ query. ## Usage +``` +Usage: + check_elasticsearch [flags] + check_elasticsearch [command] + +Available Commands: + health Checks the health status of an Elasticsearch cluster + query Checks the total hits/results of an Elasticsearch query + +Flags: + -H, --hostname string Hostname of the Elasticsearch instance (default "localhost") + -p, --port int Port of the Elasticsearch instance (default 9200) + -U, --username string Username if authentication is required + -P, --password string Password if authentication is required + -S, --tls Use a HTTPS connection + --insecure Skip the verification of the server's TLS certificate + -t, --timeout int Timeout in seconds for the CheckPlugin (default 30) + -h, --help help for check_elasticsearch + -v, --version version for check_elasticsearch +``` + ### Health Checks the health status of an Elasticsearch cluster. @@ -13,26 +34,22 @@ Checks the health status of an Elasticsearch cluster. Usage: check_elasticsearch health -Flags: - -h, --help help for health - -Global Flags: - -H, --hostname string Hostname or ip address of elasticsearch node (default "localhost") - --insecure Allow use of self signed certificates when using SSL - -P, --password string Password if authentication is required - -p, --port int Port of elasticsearch node (default 9200) - -S, --tls Use secure connection - -U, --username string Username if authentication is required +The cluster health status is: + green = OK + yellow = WARNING + red = CRITICAL ``` -#### Elasticsearch cluster with green status (all nodes are running) +Examples: + +Elasticsearch cluster with green status (all nodes are running): ``` $ check_elasticsearch health -U exampleuser -P examplepassword -S --insecure OK - Cluster es-example-cluster is green | status=0 nodes=3 data_nodes=3 active_primary_shards=10 active_shards=20 ``` -#### Elasticsearch cluster with yellow status (not all nodes are running) +Elasticsearch cluster with yellow status (not all nodes are running): ``` $ check_elasticsearch health -U exampleuser -P examplepassword -S --insecure @@ -41,31 +58,34 @@ WARNING - Cluster es-example-cluster is yellow | status=1 nodes=2 data_nodes=2 a ### Query -Checks the total hits/results of an Elasticsearch query.
-The plugin is currently capable to return the total hits of documents based on a provided query string. +Checks the total hits/results of an Elasticsearch query. + +Hint: The plugin is currently capable to return the total hits of documents based on a provided query string. ``` Usage: check_elasticsearch query [flags] Flags: - -q, --query string Elasticsearch query - -I, --index string The index which will be used (default "_all") - -k, --msgkey string Message of messagekey to display - -m, --msglen int Number of characters to display in latest message (default 80) - -w, --warning uint Warning threshold for total hits (default 20) - -c, --critical uint Critical threshold for total hits (default 50) - -h, --help help for query + -q, --query string The Elasticsearch query + -I, --index string Name of the Index which will be used (default "_all") + -k, --msgkey string Message of messagekey to display + -m, --msglen int Number of characters to display in the latest message (default 80) + -w, --warning string Warning threshold for total hits (default "20") + -c, --critical string Critical threshold for total hits (default "50") + -h, --help help for query ``` -#### Search for total hits without any message +Examples: + +Search for total hits without any message: ``` $ check_elasticsearch query -q "event.dataset:sample_web_logs and @timestamp:[now-5m TO now]" -I "kibana_sample_data_logs" CRITICAL - Total hits: 14074 | total=14074;20;50 ``` -#### Search for total hits with message +Search for total hits with message: ``` $ check_elasticsearch query -q "event.dataset:sample_web_logs and @timestamp:[now-5m TO now]" -I "kibana_sample_data_logs" -k "message" diff --git a/cmd/health.go b/cmd/health.go index 52b6e1b..5759a08 100644 --- a/cmd/health.go +++ b/cmd/health.go @@ -12,9 +12,9 @@ var healthCmd = &cobra.Command{ Long: `Checks the health status of an Elasticsearch cluster The cluster health status is: - green = OK - yellow = WARNING - red = CRITICAL.`, + green = OK + yellow = WARNING + red = CRITICAL`, Example: " check_elasticsearch health --hostname \"127.0.0.1\" --port 9200 --username \"exampleUser\" " + "--password \"examplePass\" --tls --insecure", Run: func(cmd *cobra.Command, args []string) { diff --git a/cmd/query.go b/cmd/query.go index 440b15f..ab4740b 100644 --- a/cmd/query.go +++ b/cmd/query.go @@ -91,13 +91,13 @@ func init() { fs := queryCmd.Flags() fs.StringVarP(&cliQueryConfig.Query, "query", "q", "", - "Elasticsearch query") + "The Elasticsearch query") fs.StringVarP(&cliQueryConfig.Index, "index", "I", "_all", - "The index which will be used ") + "Name of the Index which will be used") fs.StringVarP(&cliQueryConfig.MessageKey, "msgkey", "k", "", "Message of messagekey to display") fs.IntVarP(&cliQueryConfig.MessageLen, "msglen", "m", 80, - "Number of characters to display in latest message") + "Number of characters to display in the latest message") fs.StringVarP(&cliQueryConfig.Warning, "warning", "w", "20", "Warning threshold for total hits") fs.StringVarP(&cliQueryConfig.Critical, "critical", "c", "50", diff --git a/cmd/root.go b/cmd/root.go index 67ec157..dc8c115 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -41,19 +41,19 @@ func init() { pfs := rootCmd.PersistentFlags() pfs.StringVarP(&cliConfig.Hostname, "hostname", "H", "localhost", - "Address of elasticsearch node") + "Hostname of the Elasticsearch instance") pfs.IntVarP(&cliConfig.Port, "port", "p", 9200, - "Port of elasticsearch node") + "Port of the Elasticsearch instance") pfs.StringVarP(&cliConfig.Username, "username", "U", "", "Username if authentication is required") pfs.StringVarP(&cliConfig.Password, "password", "P", "", "Password if authentication is required") pfs.BoolVarP(&cliConfig.TLS, "tls", "S", false, - "Use secure connection") + "Use a HTTPS connection") pfs.BoolVar(&cliConfig.Insecure, "insecure", false, - "Allow use of self signed certificates when using SSL") + "Skip the verification of the server's TLS certificate") pfs.IntVarP(&Timeout, "timeout", "t", Timeout, - "Timeout for the check") + "Timeout in seconds for the CheckPlugin") rootCmd.Flags().SortFlags = false pfs.SortFlags = false