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