sunetdrive/templates/application/check_nextcloud_mounts.py

34 lines
1.2 KiB
Python

#!/usr/bin/env python3
from collections import Counter
import json
import shlex
import subprocess
import sys
buckets = []
bucket_count = {}
containers = {}
exit = 0
get_containers = subprocess.Popen('/usr/local/bin/get_containers', stdout=subprocess.PIPE).stdout.read()
containers = get_containers.decode().splitlines()
for container in containers:
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())
for items in mount_data:
buckets.append(items["configuration"]["bucket"])
bucket_count = dict(Counter(buckets))
for i, (k, v) in enumerate(bucket_count.items()):
if v > 1:
if i == 0:
print("WARNING: buckets with multiple mounts")
print(f"bucket {k} is mounted {v} times | {k}_num_mounts={v}")
else:
print(f"bucket {k} is mounted {v} times | {k}_num_mounts={v}")
# lets do exit 0 for now
# exit = 1
sys.exit(exit)