fixed crash when last login seems to be in the future
This commit is contained in:
BIN
mkp/Nextcloud-3.2.1.mkp
Normal file
BIN
mkp/Nextcloud-3.2.1.mkp
Normal file
Binary file not shown.
@@ -20,6 +20,7 @@ from cmk.agent_based.v2 import (
|
|||||||
|
|
||||||
NO_LEVELS: Final[str] = "no_levels"
|
NO_LEVELS: Final[str] = "no_levels"
|
||||||
|
|
||||||
|
|
||||||
def get_state_upper(levels, value):
|
def get_state_upper(levels, value):
|
||||||
warn, crit = levels
|
warn, crit = levels
|
||||||
if value >= crit:
|
if value >= crit:
|
||||||
@@ -46,7 +47,10 @@ def discover_nextcloud_users(section) -> DiscoveryResult:
|
|||||||
def check_nextcloud_users(item, params, section) -> CheckResult:
|
def check_nextcloud_users(item, params, section) -> CheckResult:
|
||||||
attr = section.get(item)
|
attr = section.get(item)
|
||||||
if not attr:
|
if not attr:
|
||||||
yield Result(state=State.UNKNOWN, summary="User not found anymore, maybe it has been deleted.")
|
yield Result(
|
||||||
|
state=State.UNKNOWN,
|
||||||
|
summary="User not found anymore, maybe it has been deleted.",
|
||||||
|
)
|
||||||
return
|
return
|
||||||
userid = item
|
userid = item
|
||||||
quota_used_percent = section[item][0]
|
quota_used_percent = section[item][0]
|
||||||
@@ -65,9 +69,7 @@ def check_nextcloud_users(item, params, section) -> CheckResult:
|
|||||||
level_type_free_space, levels_free_space = params["levels_users_free_space"]
|
level_type_free_space, levels_free_space = params["levels_users_free_space"]
|
||||||
if (last_login_human == "never") or (not quota_is_set):
|
if (last_login_human == "never") or (not quota_is_set):
|
||||||
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 or no quota set)"
|
||||||
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
|
||||||
if level_type_free_space != NO_LEVELS:
|
if level_type_free_space != NO_LEVELS:
|
||||||
@@ -87,7 +89,9 @@ def check_nextcloud_users(item, params, section) -> CheckResult:
|
|||||||
if state != State.OK:
|
if state != State.OK:
|
||||||
yield Result(state=state, notice=notice)
|
yield Result(state=state, notice=notice)
|
||||||
if level_type_quota_used != NO_LEVELS:
|
if level_type_quota_used != NO_LEVELS:
|
||||||
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)
|
||||||
else:
|
else:
|
||||||
# a rule with no levels set is active, so assume OK state
|
# a rule with no levels set is active, so assume OK state
|
||||||
@@ -113,8 +117,12 @@ def parse_nextcloud_users(string_table: StringTable) -> dict:
|
|||||||
# user logged in at least once
|
# user logged in at least once
|
||||||
curr_time = int(time())
|
curr_time = int(time())
|
||||||
login_diff = curr_time - last_login
|
login_diff = curr_time - last_login
|
||||||
|
if login_diff < 0:
|
||||||
|
# this should not happen, but if it does, we handle it gracefully
|
||||||
|
last_login_since = "Check your system time, last login is in the future"
|
||||||
|
else:
|
||||||
|
last_login_since = render.timespan(login_diff)
|
||||||
last_login_human = render.datetime(last_login)
|
last_login_human = render.datetime(last_login)
|
||||||
last_login_since = render.timespan(login_diff)
|
|
||||||
quota_quota = int(line[4])
|
quota_quota = int(line[4])
|
||||||
if quota_quota == -3:
|
if quota_quota == -3:
|
||||||
# TBD, no quota set for user
|
# TBD, no quota set for user
|
||||||
|
|||||||
Reference in New Issue
Block a user