@@ -12,11 +12,14 @@ type QueryConfig struct {
1212 Query string
1313 MessageKey string
1414 MessageLen int
15- Critical uint
16- Warning uint
15+ Critical string
16+ Warning string
1717}
1818
19- var cliQueryConfig QueryConfig
19+ var (
20+ cliQueryConfig QueryConfig
21+ rc int
22+ )
2023
2124var queryCmd = & cobra.Command {
2225 Use : "query" ,
@@ -44,7 +47,7 @@ https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-
4447 check .ExitError (err )
4548 }
4649
47- rc := 3
50+ rc = check . Unknown
4851 output := fmt .Sprintf ("Total hits: %d" , total )
4952
5053 if len (messages ) > 0 {
@@ -57,19 +60,26 @@ https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-
5760 }
5861 }
5962
60- if total >= cliQueryConfig .Critical {
63+ crit , err := check .ParseThreshold (cliQueryConfig .Critical )
64+ if err != nil {
65+ check .ExitError (err )
66+ }
67+
68+ warn , err := check .ParseThreshold (cliQueryConfig .Warning )
69+ if err != nil {
70+ check .ExitError (err )
71+ }
72+
73+ if crit .DoesViolate (float64 (total )) {
6174 rc = check .Critical
62- } else if total >= cliQueryConfig . Warning {
75+ } else if warn . DoesViolate ( float64 ( total )) {
6376 rc = check .Warning
64- } else if total < cliQueryConfig . Warning {
77+ } else {
6578 rc = check .OK
6679 }
6780
6881 p := perfdata.PerfdataList {
69- {Label : "total" , Value : total ,
70- Warn : & check.Threshold {Upper : float64 (cliQueryConfig .Warning )},
71- Crit : & check.Threshold {Upper : float64 (cliQueryConfig .Critical )},
72- },
82+ {Label : "total" , Value : total , Warn : warn , Crit : crit },
7383 }
7484
7585 check .ExitRaw (rc , output , "|" , p .String ())
@@ -88,9 +98,9 @@ func init() {
8898 "Message of messagekey to display" )
8999 fs .IntVarP (& cliQueryConfig .MessageLen , "msglen" , "m" , 80 ,
90100 "Number of characters to display in latest message" )
91- fs .UintVarP (& cliQueryConfig .Warning , "warning" , "w" , 20 ,
101+ fs .StringVarP (& cliQueryConfig .Warning , "warning" , "w" , "20" ,
92102 "Warning threshold for total hits" )
93- fs .UintVarP (& cliQueryConfig .Critical , "critical" , "c" , 50 ,
103+ fs .StringVarP (& cliQueryConfig .Critical , "critical" , "c" , "50" ,
94104 "Critical threshold for total hits" )
95105
96106 fs .SortFlags = false
0 commit comments