Überwachen von Joomla und der Componenten via Nagios
- Details
- Geschrieben von Bastian Schmoll
- Veröffentlicht: 22. Januar 2014
- Zugriffe: 17916
Bei meinem letztem Script habe ich die Möglichkeit gehabt die Joomla Versionen 1.5.x bis 3.x zu prüfen. Im Genansatz zu dem anderen Script prüft dieses Script auch fast alle Installierten Versionen der Komponenten und ist in einigen Fällen sogar präziser als die eingebaute Routine bei Joomla.
Da ich mehrere Versionen installiert habe, sollte das Nagios Script einfach auf die verschiedenen Ordner angepasst werden können.
Übersicht:
Mit diesem Nagios Script ist es möglich verschiedene Installationen von Joomla 2.5.x und 3.x zu prüfen, ob diese und die Komponenten auf dem aktuellen Stand sind. Sollte z.B. die Version 2.5.14 installiert sein meldet das Script, dass es die Joomla Version 2.1.16 gibt. Das Script basiert auf bash und wurde unter Ubuntu 12.04 entworfen. Das Script kann einfach in dem Plugin-Ordner von Nagios abgelegt werden. Dieser befindet sich bei einer Nagios 3 Installation unter /usr/lib/nagios/plugins/. Das Script wird später in der commands.cfg von Nagios eingebunden.
Ihr könnt das Script auch auf der Shell einfach testen: ./check_joomla_comp_update.sh <Ordner>
Als <Ordner> wird das Installationsverzeichnis von Joomla angegeben. z.B. joomla. Sollten eure Seiten nicht unter /var/www liegen schreibt einfach den richtigen Ordner in die Variable.
Das Script
check_joomla_comp_update.sh v.1.8.3 | ||
check_joomla_comp_update.sh v.1.9 |
check_joomla_comp_update.sh:
#!/bin/bash ### # Simple bash script to check if Joomla and components up to date. # VERSION: 1.8.3 # author: Bastian Schmoll # mail: info@bastcom.de # changelog: # 1.0: initial VERSION # 1.1: Fix Bug in Nagios Status Information View # 1.2: Fix Bug if Version comp = 1.0 and fix bug show no or wrong stat if a ERROR # 1.3: Add Joomla 3.x Version support # 1.4: Add German Language Support for Joomla 3.x # 1.5: Fix problem is the external VERSION shorter then the local VERSION # 1.6: Add Table extensions enable = 1. Don`t show disable updates. # 1.6.1: Fix some Bugs # 1.6.2 Add Option for lang in Joomla > 3.3 # 1.6.3 Remove Joomla! Extension Directory and Product Builder from check # 1.6.4 Add && [ "$REMOTEVERCH" != "0" ] if the xml empty # 1.7 Add multidomain and parameter SHOWNAME if it 1 show NAME @ the end of check # 1.7.1 Add TEMP Variable # 1.7.2 Add EXCLUDE Variable and clean up the code # 1.8 Add check if input argument set and fix some bugs # 1.8.1 Fix check Joomla gt 3.3 and fix check for OSMap # 1.8.2 Fix if the remote Version smaller the the local version # 1.8.3 Fix some problems with version numbers # 1.9 Fix some problems with Version 3.5 and above. Fix timeout with wget. Add WAITTIME variable for wget. #### # Check if argument is set if [ "$#" -eq "0" ] then echo "No arugments supplied" else # Config section WEBPATH=/var/www APPS=`echo $* | sed "s/ /\n/g"` LANG=pkg_de-DE SHOWNAME=0 WAITTIME=15 TEMP=tmp EXCLUDE="'Joomla Extension Directory', 'Joomla! Extension Directory', 'Slideshow CK Update', 'mediahof', 'JCE Pro', 'Product Builder', 'VirtueMart plg_vmpayment_paypal Update Site', 'Weblinks Update Site', 'WebInstaller Update Site', 'Accredited Joomla! Translations', 'CEGCore v1 update server'" # While read loop for Multidomain while read APP do # Unset Variable and Arrys unset IFS NAME=() VERSION=() VERSIONN=() IFVERSION=() IFREMOTEVERSION=() USER=`cat $WEBPATH/$APP/configuration.php | grep public | head -n14 | sed -e '1,13d' | sed 's/\(.*\)..$/\1/' | awk '{print $4}' | sed 's/^.//'` PASS=`cat $WEBPATH/$APP/configuration.php | grep public | head -n15 | sed -e '1,14d' | sed 's/\(.*\)..$/\1/' | awk '{print $4}' | sed 's/^.//'` DB=`cat $WEBPATH/$APP/configuration.php | grep public | head -n16 | sed -e '1,15d' | sed 's/\(.*\)..$/\1/' | awk '{print $4}' | sed 's/^.//'` PREFIX=`cat $WEBPATH/$APP/configuration.php | grep public | head -n17 | sed -e '1,16d' | sed 's/\(.*\)..$/\1/' | awk '{print $4}' | sed 's/^.//'` JOOMLANEWFILE=$WEBPATH/$APP/libraries/cms/version/version.php #Which Joomla Version we have? WHICHVERSION=`cat $JOOMLANEWFILE | grep public | head -n2 | sed -e '1d' | awk '{print $4}' | sed 's/\(.*\)..$/\1/' | sed 's/^.//' | sed 's/\.//g'` #Find no version? Try this. if [ -z $WHICHVERSION ]; then WHICHVERSION=`cat $JOOMLANEWFILE | grep RELEASE | head -n1 | awk '{print $4}' | sed 's/\(.*\)..$/\1/' | sed 's/^.//' | sed 's/\.//g'` fi #if Version 2.5 if [ "$WHICHVERSION" == 25 ]; then # Which Version we have LOCALVERSION=`echo -e $(mysql -u $USER -p$PASS $DB -se "SELECT T3.manifest_cache FROM "$PREFIX"update_sites_extensions T1 INNER JOIN "$PREFIX"update_sites T2 INNER JOIN "$PREFIX"extensions T3 ON T1.update_site_id = T2.update_site_id WHERE T1.extension_id = T3.extension_id AND T3.enabled = 1 AND T2.enabled = 1 AND T2.NAME NOT IN ($EXCLUDE)")` # Which Comp NAME we have LOCALNAME=`echo -e $(mysql -u $USER -p$PASS $DB -se "SELECT T2.NAME,'\n' FROM "$PREFIX"update_sites_extensions T1 INNER JOIN "$PREFIX"update_sites T2 INNER JOIN "$PREFIX"extensions T3 ON T1.update_site_id = T2.update_site_id WHERE T1.extension_id = T3.extension_id AND T3.enabled = 1 AND T2.enabled = 1 AND T2.NAME NOT IN ($EXCLUDE)")` # Build the List of XML urls XMLLIST=`echo -e $(mysql -u $USER -p$PASS $DB -se "SELECT T2.location FROM "$PREFIX"update_sites_extensions T1 INNER JOIN "$PREFIX"update_sites T2 INNER JOIN "$PREFIX"extensions T3 ON T1.update_site_id = T2.update_site_id WHERE T1.extension_id = T3.extension_id AND T3.enabled = 1 AND T2.enabled = 1 AND T2.NAME NOT IN ($EXCLUDE)") | sed -e "s/\ /\\n/g"` else # Which Version we have LOCALVERSION=`echo -e $(mysql -u $USER -p$PASS $DB -se "SELECT DISTINCT T3.manifest_cache FROM "$PREFIX"update_sites_extensions T1 INNER JOIN "$PREFIX"update_sites T2 INNER JOIN "$PREFIX"extensions T3 ON T1.update_site_id = T2.update_site_id WHERE T1.extension_id = T3.extension_id AND T3.enabled = 1 AND T2.enabled = 1 AND T2.NAME NOT IN ($EXCLUDE) AND T3.element != 'en-GB'")` # Which Comp NAME we have LOCALNAME=`echo -e $(mysql -u $USER -p$PASS $DB -se "SELECT DISTINCT T2.NAME,'\n' FROM "$PREFIX"update_sites_extensions T1 INNER JOIN "$PREFIX"update_sites T2 INNER JOIN "$PREFIX"extensions T3 ON T1.update_site_id = T2.update_site_id WHERE T1.extension_id= T3.extension_id AND T3.enabled = 1 AND T2.enabled = 1 AND T2.NAME NOT IN ($EXCLUDE)")` # Build the List of XML urls XMLLIST=`echo -e $(mysql -u $USER -p$PASS $DB -se "SELECT DISTINCT T2.location FROM "$PREFIX"update_sites_extensions T1 INNER JOIN "$PREFIX"update_sites T2 INNER JOIN "$PREFIX"extensions T3 ON T1.update_site_id = T2.update_site_id WHERE T1.extension_id = T3.extension_id AND T3.enabled = 1 AND T2.enabled = 1 AND T2.NAME NOT IN ($EXCLUDE)") | sed -e "s/\ /\\n/g"` fi # Build an array for the Versions IFVERSION+=(`echo -e $LOCALVERSION | grep version | sed 's/'","'/''/g' | sed 's/'\"'/''/g' | sed 's/':'/'\\\n'/g' | grep description | sed 's/description/''/g' | sed 's/\./''/g' | sed 's/[A-Z]*//g'`) # Only for human readable VERSIONN+=(`echo -e $LOCALVERSION | grep version | sed 's/'","'/''/g' | sed 's/'\"'/''/g' | sed 's/':'/'\\\n'/g' | grep description | sed 's/description/''/g'`) # Get remote Joomla VERSION from XML if [ -d /$TEMP/$APP ]; then rm /$TEMP/$APP/*.xml else mkdir /$TEMP/$APP fi Z=0 while read XML; do Z=$(($Z+1)) wget -T$WAITTIME -qO /$TEMP/$APP/"$Z".xml $XML #if Version 2.5.x if [ "$WHICHVERSION" == 25 ]; then # if Joomla 2.5.x: Which VERSION we found in XML VERSION+=(`cat /$TEMP/$APP/$Z.xml | sed "s/ /\n/g" | grep version | grep -v targetplatformversion | grep -v version=\"1.0\" | sed 's/'version'/''/g' | sed 's/'\<'/''/g' | sed 's/'\>'/''/g' | sed 's/'\"'/''/g' | sed 's/'\='/''/g' | sed -e 's/\///g' | sed '/^$/d' | sed -n '1p'`) VTEST=`cat /$TEMP/$APP/$Z.xml | sed "s/ /\n/g" | grep version | grep -v targetplatformversion | grep -v version=\"1.0\" | sed 's/'version'/''/g' | sed 's/infourl.*//' | sed 's/'\<'/''/g' | sed 's/'\>'/''/g' | sed 's/'\"'/''/g' | sed 's/'\='/''/g' | sed -e 's/\///g' | sed 's/\./''/g' | sed '/^$/d' | sed -n '1p' | sed -e "s/[^1234567890]//g"` else # If Joomla greater than 3.3 if [ "$Z" == "1" ] && [ "$WHICHVERSION" -gt "33" ]; then VERSIONTEST=(`cat /$TEMP/$APP/$Z.xml | sed "s/ /\n/g" | grep version | grep -v targetplatformversion | tail -n 2 | grep -v version=\"1.0\" | sed -n '2p' | sed 's/'version'/''/g' | sed 's/'\<'/''/g' | sed 's/'\>'/''/g' | sed 's/'\"'/''/g' | sed 's/'\='/''/g' | sed -e's/\///g' | sed 's/^[ \t]*//'`) VTEST=`cat /$TEMP/$APP/$Z.xml | sed "s/ /\n/g" | grep version | grep -v targetplatformversion | tail -n 2 | grep -v version=\"1.0\" | sed 's/infourl.*//' | sed -n '2p' | sed 's/'version'/''/g' | sed 's/'\<'/''/g' | sed 's/'\>'/''/g' | sed 's/'\"'/''/g' | sed 's/'\='/''/g' | sed -e 's/\///g' | sed 's/\./''/g' | sed -e "s/[^1234567890]//g"` elif [ "$Z" == "2" ] && [ "$WHICHVERSION" -gt "33" ] && [ "$WHICHVERSION" -lt "35" ]; then VERSIONTEST=(`cat /$TEMP/$APP/$Z.xml | grep $LANG | sed "s/ /\n/g" | grep version | grep -v targetplatformversion | tail -n 2 | grep -v version=\"1.0\" | sed -n '1p'| sed 's/'version'/''/g' | sed 's/'\<'/''/g' | sed 's/'\>'/''/g' | sed 's/'\"'/''/g' | sed 's/'\='/''/g' | sed -e's/\///g' | sed 's/^[ \t]*//'`) VTEST=`cat /$TEMP/$APP/$Z.xml | grep $LANG | sed "s/ /\n/g" | grep version | grep -v targetplatformversion | tail -n 2 | grep -v version=\"1.0\" | sed -n '1p' | sed 's/'version'/''/g' | sed 's/'\<'/''/g' | sed 's/'\>'/''/g' | sed 's/'\"'/''/g' | sed 's/'\='/''/g' | sed -e 's/\///g' | sed 's/\./''/g' | sed -e "s/[^1234567890]//g"` else # If Joomla 3.x VERSIONTEST=(`cat /$TEMP/$APP/$Z.xml | sed "s/ /\n/g" | grep version | grep -v targetplatformversion | tail -n 2 | grep -v version=\"1.0\" | sed -n '1p'| sed 's/'version'/''/g' | sed -e "s/git.*$//g" | sed 's/'\<'/''/g' | sed 's/'\>'/''/g' | sed 's/'\"'/''/g' | sed 's/'\='/''/g' | sed -e 's/\///g' | sed -e "s/[^1234567890.]//g" `) VTEST=`cat /$TEMP/$APP/$Z.xml | sed "s/ /\n/g" | grep version | grep -v targetplatformversion | tail -n 2 | grep -v version=\"1.0\" | sed 's/infourl.*//' | sed -n '1p' | sed 's/'version'/''/g' | sed 's/'\<'/''/g' | sed 's/'\>'/''/g' | sed 's/'\"'/''/g' | sed 's/'\='/''/g' | sed -e 's/\///g' | sed 's/\./''/g' | sed -e "s/[^1234567890]//g"` fi fi # Some XMLs dont have VERSION infos, replace this if [[ -z "$VERSIONTEST" ]]; then VERSION+=("0") else VERSION+=("$VERSIONTEST") fi # Some XMLs dont have VERSION infos, replace this if [[ $VTEST == 0 ]]; then IFREMOTEVERSION=`echo -e $IFREMOTEVERSION | sed -e "s/^.\{,1\}//"`; fi # Some XMLs dont have VERSION infos, replace this if [[ -z "$VTEST" ]]; then IFREMOTEVERSION+=("0") else IFREMOTEVERSION+=("$VTEST") fi done <<< "$XMLLIST" # Clean up the Names for human readable while read -r LNAME; do IFS="" NAME+=(`echo -e $LNAME | sed 's/ $//' | sed 's/^ //' `) done <<< "$LOCALNAME" # Clean up the .txt files cat /dev/null > /$TEMP/OK_$APP.txt cat /dev/null > /$TEMP/ERROR_$APP.txt # Now we check if we have the newest VERSION and build a file for ((i=0; i < ${#IFVERSION[*]}; i++)) do REMOTEVER=`echo ${IFREMOTEVERSION[i]} | wc -c` REMOTEVERCH=`echo ${IFREMOTEVERSION[i]}` LOCALVER=`echo ${IFVERSION[i]} | wc -c` NUMBER=`expr $LOCALVER - $REMOTEVER`; FIGURE=${IFREMOTEVERSION[i]}; REMOTEVER=`printf "$FIGURE%.${NUMBER}i\n"` if [ "$REMOTEVER" -eq "$REMOTEVER" ] 2>/dev/null then REMOTEVER=$REMOTEVER; else REMOTEVER="0"; fi VERSIONE=`echo ${VERSION[i]} | sed 's/[a-zA-Z]//g' | sed 's/'_'/'\\\n'/g' | sed "s/\:.*//"`; # Check if the external VERSION shorter then the local VERSION and not 0 whith NAME or whithout NAME if [ "$SHOWNAME" == "1" ]; then if [ "$REMOTEVER" -lt "$LOCALVER" ] && [ "$REMOTEVERCH" != "0" ]; then echo "A new VERSION is available: $VERSIONE Our Version of ${NAME[i]} (${VERSIONN[i]}) is out of date ($APP)." >> /$TEMP/ERROR_$APP.txt OK="ERROR" elif [ "${IFVERSION[i]}" -lt "${IFREMOTEVERSION[i]}" ] && [ "$REMOTEVERCH" != "0" ]; then echo "A new VERSION is available: $VERSIONE Our Version of ${NAME[i]} (${VERSIONN[i]}) is out of date ($APP)." >> /$TEMP/ERROR_$APP.txt OK="ERROR" else echo "Your current Version of ${NAME[i]} (${VERSIONN[i]}) is up to date ($APP)." >> /$TEMP/OK_$APP.txt fi else if [ "$REMOTEVER" -lt "$LOCALVER" ] && [ "$REMOTEVERCH" != "0" ]; then echo "A new VERSION is available: $VERSIONE Our Version of ${NAME[i]} (${VERSIONN[i]}) is out of date." >> /$TEMP/ERROR_$APP.txt OK="ERROR" elif [ "${IFVERSION[i]}" -lt "${IFREMOTEVERSION[i]}" ] && [ "$REMOTEVERCH" != "0" ]; then echo "A new VERSION is available: $VERSIONE Our Version of ${NAME[i]} (${VERSIONN[i]}) is out of date." >> /$TEMP/ERROR_$APP.txt OK="ERROR" else echo "Your current Version of ${NAME[i]} (${VERSIONN[i]}) is up to date." >> /$TEMP/OK_$APP.txt fi fi done # The last test if anything OK, say it, if not f**ck if [ "$OK" == ERROR ]; then cat /$TEMP/ERROR_$APP.txt exit 2 else cat /$TEMP/OK_$APP.txt fi done <<< "$APPS" fi
commands.cfg
Das Einbinden in die commands.cfg ist simpel. Ich habe das Script ganz unten in die Datei eingefügt:
# 'check_joomla_comp' command definition define command{ command_name check_joomla_comp_version command_line /bin/bash $USER1$/check_joomla_comp_update.sh $ARG1$ }
Service einbinden
Zum Schluss muss nur noch der check in der services.cfg Datei eingebunden werden.
define service{ use local-service host_name localhost service_description Joomla 2.5 Version and Components check_command check_joomla_comp_version!<Ordner> }