Merge branch 'testing' of ssh://platform.sunet.se:22022/Drive/sunetdrive into testing
This commit is contained in:
commit
ef1eb5b4ad
3 changed files with 49 additions and 27 deletions
|
@ -101,6 +101,23 @@ define sunetdrive::app_type (
|
||||||
content => template('sunetdrive/application/get_containers'),
|
content => template('sunetdrive/application/get_containers'),
|
||||||
mode => '0744',
|
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) {
|
if ($nodenumber == 3) {
|
||||||
file { '/usr/local/bin/scan_external_mounts':
|
file { '/usr/local/bin/scan_external_mounts':
|
||||||
ensure => present,
|
ensure => present,
|
||||||
|
@ -388,22 +405,4 @@ define sunetdrive::app_type (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if $facts['networking']['hostname'] == 'node1' or $facts['networking']['hostname'] =~ /^multinode[1-9]+$/{
|
|
||||||
file { '/usr/lib/nagios/plugins/check_nextcloud_mounts.py':
|
|
||||||
ensure => present,
|
|
||||||
force => true,
|
|
||||||
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'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,21 @@ class sunetdrive::multinode (
|
||||||
content => template('sunetdrive/application/get_containers'),
|
content => template('sunetdrive/application/get_containers'),
|
||||||
mode => '0744',
|
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':
|
file { '/usr/local/bin/scan_external_mounts':
|
||||||
ensure => present,
|
ensure => present,
|
||||||
force => true,
|
force => true,
|
||||||
|
|
|
@ -6,29 +6,37 @@ import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
buckets = []
|
|
||||||
bucket_count = {}
|
|
||||||
containers = {}
|
|
||||||
exit = 0
|
exit = 0
|
||||||
base_message = "OK: no duplicate mounts"
|
base_message = "OK: no duplicate mounts"
|
||||||
perf_data = ""
|
long_message = ""
|
||||||
|
|
||||||
get_containers = subprocess.Popen('/usr/local/bin/get_containers', stdout=subprocess.PIPE).stdout.read()
|
get_containers = subprocess.Popen('/usr/local/bin/get_containers', stdout=subprocess.PIPE).stdout.read()
|
||||||
containers = get_containers.decode().splitlines()
|
containers = get_containers.decode().splitlines()
|
||||||
|
|
||||||
for container in containers:
|
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"
|
list_command = f"/usr/local/bin/nocc {container} files_external:list --all --show-password --output json"
|
||||||
command = shlex.split(list_command)
|
command = shlex.split(list_command)
|
||||||
mount_data_byte = subprocess.Popen(command, stdout=subprocess.PIPE).stdout.read()
|
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:
|
for items in mount_data:
|
||||||
buckets.append(items["configuration"]["bucket"])
|
buckets.append(items["configuration"]["bucket"])
|
||||||
bucket_count = dict(Counter(buckets))
|
bucket_count = dict(Counter(buckets))
|
||||||
for k, v in bucket_count.items():
|
for k, v in bucket_count.items():
|
||||||
if v > 1:
|
if v > 1:
|
||||||
base_message = "WARNING: buckets with multiple mounts |"
|
base_message = "WARNING: buckets with multiple mounts"
|
||||||
perf_data += f" {k}={v}"
|
long_message += f"\ncontainer: {container} - bucket: {k} - {v}"
|
||||||
# lets do exit 0 for now
|
# lets do exit 0 for now
|
||||||
# exit = 1
|
# exit = 1
|
||||||
print(base_message + perf_data)
|
print(base_message)
|
||||||
|
if long_message != "":
|
||||||
|
print(long_message.lstrip())
|
||||||
sys.exit(exit)
|
sys.exit(exit)
|
||||||
|
|
Loading…
Add table
Reference in a new issue