Skip to content

Commit 2f6c6b3

Browse files
author
Ambroise Rosset
committed
add script to monitor redis application through the check_mk agent
1 parent 8449171 commit 2f6c6b3

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

agent-local/redis

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python3
2+
3+
import json
4+
import subprocess
5+
6+
shell_cmd = "redis-cli info"
7+
all_data = (
8+
subprocess.Popen(shell_cmd, shell=True, stdout=subprocess.PIPE)
9+
.stdout.read()
10+
.split(b"\n")
11+
)
12+
13+
version = 1
14+
error = 0
15+
error_string = ""
16+
redis_data = {}
17+
18+
# stdout list to json
19+
try:
20+
category = ""
21+
for d in all_data:
22+
d = d.replace(b"\r", b"")
23+
24+
if d in [b""]:
25+
continue
26+
27+
if d.startswith(b"#"):
28+
category = d.replace(b"# ", b"").decode("utf-8")
29+
redis_data[category] = {}
30+
continue
31+
32+
if not len(category):
33+
error = 2
34+
error_string = "category not defined"
35+
break
36+
37+
k, v = d.split(b":")
38+
k = k.decode("utf-8")
39+
v = v.decode("utf-8")
40+
41+
redis_data[category][k] = v
42+
43+
except:
44+
error = 1
45+
error_string = "data extracting error"
46+
47+
output = {
48+
"version": version,
49+
"error": error,
50+
"errorString": error_string,
51+
"data": redis_data,
52+
}
53+
print("<<<redis>>>")
54+
print(json.dumps(output))

0 commit comments

Comments
 (0)