]> granicus.if.org Git - icinga2/commitdiff
Add timestamp option for checkresult test script
authorMichael Friedrich <michael.friedrich@netways.de>
Fri, 24 Apr 2015 14:01:58 +0000 (16:01 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Fri, 24 Apr 2015 16:14:57 +0000 (18:14 +0200)
refs #9055

tools/scripts/process_check_result

index 229b671e73d15c002b9e4e705c0c798f7251c727..50cf7b1e5009660466d53d5e38270cea2f3ecf29 100755 (executable)
@@ -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'"