Skip to content

Commit a06fc92

Browse files
authored
feat(valkey-status): support user and password credentials, fix tls connection (#954)
1 parent f6b3678 commit a06fc92

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

check-plugins/valkey-status/README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Returns information and statistics about a Valkey server. Alerts on memory consu
66

77
Hints:
88

9-
* Tested on Valkey 8.0.
9+
* Tested on Valkey 7.2 and 8.0.
1010
* "I'm here to keep you safe, Sam. I want to help you." comes from the character GERTY in the movie "Moon" (2009).
1111

1212

@@ -24,11 +24,11 @@ Hints:
2424
## Help
2525

2626
```text
27-
usage: valkey-status [-h] [-V] [--always-ok] [-c CRIT] [-H HOSTNAME]
27+
usage: valkey-status [-h] [-V] [--always-ok] [-c CRIT] [--cacert FILE] [-H HOSTNAME]
2828
[--ignore-maxmemory0] [--ignore-overcommit]
2929
[--ignore-somaxconn] [--ignore-sync-partial-err]
3030
[--ignore-thp] [-p PASSWORD] [--port PORT]
31-
[--socket SOCKET] [--test TEST] [--tls] [-w WARN]
31+
[--socket SOCKET] [--test TEST] [--tls] [-u USER] [--verbose] [-w WARN]
3232
3333
Returns information and statistics about a Valkey server. Alerts on memory
3434
consumption, memory fragmentation, hit rates and more.
@@ -39,6 +39,7 @@ options:
3939
--always-ok Always returns OK.
4040
-c, --critical CRIT Set the CRIT threshold as a percentage. Default: >=
4141
None
42+
--cacert CA Certificate file to verify with.
4243
-H, --hostname HOSTNAME
4344
Valkey server hostname. Default: 127.0.0.1
4445
--ignore-maxmemory0 Don't warn about valkey' maxmemory=0. Default: False
@@ -60,6 +61,9 @@ options:
6061
--test TEST For unit tests. Needs "path-to-stdout-file,path-to-
6162
stderr-file,expected-retc".
6263
--tls Establish a secure TLS connection to Valkey.
64+
-u, --user USER
65+
Username to use when connecting to the valkey server.
66+
--verbose Verbose mode helps you debug stuff.
6367
-w, --warning WARN Set the WARN threshold as a percentage. Default: >= 90
6468
```
6569

@@ -157,5 +161,5 @@ net.core.somaxconn is lower than net.ipv4.tcp_max_syn_backlog
157161

158162
## Credits, License
159163

160-
* Authors: [Linuxfabrik GmbH, Zurich](https://www.linuxfabrik.ch)
164+
* Authors: [Linuxfabrik GmbH, Zurich](https://www.linuxfabrik.ch); [Claudio Kuenzler](https://www.claudiokuenzler.com)
161165
* License: The Unlicense, see [LICENSE file](https://unlicense.org/).

check-plugins/valkey-status/valkey-status

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import lib.txt # pylint: disable=C0413
2323
from lib.globals import (STATE_CRIT, STATE_OK, # pylint: disable=C0413
2424
STATE_UNKNOWN, STATE_WARN)
2525

26-
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
27-
__version__ = '2025062901'
26+
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland; Claudio Kuenzler'
27+
__version__ = '2025092401'
2828

2929
DESCRIPTION = """Returns information and statistics about a Valkey server. Alerts on memory
3030
consumption, memory fragmentation, hit rates and more."""
@@ -67,6 +67,12 @@ def parse_args():
6767
default=DEFAULT_CRIT,
6868
)
6969

70+
parser.add_argument(
71+
'--cacert',
72+
help='CA Certificate file to verify with.',
73+
dest='CACERT',
74+
)
75+
7076
parser.add_argument(
7177
'-H', '--hostname',
7278
help='Valkey server hostname. Default: %(default)s',
@@ -153,6 +159,20 @@ def parse_args():
153159
default=False,
154160
)
155161

162+
parser.add_argument(
163+
'-u', '--user',
164+
help='Username to use when connecting to the valkey server.',
165+
dest='USER',
166+
)
167+
168+
parser.add_argument(
169+
'--verbose',
170+
help='Verbose mode helps you debug stuff.',
171+
dest='VERBOSE',
172+
action='store_true',
173+
default=False,
174+
)
175+
156176
parser.add_argument(
157177
'-w', '--warning',
158178
help='Set the WARN threshold as a percentage. Default: >= %(default)s',
@@ -178,11 +198,17 @@ def main():
178198
base_cmd = 'valkey-cli -h {} -p {} '.format(args.HOSTNAME, args.PORT)
179199
else:
180200
base_cmd = 'valkey-cli -s {} '.format(args.SOCKET)
181-
if args.PASSWORD:
201+
if args.PASSWORD and not args.USER:
182202
base_cmd += '-a {} '.format(args.PASSWORD)
183203
base_cmd += '--no-auth-warning '
204+
if args.PASSWORD and args.USER:
205+
base_cmd += '--user {} '.format(args.USER)
206+
base_cmd += '--pass {} '.format(args.PASSWORD)
207+
base_cmd += '--no-auth-warning '
184208
if args.TLS:
185-
base_cmd += '--tls --cacert /etc/pki/tls/certs/rootCA.pem '
209+
base_cmd += '--tls '
210+
if args.CACERT:
211+
base_cmd += '--cacert {} '.format(args.CACERT)
186212

187213
# fetch data using `valkey-cli info default`
188214
if args.TEST is None:
@@ -198,6 +224,9 @@ def main():
198224
if not stdout.startswith('# Server'):
199225
lib.base.oao(stdout, STATE_WARN)
200226

227+
# Debug output
228+
if args.VERBOSE:
229+
print(stdout)
201230
# parse the output
202231
lines = stdout.splitlines()
203232
result = {}
@@ -230,11 +259,12 @@ def main():
230259

231260
# analyze result, get the state and build the message
232261

233-
# Valkey v8.0.3 (based on Redis v7.2.4), standalone mode on 127.0.0.1:6379,
262+
# Valkey v8.0.3 (based on Redis v7.2.4), standalone mode on 127.0.0.1:6379,
234263
msg += 'Valkey v{}'.format(result['valkey_version'])
235264
if 'redis_version' in result:
236265
msg += ' (based on Redis v{})'.format(result['redis_version'])
237-
msg += ', {} mode '.format(result['server_mode'])
266+
if 'server_mode' in result:
267+
msg += ', {} mode '.format(result['server_mode'])
238268
if not args.SOCKET:
239269
msg += 'on {}:{}, '.format(
240270
args.HOSTNAME,

0 commit comments

Comments
 (0)