fixed bug when no user quota is set
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
# pylint: disable=line-too-long, too-many-locals
|
# pylint: disable=line-too-long, too-many-locals
|
||||||
|
|
||||||
from time import time
|
from time import time
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
from cmk.agent_based.v2 import (
|
from cmk.agent_based.v2 import (
|
||||||
AgentSection,
|
AgentSection,
|
||||||
@@ -50,14 +51,17 @@ def check_nextcloud_users(item, params, section) -> CheckResult:
|
|||||||
last_login_human = section[item][4]
|
last_login_human = section[item][4]
|
||||||
last_login_since = section[item][5]
|
last_login_since = section[item][5]
|
||||||
free_space = quota_total_bytes - quota_used_bytes
|
free_space = quota_total_bytes - quota_used_bytes
|
||||||
# print(free_space)
|
if quota_total_bytes == -3.0:
|
||||||
|
# no quota set for user, we can't calculate free space and used percent
|
||||||
|
quota_is_set = False
|
||||||
|
else:
|
||||||
|
quota_is_set = True
|
||||||
_level_type, levels_quota_used = params["levels_users_quota_used"]
|
_level_type, levels_quota_used = params["levels_users_quota_used"]
|
||||||
_level_type, levels_free_space = params["levels_users_free_space"]
|
_level_type, levels_free_space = params["levels_users_free_space"]
|
||||||
if last_login_human == "never":
|
if (last_login_human == "never") or (not quota_is_set):
|
||||||
quota_used_percent = 0
|
|
||||||
details = f"User ID is '{userid}', Last login: {last_login_human}"
|
details = f"User ID is '{userid}', Last login: {last_login_human}"
|
||||||
summary = (
|
summary = (
|
||||||
f"Used quota of '{display_name}' can't be calculated yet (never logged in)"
|
f"Used quota of '{display_name}' can't be calculated yet (never logged in or no quota set)"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# Levels are given in MBytes, we have to adjust this here
|
# Levels are given in MBytes, we have to adjust this here
|
||||||
@@ -71,6 +75,7 @@ def check_nextcloud_users(item, params, section) -> CheckResult:
|
|||||||
yield Metric("nc_users_free_space", free_space, levels=(warn, crit))
|
yield Metric("nc_users_free_space", free_space, levels=(warn, crit))
|
||||||
if state != State.OK:
|
if state != State.OK:
|
||||||
yield Result(state=state, notice=notice)
|
yield Result(state=state, notice=notice)
|
||||||
|
yield Metric("nc_users_free_space", free_space, levels=(warn, crit))
|
||||||
yield Metric("nc_users_quota_used", quota_used_percent, levels=levels_quota_used)
|
yield Metric("nc_users_quota_used", quota_used_percent, levels=levels_quota_used)
|
||||||
state = get_state_upper(levels_quota_used, quota_used_percent)
|
state = get_state_upper(levels_quota_used, quota_used_percent)
|
||||||
yield Result(state=state, summary=summary, details=details)
|
yield Result(state=state, summary=summary, details=details)
|
||||||
|
|||||||
Reference in New Issue
Block a user