#!/usr/bin/bash
#
# test_updates
#
# fehlende Patche des Servers ans ULS
#
if [[ $# -lt 2 ]]; then
  DT=`date '+%F %T%:z'`
else
  DT="$1 $2"
fi
#
# list updates
#
if [[ -x /usr/bin/zypper ]]; then
  if zypper -h 2>&1 | fgrep -q 'list-patches'; then
    P=list-patches
  else
    P=lu
  fi

  zypper --non-interactive ref &>/dev/null
  zypper --non-interactive $P 2>/dev/null | tee /tmp/Patche.txt | egrep -v "^---|^Catalog" | \
  awk -v DT="$DT" 'BEGIN {ke=0; se=0; re=0}
       /kernel.*security/ {ke++}
       /security/ {se++ }
       /recommended/ {re++}
      END { system("send_test_line Security Updates " DT " kernel:" ke ": security:" se-ke ": recommended:" re ":") }'
  send_file_value Security Updates Patche $DT /tmp/Patche.txt
fi
#
#
PD=$(date -d@"$(rpm -qa --qf '%{INSTALLTIME}\n' 2>&1 | sort -rn | head -1)" '+%F %T')
if [[ -n "$PD" ]]; then
  send_test_value System Info 'Last Software Install' $DT "$PD" '{DT}'
fi
