This commit is contained in:
Simon Zeyer 2021-12-11 14:59:17 +01:00
commit ac405f5658
2 changed files with 88 additions and 0 deletions

61
checks/nc_groupquota Normal file
View File

@ -0,0 +1,61 @@
#!/usr/bin/python
# Author: Simon Zeyer
# E-Mail: simon@zeyersch.de
# URL:
# License: GPLv2
# default parameters
nc_groupquota_default_levels = (90, 95)
# the inventory function
def inventory_nc_groupquota(info):
# loop over all output lines of the agent
for line in info:
arr_ncgq_vars = line[0].split(";")
yield arr_ncgq_vars[0] + "", "nc_groupquota_default_levels"
# the check function (dummy)
def check_nc_groupquota(item, params, info):
# print(item, params, info)
group = None
for line in info:
if line[0].split(";")[0] == item:
group = line[0].split(";")
#print(group)
#if line_count is 0, no backup file exists --> error!
if not group:
yield 2, "group not found!"
return
perfdata = [
( "quota", int(group[2]), int(group[1])/100*params["levels"][0], int(group[1])/100*params["levels"][1] ),
]
#check counter
if 100*int(group[2])/int(group[1]) >= params["levels"][1]:
yield 2, "quota using {} exceeted crit level of {}%".format(100*int(group[2])/int(group[1]), params["levels"][1]), perfdata
return
if 100*int(group[2])/int(group[1]) >= params["levels"][0]:
yield 1, "quota using {} exceeted warn level of {}%".format(100*int(group[2])/int(group[1]), params["levels"][0]), perfdata
return
if 100*int(group[2])/int(group[1]) < params["levels"][0]:
yield 0, "quota using {}%".format(100*int(group[2])/int(group[1])), perfdata
return
yield 3, "error occured in check plugin."
return
# declare the check to Check_MK
check_info["nc_groupquota"] = {
'check_function': check_nc_groupquota,
'inventory_function': inventory_nc_groupquota,
'service_description': 'NC GroupQuota %s',
'group': 'filesystem',
'has_perfdata': True,
}

27
plugins/nc_groupquota Normal file
View File

@ -0,0 +1,27 @@
#!/usr/bin/python
# Author: Simon Zeyer
# E-Mail: simon@zeyersch.de
# URL:
# License: GPLv2
import os
import re
instances = {
"Wolke": {
"occ": "sudo -u www-data php /var/www/html/occ"
},
# "Wolke": {
# "occ": "sudo -u www-data php /var/www/html/occ"
# }
}
print('<<<nc_groupquota>>>')
for instance in instances:
stream = os.popen("{} {}:{}".format(instances[instance]["occ"], "groupquota", "list" ))
res = re.findall(r"(.*): (\d+)", stream.read())
for s in res:
stream = os.popen("{} {}:{} {}".format(instances[instance]["occ"], "groupquota", "used", s[0] ))
print("{}:{};{};{}".format(instance, s[0], s[1], stream.read().strip() ))