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.
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
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)
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