MKP 2.5.1, added version infos for apps with available updates

This commit is contained in:
mellis 2024-01-12 16:38:48 +01:00
parent 05415a8d1d
commit a2a409a405
9 changed files with 65 additions and 10 deletions

View File

@ -5,10 +5,42 @@ Tested with Nextcloud 25/26/27/28.
Tested only with MySQL/MariaDB as database backend.
Feel free to report other working environments.
Upgrade from older MKPs (before 2.4.0):
If you upgrade from a already installed version before 2.4.0, you have to re-create your rules for the "Nextcloud Server Information" (reason: massive parameter changes).
Steps to accomplish this without problems:
1. Take a screenshot of your settings in the above mentioned ruleset
2. Assure that you have access to the passwords/tokens you used within the current rules
3. Delete all rules for "Nextcloud Server Information"
4. Install and enable the new MKP
5. Re-create your rules with the previously saved information from steps 1 and 2
6. Apply your changes
Hint: You have to create an app password now for accessing your Nextcloud instance. For this to accomplish login to your Nextcloud server with an administrative user account. Go to "Personal Settings|Security" and take note of the section "Devices & Sessions". Create the app password via clicking the button "create new app password". You may use this password explicitly within the rule or store it first in the password safe of CheckMK.
General installation instructions:
1. Upload and enable the MKP
2. Apply changes
3. Click Setup, search for "Nextcloud"
4. Click on "Nextcloud Server Information" below "Other integrations"
5. Create a new rule and fill in all mandatory information (Hostname, Username, App Password)
6. Adjust all other options to your needs
7. Bind this rule to your Nextcloud host object (e.g. via "Explicit hosts")
8. If you have no host object at all, create a dummy host for this (with no IP or something like 127.0.0.2)
9. Assure that your agents settings for this host object are correct (must contain "Configured API integrations")
10. Apply your changes
11. Execute a service discovery on your Nextcloud host(s) and accept the newly detected services
12. Feel free to adjust the various parameters for thresholds within the available parameter sections (Setup, "Service monitoring rules" after searching for "Nextcloud")
Version History:
--
|Date|Version|Changes|
|----|-------|-------|
|2023/01/12|2.5.1|Added versions for apps with available updates|
|2023/01/12|2.4.1|Removed Parameter "token", switched to parameter "app password" only|
|2023/01/12|2.4.0|Integrated Password Store for App Password, some changes for compatibility with NC 28 added|
|2023/11/26|2.3.4|Fixed agent crash if opcache_get_status is disabled by server settings|
|2023/08/16|2.3.3|Fixed some misleading info strings regarding database opcache|
@ -26,3 +58,7 @@ Example how the checks look like:
Example of the details of the info check:
--
![Nextcloud Info Details](images/Nextcloud-Info-Details.png)
Example when app updates are available:
--
![Nextcloud AppUpdateInfo](images/Nextcloud-Update-Status-WARN.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

@ -39,7 +39,7 @@ def check_nextcloud_info(params, section):
except KeyError:
last_update = "Update information not available, update to at least version 28"
update_available = "False"
last_update_human = "Update information not available"
last_update_human = "Information not available"
status = section[key]["status"]
free_space = section[key]["freespace"]
version = section[key]["version"]
@ -53,8 +53,8 @@ def check_nextcloud_info(params, section):
yield(Metric("nc_num_shares", num_shares))
# create overall result
summary = f"Status is {status}"
details = f"Nextcloud version: {version}\nLast update: {last_update_human}\nPHP version: {php_version}\nWebserver: {webserver}\n\nNumber of files: {num_files}\nNumber of shares: {num_shares}\n\nFree space on disk: {render.bytes(free_space)}\n"
summary = f"Status is {status}, Last update: {last_update_human}"
details = f"Nextcloud version: {version}\nPHP version: {php_version}\nWebserver: {webserver}\n\nNumber of files: {num_files}\nNumber of shares: {num_shares}\n\nFree space on disk: {render.bytes(free_space)}\n"
if status == "ok":
state = State.OK
else:
@ -118,12 +118,19 @@ def check_nextcloud_info(params, section):
try:
num_apps_installed = section[key]["installed"]
num_apps_with_updates_available = section[key]["with_updates_available"]
if "app_versions" in section[key]:
app_versions = section[key]["app_versions"]
else:
app_versions = ""
# create graphs for number of apps
levels = params["levels_apps_with_updates_available"]
yield Metric("nc_num_apps_installed", num_apps_installed)
yield Metric("nc_apps_with_updates_available", num_apps_with_updates_available, levels=levels)
state = getStateUpper(levels, num_apps_with_updates_available)
notice = f"Number of installed apps: {num_apps_installed}\nNumber of apps with updates available: {num_apps_with_updates_available}"
if (app_versions == ""):
notice = f"Number of installed apps: {num_apps_installed}\nNumber of apps with updates available: {num_apps_with_updates_available}"
else:
notice = f"Number of installed apps: {num_apps_installed}\nNumber of apps with updates available: {num_apps_with_updates_available}\nNew app versions available: {app_versions}"
yield(Result(state=state, notice=notice))
except KeyError:
pass
@ -153,6 +160,7 @@ def parse_nextcloud_info_section(string_table):
"NC_Num_Storages_Other",
"NC_Num_Apps_Installed",
"NC_Num_Apps_Updates_Available",
"NC_Apps_With_Updates_Available",
"NC_Active_Users_Last_5Min",
"NC_Active_Users_Last_1Hour",
"NC_Active_Users_Last_1Day"
@ -191,6 +199,8 @@ def parse_nextcloud_info_section(string_table):
parsed_data["apps"]["installed"] = int(value)
elif param == "NC_Num_Apps_Updates_Available":
parsed_data["apps"]["with_updates_available"] = int(value)
elif param == "NC_Apps_With_Updates_Available":
parsed_data["apps"]["app_versions"] = value
elif param == "NC_Num_Users":
parsed_data["users"]["number"] = int(value)
elif param == "NC_Active_Users_Last_5Min":

View File

@ -136,10 +136,10 @@ def getSession(username, secret):
return session
def getData(session, url, verify):
data = {}
headers = CaseInsensitiveDict()
headers["Accept"] = "application/json"
cookies = {"nc_sameSiteCookiestrict": "true"}
response = session.get(url, headers=headers, cookies=cookies, verify=verify)
response = session.get(url, headers=headers, verify=verify)
status = response.status_code
if (status == 200):
jsdata = response.text
@ -157,8 +157,7 @@ def getDataAllUsers(session, url, verify):
headers = CaseInsensitiveDict()
headers["Accept"] = "application/json"
headers["OCS-APIRequest"] = "true"
cookies = {"nc_sameSiteCookiestrict": "true"}
response = session.get(url, headers=headers, cookies=cookies, verify=verify)
response = session.get(url, headers=headers, verify=verify)
status = response.status_code
if (status == 200):
jsdata = response.text
@ -172,8 +171,7 @@ def getDataUser(session, url, verify):
headers = CaseInsensitiveDict()
headers["Accept"] = "application/json"
headers["OCS-APIRequest"] = "true"
cookies = {"nc_sameSiteCookiestrict": "true"}
response = session.get(url, headers=headers, cookies=cookies, verify=verify)
response = session.get(url, headers=headers, verify=verify)
status = response.status_code
if (status == 200):
jsdata = response.text
@ -184,6 +182,8 @@ def getDataUser(session, url, verify):
sys.exit(1)
def doCmkOutput(data):
apps_with_updates_available = {}
str_apps_with_updates_available = ""
print("<<<nextcloud_info:sep(59)>>>")
print(f"NC_Version;{data['ocs']['data']['nextcloud']['system']['version']}")
print(f"NC_Freespace;{data['ocs']['data']['nextcloud']['system']['freespace']}")
@ -205,6 +205,11 @@ def doCmkOutput(data):
try:
print(f"NC_Num_Apps_Installed;{data['ocs']['data']['nextcloud']['system']['apps']['num_installed']}")
print(f"NC_Num_Apps_Updates_Available;{data['ocs']['data']['nextcloud']['system']['apps']['num_updates_available']}")
apps_with_updates_available = data['ocs']['data']['nextcloud']['system']['apps']['app_updates']
if apps_with_updates_available:
for app, version in apps_with_updates_available.items():
str_apps_with_updates_available = str_apps_with_updates_available + app + "/" + version + " "
print(f"NC_Apps_With_Updates_Available;{str_apps_with_updates_available}")
except KeyError:
pass
print(f"NC_Active_Users_Last_5Min;{data['ocs']['data']['activeUsers']['last5minutes']}")

View File

@ -12,7 +12,9 @@ description:
The user must not be secured with 2FA.
Shows several information about a Nextcloud instance, e.g. number of files/storages/(active)users, free space on disk.
The check will raise CRIT if the Nextcloud instance is not in "ok" state.
The check will raise WARN if there is an update availbale for Nextcloud.
The check will raise WARN/CRIT if free space on disk is below the configurable levels.
The check will raise WARN/CRIT if the number of installed apps with available updates is above the configurable levels.
The check will raise WARN/CRIT if the number of files is above the configurable levels.
inventory:
one service is created (with several details)

View File

@ -51,10 +51,12 @@ def _parameter_spec_nextcloud_info():
Integer(
title=_("Warning at"),
default_value=100000,
size=32,
),
Integer(
title=_("Critical at"),
default_value=250000,
size=32,
)
],
)),

Binary file not shown.

Binary file not shown.

BIN
mkp/Nextcloud-2.5.1.mkp Normal file

Binary file not shown.