Merge branch 'main' of ssh://platform.sunet.se:22022/Drive/sunetdrive

This commit is contained in:
Micke Nordin 2025-03-12 11:44:20 +01:00
commit 5950751c73
Signed by untrusted user: Micke
GPG key ID: 0DA0A7A5708FE257
4 changed files with 80 additions and 2 deletions

View file

@ -101,6 +101,23 @@ define sunetdrive::app_type (
content => template('sunetdrive/application/get_containers'),
mode => '0744',
}
if ($nodenumber == 3) {
file { '/usr/lib/nagios/plugins/check_nextcloud_mounts.py':
ensure => present,
owner => 'root',
group => 'root',
content => template('sunetdrive/application/check_nextcloud_mounts.py'),
mode => '0744',
}
sunet::sudoer {'nagios_run_nextcloud_mounts_command':
user_name => 'nagios',
collection => 'nrpe_nextcloud_mounts_check',
command_line => '/usr/lib/nagios/plugins/check_nextcloud_mounts.py'
}
sunet::nagios::nrpe_command {'check_nextcloud_mounts':
command_line => '/usr/bin/sudo /usr/lib/nagios/plugins/check_nextcloud_mounts.py'
}
}
if ($nodenumber == 3) {
file { '/usr/local/bin/scan_external_mounts':
ensure => present,
@ -388,5 +405,4 @@ define sunetdrive::app_type (
}
}
}
}

View file

@ -46,6 +46,21 @@ class sunetdrive::multinode (
content => template('sunetdrive/application/get_containers'),
mode => '0744',
}
file { '/usr/lib/nagios/plugins/check_nextcloud_mounts.py':
ensure => present,
owner => 'root',
group => 'root',
content => template('sunetdrive/application/check_nextcloud_mounts.py'),
mode => '0744',
}
sunet::sudoer {'nagios_run_nextcloud_mounts_command':
user_name => 'nagios',
collection => 'nrpe_nextcloud_mounts_check',
command_line => '/usr/lib/nagios/plugins/check_nextcloud_mounts.py'
}
sunet::nagios::nrpe_command {'check_nextcloud_mounts':
command_line => '/usr/bin/sudo /usr/lib/nagios/plugins/check_nextcloud_mounts.py'
}
file { '/usr/local/bin/scan_external_mounts':
ensure => present,
force => true,

View file

@ -99,6 +99,11 @@ class sunetdrive::sitemonitornaemon() {
description => 'Status of sarimner interface',
contact_groups => ['alerts']
}
nagioscfg::service {'check_nextcloud_mounts':
hostgroup_name => ['sunetdrive::application','sunetdrive::multinode'],
check_command => 'check_nrpe_1arg!check_nextcloud_mounts',
description => 'S3 buckets with multiple Nextcloud mounts',
contact_groups => ['alerts']
}
}

View file

@ -0,0 +1,42 @@
#!/usr/bin/env python3
from collections import Counter
import json
import shlex
import subprocess
import sys
exit = 0
base_message = "OK: no duplicate mounts"
long_message = ""
get_containers = subprocess.Popen('/usr/local/bin/get_containers', stdout=subprocess.PIPE).stdout.read()
containers = get_containers.decode().splitlines()
for i, container in enumerate(containers, start=1):
buckets = []
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()
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"
long_message += f"\ncontainer: {container} - bucket: {k} - {v}"
# lets do exit 0 for now
# exit = 1
print(base_message)
if long_message != "":
print(long_message.lstrip())
sys.exit(exit)