Wenn man Software nicht aus den Repositories einer Distribution, sondern von Hand installiert, muss man immer im Blick haben, ob fuer die Software nicht ein Update zur Verfuegung steht
Um sich dieses fuer Piwik zu vereinfachen habe ich dafuer ein sehr simples Nagios Plugin, check_piwik.sh, geschrieben:
#!/bin/bash
#####
#
# Simple Skript that checks if Piwik version from given URL is up to date
#
# Usage: ./check_piwik.php http://example.net/piwik/ MYTOKEN
#
#####
## check if two parameters are given
if [ "$#" -lt "2" ]; then echo -e "ERROR: You need to give two parameter, first option is URL and second option Token . Aborting." >&2 exit 1; fi
PIWIKURL="$1"
TOKEN="$2"
## check if needed programs are installed
type -P curl &> /dev/null || { echo "ERROR: curl is required but seems not to be installed. Aborting." >&2 exit 1; }
type -P sed &> /dev/null || { echo "ERROR: sed is required but seems not to be installed. Aborting." >&2 exit 1; }
## get latest piwik version from piwik api
LATESTVERSION=$(curl -s http://api.piwik.org/1.0/getLatestVersion/)
## get piwik version from given url
LOCALURL="$PIWIKURL/index.php?module=API&method=API.getPiwikVersion&format=xml&token_auth=$TOKEN"
LOCALVERSION=$(curl -s $LOCALURL | sed -n -e 's/.*<result>\(.*\)<\/result>.*/\1/p')
## compare both strings
if [ "$LATESTVERSION" != "$LOCALVERSION" ]; then
echo "A new version is available: $LOCALVERSION -> $LATESTVERSION"
exit 2
else
echo "Your current version $LOCALVERSION is up to date"
fi |
#!/bin/bash
#####
#
# Simple Skript that checks if Piwik version from given URL is up to date
#
# Usage: ./check_piwik.php http://example.net/piwik/ MYTOKEN
#
#####
## check if two parameters are given
if [ "$#" -lt "2" ]; then echo -e "ERROR: You need to give two parameter, first option is URL and second option Token . Aborting." >&2 exit 1; fi
PIWIKURL="$1"
TOKEN="$2"
## check if needed programs are installed
type -P curl &> /dev/null || { echo "ERROR: curl is required but seems not to be installed. Aborting." >&2 exit 1; }
type -P sed &> /dev/null || { echo "ERROR: sed is required but seems not to be installed. Aborting." >&2 exit 1; }
## get latest piwik version from piwik api
LATESTVERSION=$(curl -s http://api.piwik.org/1.0/getLatestVersion/)
## get piwik version from given url
LOCALURL="$PIWIKURL/index.php?module=API&method=API.getPiwikVersion&format=xml&token_auth=$TOKEN"
LOCALVERSION=$(curl -s $LOCALURL | sed -n -e 's/.*<result>\(.*\)<\/result>.*/\1/p')
## compare both strings
if [ "$LATESTVERSION" != "$LOCALVERSION" ]; then
echo "A new version is available: $LOCALVERSION -> $LATESTVERSION"
exit 2
else
echo "Your current version $LOCALVERSION is up to date"
fi
Es erwartet zwei Parameter, eine URL zu dem Piwik das ueberprueft werden soll, und den API Token fuer diese Installation. Dementsprechend muss in der command.cfg der Check wie folgt definiert werden:
define command {
command_name check_piwik
command_line $USER1$/check_piwik.sh $ARG1$ $ARG2$
} |
define command {
command_name check_piwik
command_line $USER1$/check_piwik.sh $ARG1$ $ARG2$
}
Der Check selbst wird dann wie folgt in die entsprechende Konfigurationsdatei eingetragen:
define service {
use my-service
host_name example.net
service_description Piwik
check_command check_piwik!http://example.net/piwik!abcdefghijklmnopqrstuvwxyz123
} |
define service {
use my-service
host_name example.net
service_description Piwik
check_command check_piwik!http://example.net/piwik!abcdefghijklmnopqrstuvwxyz123
}
Fertig eingerichtet bekommt man dann von seinem Nagios Auskunft ueber den Updatestatus der entsprechenden Installation: