Skip to content

Commit dcc48e8

Browse files
committed
Detect redis cli per instance
1 parent 9b66edd commit dcc48e8

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

agents/plugins/mk_redis

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ CMK_VERSION="2.5.0b1"
1414
# sample output of pgrep command
1515
# 1051 /usr/bin/redis-server 127.0.0.1:6380
1616
# 1324 /usr/bin/redis-server 127.0.0.1:6379
17+
# 1612 /usr/bin/valkey-server 127.0.0.1:6379
1718

1819
# example cfg file /etc/check_mk/mk_redis.cfg
1920
#
@@ -55,13 +56,26 @@ redis_args() {
5556
REDIS_ARGS=("-h" "${!HOST}" "-p" "${!PORT}")
5657
fi
5758

58-
if [[ "${!PASSWORD}" ]] && [[ "${!PASSWORD}" != "None" ]]; then
59-
REDIS_CLI_COMMAND="REDISCLI_AUTH='${!PASSWORD}' redis-cli"
60-
else
59+
REDIS_ARGS+=("info")
60+
61+
# detect usable redis-cli
62+
if [[ "${!HOST}" == /omd/sites/* ]]; then
63+
# use site redis-cli for redis instances in site
64+
IFS="/" read -ra ADDR <<<"${!HOST}"
65+
REDIS_CLI_COMMAND="/omd/sites/${ADDR[3]}/bin/redis-cli"
66+
elif type redis-cli &>/dev/null; then
6167
REDIS_CLI_COMMAND="redis-cli"
68+
elif type valkey-cli &>/dev/null; then
69+
REDIS_CLI_COMMAND="valkey-cli"
70+
else
71+
REDIS_CLI_COMMAND="echo 'error: no cli found'"
72+
REDIS_ARGS=()
73+
return
6274
fi
6375

64-
REDIS_ARGS+=("info")
76+
if [[ "${!PASSWORD}" ]] && [[ "${!PASSWORD}" != "None" ]]; then
77+
REDIS_CLI_COMMAND="REDISCLI_AUTH='${!PASSWORD}' ${REDIS_CLI_COMMAND}"
78+
fi
6579
}
6680

6781
main() {
@@ -112,13 +126,7 @@ main() {
112126
# print server section
113127
echo "[[[$INSTANCE|${!HOST}|${!PORT}]]]"
114128

115-
if [[ "${!HOST}" == /omd/sites/* ]]; then
116-
# use site redis-cli for redis instances in site
117-
IFS="/" read -ra ADDR <<<"${!HOST}"
118-
output=$(waitmax 3 bash -c "/omd/sites/${ADDR[3]}/bin/redis-cli ${REDIS_ARGS[*]}" 2>&1 || true)
119-
else
120-
output=$(waitmax 3 bash -c "${REDIS_CLI_COMMAND} ${REDIS_ARGS[*]}" 2>&1 || true)
121-
fi
129+
output=$(waitmax 3 bash -c "${REDIS_CLI_COMMAND} ${REDIS_ARGS[*]}" 2>&1 || true)
122130

123131
if [[ "$output" == *"Could not connect to Redis at ${!HOST}: Permission denied"* ]]; then
124132
# mark error explicitly for easier parsing

0 commit comments

Comments
 (0)