#!/bin/bash
#
# uls_stop_maint
#
# ULS Ueberwachungspause updaten
#
# Aufruf: uls_stop_maint [<section> [<teststep> [<detail>]]]
#
##########################################################
#
ULSTIMESTAMPFILE="/var/tmp/uls_maint_suspension_timestamp-$(id -u).dat"
#
if [[ "$1" == -* ]]; then
  echo "usage: $(basename $0) [<section> [<teststep> [<detail>]]]"
  exit
fi
#
if [[ -f "$ULSTIMESTAMPFILE" ]]; then
  read D T remark <<<"$(<$ULSTIMESTAMPFILE)"
else
  echo "Error: Timestampfile $ULSTIMESTAMPFILE not found."
  exit 1
fi
if echo "$D $T" | grep -q	 '^[2-9][0-9][0-9][0-9]-[01][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]'; then
  #
  # ULS Ueberwachungspause aendern
  if [[ -f /etc/uls/uls.conf ]]; then
    . /etc/uls/uls.conf
  fi
  #
  DTE=`date -d '+15 minute' '+%F %T%:z'`
  echo "PC;$D $T;$ULSHOSTNAME;${1:-*};$2;$3;$DTE;;;${remark:-Set by uls_start_maint for patching} ($(id -un))" | send_test_tab -S
  rm -f "$ULSTIMESTAMPFILE"
  #
else
  echo "Error: Wrong timeformat in Timestampfile $ULSTIMESTAMPFILE."
  exit 1
fi
