#!/bin/bash # Wrapper for nagioscheck4updates # Documentation: http://tech.nnx.com/doku.php?id=start:developpement:joomla:nagioscheck4updates if [ 3 -ne $# ] ; then echo "Wrong parameters." echo "Usage : $0 web_site username password" exit fi site=$1 user=$2 pass=$3 url="http://$site/index.php?option=com_nagioscheck4updates" # Var NAGIOS STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 STATE_DEPENDENT=4 # Get status ret=$(wget -q -O - "$url" --user="$user" --password="$pass") nbl=$(echo -e "$ret"|wc -l) # Check the content of the page if [ 2 -ne $nbl ] ; then echo "Problem: there is $nbl line instead of 2" echo -e "$ret" exit $STATE_UNKNOWN fi state=$(echo -e "$ret" | head -n 1) comment=$(echo -e "$ret" | tail -n 1) # Check informations of the Joomla! component if [[ ! "$state" =~ [0-4] ]] ; then echo "Problem: -$state- should be a number between 0 and 4" exit $STATE_UNKNOWN fi # Return informations echo $comment exit $state