From ac405f56583ef33b6ff8ad9b73cbd1930ac5ba27 Mon Sep 17 00:00:00 2001 From: Simon Zeyer Date: Sat, 11 Dec 2021 14:59:17 +0100 Subject: [PATCH] Initial --- checks/nc_groupquota | 61 +++++++++++++++++++++++++++++++++++++++++++ plugins/nc_groupquota | 27 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 checks/nc_groupquota create mode 100644 plugins/nc_groupquota diff --git a/checks/nc_groupquota b/checks/nc_groupquota new file mode 100644 index 0000000..39ec708 --- /dev/null +++ b/checks/nc_groupquota @@ -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, +} diff --git a/plugins/nc_groupquota b/plugins/nc_groupquota new file mode 100644 index 0000000..e9ad4dd --- /dev/null +++ b/plugins/nc_groupquota @@ -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('<<>>') + +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() ))