
#!/bin/sh
# File	: netapp_mdv-aud-volume_re-move.sh
# By	: Maarten.deBoer@Atos.net, 260119
# Subject : Script to remove & recreate MDV_aud-volumes
# Based on
#+ How to create or remove auditing staging (MDV_AUD) volumes
#- https://kb.netapp.com/on-prem/ontap/Ontap_OS/OS-KBs/How_to_create_or_remove_auditing_staging_MDV_AUD_volumes
#
PGM=`basename $0|cut -d\. -f1`
VER="0.1"
LOG="${HOME}/log/${PGM}.log"
SSH="/usr/bin/ssh -n"

CLUSTER="nlnaf199"
VSERVER="*"

if [ "${1}" != "" ]; then
  CLUSTER="${1}"
fi
if [ "${2}" != "" ]; then
  VSERVER="${2}"
fi

echo "`date` ${PGM} v${VER} started."|tee -a ${LOG}
echo "  CLUSTER=${CLUSTER}"
echo "  VSERVER=${VSERVER}"
sleep 1

${SSH} ${CLUSTER} "volume show -volume MDV_aud* -fields vserver,aggregate "

${SSH} ${CLUSTER} "vserver audit show -field vserver,state,destination,events"

ANSW=`${SSH} ${CLUSTER} "set -showseparator \";\" ; vserver audit show -vserver ${VSERVER} -field vserver,state,destination,events"|grep ${VSERVER}`
# nlnafsomi52;true;/omi52_vol10000/evt_arch;file-ops,cifs-logon-logoff,cap-staging,audit-policy-change;

STATE=`echo ${ANSW}|awk -F\; '{print $2}'`
DEST=`echo ${ANSW}|awk -F\; '{print $3}'`
EVENTS=`echo ${ANSW}|awk -F\; '{print $4}'`
echo "  STATE=${STATE}"|tee -a ${LOG}
echo "  DEST=${DEST}"|tee -a ${LOG}
echo "  EVENTS=${EVENTS}"|tee -a ${LOG}
if [ "${STATE}" = "" ] || [ "${DEST}" = "" ] || [ "${EVENTS}" = "" ]; then
  echo "    ONE of the var's is empty. Exiting ..."|tee -a ${LOG}
  exit 5
fi
sleep 2

echo "  Disable auditing for configured SVM"
${SSH} ${CLUSTER} "vserver audit disable -vserver ${VSERVER}"
echo "  And wait for 10 sec's"
sleep 10

echo "  Delete the auditing configuration for configured SVM."
${SSH} ${CLUSTER} "vserver audit delete -vserver ${VSERVER}"
sleep 2

echo "  Check for the presence of auditing volumes."
${SSH} ${CLUSTER} "volume show -volume MDV_aud* -fields aggregate"
sleep 2

echo "  Recreate the auditing configuration for SVM using the data collected in  previous step"
${SSH} ${CLUSTER} "vserver audit create -vserver ${VSERVER} -destination ${DEST}"
sleep 2

echo "  Enable the auditing configuration for SVM using the data collected in previous step"
${SSH} ${CLUSTER} "vserver audit enable -vserver ${VSERVER}"
sleep 2

echo "  Check for the presence of auditing volumes."
${SSH} ${CLUSTER} "volume show -volume MDV_aud* -fields aggregate"
${SSH} ${CLUSTER} "vserver audit show -vserver ${VSERVER} -field vserver,state,destination,events"

echo "`date` ${PGM} v${VER} finished."|tee -a ${LOG}
exit 0

