Add timestamp option for checkresult test script

refs #9055
This commit is contained in:
Michael Friedrich 2015-04-24 16:01:58 +02:00
parent 1664430c9f
commit 0f3d46c61a
1 changed files with 10 additions and 7 deletions

View File

@ -28,7 +28,8 @@ usage: $0 options
-H Host name for the check result
-S Service name for the check result. If not provided, a host check result is assumed.
-r Return code of the check result
-o Output of the checkresult
-o Output of the check result
-T Timestamp of the check result
EOF
}
@ -38,9 +39,10 @@ CMDFILE="/var/run/icinga2/cmd/icinga2.cmd"
HOST=""
SERVICE=""
RETURNCODE=0
OUTPUT="icinga2 extcmdfile test @ `date +%s`"
TIMESTAMP="`date +%s`"
OUTPUT="icinga2 extcmdfile test @ $TIMESTAMP"
while getopts ":c:H:S:r:o:h" opt; do
while getopts ":c:H:S:r:o:T:h" opt; do
case $opt in
h)
usage
@ -61,6 +63,9 @@ while getopts ":c:H:S:r:o:h" opt; do
o)
OUTPUT=$OPTARG
;;
T)
TIMESTAMP=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
@ -74,8 +79,6 @@ while getopts ":c:H:S:r:o:h" opt; do
esac
done
DATETIME=`date +%s`
if [ -z "$HOST" ]; then
echo "Host name missing. Please use -H with a valid host name."
usage
@ -83,9 +86,9 @@ if [ -z "$HOST" ]; then
fi
if [ -z "$SERVICE" ]; then
CMDLINE="[$DATETIME] PROCESS_HOST_CHECK_RESULT;$HOST;$RETURNCODE;$OUTPUT"
CMDLINE="[$TIMESTAMP] PROCESS_HOST_CHECK_RESULT;$HOST;$RETURNCODE;$OUTPUT"
else
CMDLINE="[$DATETIME] PROCESS_SERVICE_CHECK_RESULT;$HOST;$SERVICE;$RETURNCODE;$OUTPUT"
CMDLINE="[$TIMESTAMP] PROCESS_SERVICE_CHECK_RESULT;$HOST;$SERVICE;$RETURNCODE;$OUTPUT"
fi
echo "Sending '$ECHO $CMDLINE >> $CMDFILE'"