-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script to monitor redis application through the check_mk agent
- Loading branch information
Ambroise Rosset
committed
Aug 5, 2022
1 parent
8449171
commit 2f6c6b3
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import json | ||
import subprocess | ||
|
||
shell_cmd = "redis-cli info" | ||
all_data = ( | ||
subprocess.Popen(shell_cmd, shell=True, stdout=subprocess.PIPE) | ||
.stdout.read() | ||
.split(b"\n") | ||
) | ||
|
||
version = 1 | ||
error = 0 | ||
error_string = "" | ||
redis_data = {} | ||
|
||
# stdout list to json | ||
try: | ||
category = "" | ||
for d in all_data: | ||
d = d.replace(b"\r", b"") | ||
|
||
if d in [b""]: | ||
continue | ||
|
||
if d.startswith(b"#"): | ||
category = d.replace(b"# ", b"").decode("utf-8") | ||
redis_data[category] = {} | ||
continue | ||
|
||
if not len(category): | ||
error = 2 | ||
error_string = "category not defined" | ||
break | ||
|
||
k, v = d.split(b":") | ||
k = k.decode("utf-8") | ||
v = v.decode("utf-8") | ||
|
||
redis_data[category][k] = v | ||
|
||
except: | ||
error = 1 | ||
error_string = "data extracting error" | ||
|
||
output = { | ||
"version": version, | ||
"error": error, | ||
"errorString": error_string, | ||
"data": redis_data, | ||
} | ||
print("<<<redis>>>") | ||
print(json.dumps(output)) |