Nextcloud Local Check(s)

Just a little thing i made and wanted to share.
I know there is a Special Agent for NextCloud/OpenCloud, but to minimize differences i try to stick to a/the regular agent.
So to get insight into some parts on Nextcloud ( specifically updates) i made the below localscript.

As with all local checks, this script needs to be placed in/on the NextCloud server itself in /usr/lib/check_mk_agent/local and must be made executable via chmod +x /usr/lib/check_mk_agent/local/scriptname.here

#!/bin/bash

#basepath of Nextcloud's occ executable
BASEPATH="/var/www/html"

sudo -u apache php $BASEPATH/occ status -e
if [ $? -eq 0 ]; then
    echo "0 \"NextCloud\" - NextCloud all up to date"
elif [ $? -eq 1 ]; then
    echo "1 \"NextCloud\" - NextCloud maintenance-mode is enabled"
elif [ $? -eq 2 ]; then
    echo "2 \"NextCloud\" - NextCloud Core needs updating"
fi

APPRESULT=$(sudo -u apache php $BASEPATH/occ app:update --showonly)
if [ -z "$APPRESULT" ]; then
    echo "0 \"NextCloud Apps\" - NextCloud Apps all up to date"
else
    UPDATECOUNT=$(echo "$APPRESULT" | wc -l)
    echo "1 \"NextCloud Apps\" - $UPDATECOUNT NextCloud Apps require updates"
fi

In essence this will give me (next to the regular information on the OS via the standard Agent) Nextcloud specifics.
For now this is what i was in need of, however maybe future needs might require me to extend this local check, and then i will update the above code.

Happy Monitoring !

  • Glowsome
4 Likes

Hi Glowsome,

very nice! Thanks for sharing.

In my case (and maybe @some others) username had to be adjusted:

indstead of β€œsudo -u apache” it had to be β€œsudo -u www-data”

best,

Gerson

This has to do with the underlying Linux type/flavour.

I myself use RockyLinux, so user β€˜apache’ but i guess Debian-style uses user β€˜www-data’

true.

Also, the check tells me to update Nextcloud apps, although all of them are up to date.

Will report changes that work, once I fetched them.

Up untill now each time the check appeared with a status other then warning on Nextcloud Apps it was true.

i locally (on the nextcloud box itself) ran:

cd /var/www/html/
sudo -u apache php occ app:update --all

And on the next pass of the check it would be OK again.

The only thing i cannot seem to grab is a/the version of Nextcloud itself ( currently running 28.0.5, but 29.0.0 is available).

image

The localcheck will however detect the status after having run this web-updater.

  • Glowsome

I did a manual β€œocc app:update -all” before also, did not work.
My NC version is already updated to 29.0.0
I’ll keep you updated

As above shows i have one incompatible app running, so i have not yet updated ( this is blocking for me)

When the app becomes available for version 29.0.0 i will update/upgrade and re-check the localcheck functionality.

  • Glowsome

Since β€œocc app:update --showonly” always shows a regex string,
I have to change
[ -z "$APPRESULT" ] to
[ "$APPRESULT" == "$STRING" ]
Should work fine now.
Again, thanks for sharing

best,
Gerson

After your report in regards of what you experienced i have extended/revised the localcheck script.

#!/bin/bash

#basepath of Nextcloud's occ executable
BASEPATH="/var/www/html"
# set the correct user for running the commands (This will be either apache or www-data, depends on your Linux Distro)
APACHEUSER="apache"

# check if jq package is present on the system
if ! [ -f /usr/bin/jq ]; then
    echo "2 \"NextCloud\" - NextCloud localcheck required jq package to be installed"
    echo "2 \"NextCloud Apps\" - NextCloud localcheck required jq package to be installed"
    exit;
fi

# Get current installed Nextcloud version-information
NCINSTALLED=$(sudo -u $APACHEUSER php $BASEPATH/occ status --output=json | jq -r '.version')

# Get latest avaiable version information
NCAVAILABLE=$(sudo -u $APACHEUSER php $BASEPATH/occ update:check | tr -d '\n' | awk '{print $2}' | cat)

# Compare results of installed and available version and report update available if they differ
if [ $NCINSTALLED != $NCAVAILABLE ]; then
   echo "1 \"NextCloud\" - A new NextCloud version ( $NCAVAILABLE )is available, please upgrade"
else
    sudo -u $APACHEUSER php $BASEPATH/occ status -e
    if [ $? -eq 0 ]; then
        echo "0 \"NextCloud\" - NextCloud all up to date"
    elif [ $? -eq 1 ]; then
        echo "1 \"NextCloud\" - NextCloud maintenance-mode is enabled"
    elif [ $? -eq 2 ]; then
        echo "2 \"NextCloud\" - NextCloud Core needs updating"
    fi
fi

# Get information about apps and potential updates and report the result.
# Result of the query for updates seems to produce a different output as of version 29.0.0
# this is under investigation
APPRESULT=$(sudo -u $APACHEUSER php $BASEPATH/occ app:update --showonly)
if [ -z "$APPRESULT" ]; then
    echo "0 \"NextCloud Apps\" - NextCloud Apps all up to date"
else
    UPDATECOUNT=$(echo "$APPRESULT" | wc -l)
    echo "1 \"NextCloud Apps\" - $UPDATECOUNT NextCloud Apps require updates"
fi

Do mind that some hardcoded parts i’m not that happy with yet, but for now it serves its purpose (again, on my end)

best regards,

  • Glowsome
1 Like

Seems alot has changed in v29.0.0 of Nextcloud.

Therefore from this version on i have to re-evaluate the whole localcheck (with input from @gebra )

I will adapt the localcheck, but changes regarding expected output are quite extensive, so i will need time to re-evaluate all.

  • Glowsome

Update on the Localcheck β†’ i have finally had a bit of time to look into this, and with a few adaptations i’ve made it work again.
Unfortunately (not my style) some output had to be hard-coded into the script.

But here goes :

#basepath of Nextcloud's occ executable

BASEPATH="/var/www/html"

# set the correct user for running the commands ( either apache or www-data )

APACHEUSER="apache"

# check if jq package is present on the system

/usr/bin/which jq >/dev/null 2>&1
if [ $? -ne 0 ]; then
    echo "2 \"NextCloud\" - NextCloud localcheck requires jq package to be installed"
    echo "2 \"NextCloud Apps\" - NextCloud localcheck requires jq package to be installed"
    exit;
fi

# Get current installed Nextcloud version-information
# in v29.x.x version gives more detail, which is not given by the check on installed version, so switched to versionstring instead.

NCINSTALLED=$(sudo -u $APACHEUSER php $BASEPATH/occ status --output=json | jq -r '.versionstring')

# Get latest avaiable version information
# In v29.x.x this has changed outputs <name-of-instance> <version,

NCAVAILABLE=$(sudo -u $APACHEUSER php $BASEPATH/occ update:check -V | tr -d '\n' | awk '{print $3}' | cat)

# compare resuts of installed and available version and report update available if they differ
if [ $NCINSTALLED != $NCAVAILABLE ]; then
   echo "1 \"NextCloud\" - A new NextCloud version ($NCAVAILABLE)is available, running version $NCINSTALLED please upgrade"
else
    sudo -u $APACHEUSER php $BASEPATH/occ status -e
    if [ $? -eq 0 ]; then
        echo "0 \"NextCloud\" - NextCloud all up to date"
    elif [ $? -eq 1 ]; then
        echo "1 \"NextCloud\" - NextCloud maintenance-mode is enabled"
    elif [ $? -eq 2 ]; then
        echo "2 \"NextCloud\" - NextCloud Core needs updating"
    fi
fi

APPRESULT=$(sudo -u $APACHEUSER php $BASEPATH/occ app:update --showonly)
if [[ $APPRESULT == *"All apps are up-to-date"* ]]; then
    echo "0 \"NextCloud Apps\" - NextCloud Apps all up to date"
else
    UPDATECOUNT=$(echo "$APPRESULT" | wc -l)
    echo "1 \"NextCloud Apps\" - $UPDATECOUNT NextCloud Apps requires updates"
fi

Happy Monitoring (again)

  • Glowsome

Hi all,

Just to keep things aligned, i have chosen to no longer post code-updates regarding this (and others) due to me having to maintain updates in a/the post.

Instead use the link to my git-repository: https://git.comsolve.nl/Comsolve/Checkmk-Development
The repository holds all (code-)changes i make to (local-)checks, datasources and/or Special agents.

  • Glowsome

Hi all,

Version 1.3 of the/this Localcheck has been released at my repository: nextcloud-updates.sh v1.3

Improvements:

  • Validate if a/the configured user in the localcheck exists (if not throw a CRIT)
  • Validate basepath for Nextcloud exists (if not throw a CRIT)
  • added comments to clarify where this file should be placed for it to be picked up by CheckMK Agent.

Happy monitoring !

  • Glowsome

Fun fact:

i’ve had cases where the check was quicker in reporting updates then a/the Nextcloud instance itself :rofl:

  • Glowsome

Hi all,

Version 1.4 of the/this Localcheck has been released at my repository: nextcloud-updates.sh v1.4

Improvement(s):

  • added logic to deal with no response (or empty) from the release-url of Nextcloud. (check timed out previously) - throw a WARN.

Happy Monitoring !

  • Glowsome

I have a request for a new feature. Below is the code diff that makes it work. I don’t care about patch level (31.0.Y) changes. I do care about minor and major version updates. I made the following changes to accomplish this in my environment:

diff /usr/lib/check_mk_agent/local/nextcloud-updates*
#insert at line 35
> # ───────────────────────────────────────────────────────────────────
> # how many β€œ.”-separated fields to compare:
> #  3 β†’ XX.YY.ZZ  (full)
> #  2 β†’ XX.YY     (major+minor)
> #  1 β†’ XX        (major only)
> VERSION_FIELDS=2
> # ───────────────────────────────────────────────────────────────────


< NCINSTALLED=$(sudo -u $APACHEUSER php $BASEPATH/occ status --output=json | jq -r '.versionstring')
---
> NCINSTALLED=$(sudo -u $APACHEUSER php $BASEPATH/occ status --output=json | jq -r '.versionstring'|cut -d. -f1-"$VERSION_FIELDS")


< NCAVAILABLE=$(curl -s --connect-timeout 5 --fail-with-body $RELEASEURL | sed -e 's/<[^>]*>//g' | grep -o "^nextcloud.*.zip" | tail -n1 | cut -d'-' -f 2 | sed 's/.\{4\}$//')
---
> NCAVAILABLE=$(curl -s --connect-timeout 5 --fail-with-body $RELEASEURL | sed -e 's/<[^>]*>//g' | grep -o "^nextcloud.*.zip" | tail -n1 | cut -d'-' -f 2 | sed 's/.\{4\}$//'|cut -d. -f1-"$VERSION_FIELDS")

This code change allows users to specify the level of version checking they want by changing a single variable.

Additionally, maybe add a link to how to make the local check cached in the top of the script so people can have the results cached? It doesn’t have to execute with every agent execution. I put mine in 86400/ so it runs once a day. That’s frequently enough for me. The individual user can choose how often to update the check.

Thanks for the plugin! It’s going to help me stay on top of updates much better.

1 Like

Hi @briand ,

Nice suggestion, i implemented it, also added some more explanation regarding cached. :+1:

So now we are at v1.5 :muscle:

  • Glowsome
1 Like