trying to improve output of check_nextcloud_mounts script
This commit is contained in:
parent
9096bf7c33
commit
fbe409efff
1 changed files with 16 additions and 7 deletions
|
@ -6,29 +6,38 @@ import shlex
|
|||
import subprocess
|
||||
import sys
|
||||
|
||||
exit = 0
|
||||
buckets = []
|
||||
bucket_count = {}
|
||||
containers = {}
|
||||
exit = 0
|
||||
base_message = "OK: no duplicate mounts"
|
||||
perf_data = ""
|
||||
long_message = ""
|
||||
|
||||
get_containers = subprocess.Popen('/usr/local/bin/get_containers', stdout=subprocess.PIPE).stdout.read()
|
||||
containers = get_containers.decode().splitlines()
|
||||
|
||||
for container in containers:
|
||||
for i, container in enumerate(containers, start=1):
|
||||
list_command = f"/usr/local/bin/nocc {container} files_external:list --all --show-password --output json"
|
||||
command = shlex.split(list_command)
|
||||
mount_data_byte = subprocess.Popen(command, stdout=subprocess.PIPE).stdout.read()
|
||||
mount_data = json.loads(mount_data_byte.decode())
|
||||
try:
|
||||
mount_data = json.loads(mount_data_byte.decode())
|
||||
except json.decoder.JSONDecodeError as err:
|
||||
if i == 1 or i != len(containers):
|
||||
base_message = "WARNING: invalid json"
|
||||
long_message += f"\ncontainer: {container} - json decode error: {err}"
|
||||
# lets do exit 0 for now
|
||||
# exit = 1
|
||||
continue
|
||||
for items in mount_data:
|
||||
buckets.append(items["configuration"]["bucket"])
|
||||
bucket_count = dict(Counter(buckets))
|
||||
for k, v in bucket_count.items():
|
||||
if v > 1:
|
||||
base_message = "WARNING: buckets with multiple mounts |"
|
||||
perf_data += f" {k}={v}"
|
||||
base_message = "WARNING: buckets with multiple mounts"
|
||||
long_message += f"\ncontainer: {container} - bucket: {k} - {v}"
|
||||
# lets do exit 0 for now
|
||||
# exit = 1
|
||||
print(base_message + perf_data)
|
||||
print(base_message)
|
||||
print(long_message.lstrip())
|
||||
sys.exit(exit)
|
||||
|
|
Loading…
Add table
Reference in a new issue