#!/bin/bash cd $(dirname $(readlink -f $0)) MAILTO=$1 . in_risk_vm_machines.env >$OUTPUT_FILE . govc.config if [[ -z $1 ]]; then echo "Hiba: nem adtal meg cimzettet! Helyes hasznalat:" echo "$0 email@cimem.hu[,email2@cimem.hu]" echo exit 1 fi #Kivetel lista felolvasasa [[ ! -e $EXCEPTION_FILE ]] && touch $EXCEPTION_FILE while read SOR; do EXCEPTIONS="$(echo $EXCEPTIONS | sed 's/^\s*//') $(echo $SOR | awk '{print $1}')" done <<< "`grep -v '^#' $EXCEPTION_FILE`" datediff() { d1=$(date -d "$1" +%s) d2=$(date -d "$2" +%s) echo $(( (d1 - d2) / 86400 )) } for VCENTER in $VCENTERS; do echo "${VCENTER#https://}" >> $OUTPUT_FILE printf "%-30s %-60s %-40s %-5s %-15s\n" "VM_NAME","RESOURCE_POOL","UUID","PW_ST","LAST_BACKUP" >>$OUTPUT_FILE export GOVC_URL="$VCENTER" ./govc find . -type p | sort | while read RESPOOL; do ./govc find "$RESPOOL" -type m | sed 's/^.*\///g' | sort | while read VM_NAME; do POWER_STATE=$(./govc vm.info "$VM_NAME" | awk -F':' '/Power state/{print $2}' | sed 's/ *powered//') UUID=$(./govc vm.info "$VM_NAME" | awk -F':' '/UUID/{print $2}' | sed 's/ *//') LAST_BACKUP=$(dsmadmc -id=$TSMUSER -pa=$TSMPASS -se=$TSMSERVER -dataonly=y "select BACKUP_DATE from backups where node_name='$TSMNODE' and hl_name like '\\$VM_NAME\\%' order by BACKUP_DATE desc FETCH FIRST 1 ROWS ONLY" | grep -v 'AN[RS]' | sed 's/^ //' | sed 's/\.000000$//') [[ -z $LAST_BACKUP ]] && LAST_BACKUP='NINCS MENTVE!' IN_RISK="" [[ $LAST_BACKUP =~ ^[2][0] && $(datediff "$(date '+%m/%d/%Y %H:%M:%S' )" "$LAST_BACKUP") -gt $IN_RISK_DAYS ]] && { LAST_BACKUP="$LAST_BACKUP ($IN_RISK_DAYS napnál régebbi!)"; IN_RISK='!!!'; } [[ ! "${EXCEPTIONS^^}" = *"${UUID^^}"* && -n $IN_RISK || $LAST_BACKUP =~ ^[^2][^0] ]] && printf "%-30s %-60s %-40s %-5s %-15s\n" "$VM_NAME","$RESPOOL","$UUID","($POWER_STATE)","$LAST_BACKUP" | sed 's/ *$//' >> $OUTPUT_FILE done done echo -e '
\n' >> $OUTPUT_FILE done echo '' > $OUTPUT_FILE.html; for VCENTER in $VCENTERS; do VCENTER=$(echo ${VCENTER#https://} | sed 's/\/.*$//') echo '

Régen mentett VMware hosztok

' >> $OUTPUT_FILE.html ROWNUM=1 echo '' >> $OUTPUT_FILE.html while read INPUT ; do [[ "$(echo $INPUT | grep -c '(Off)')" -eq 1 ]] && continue; # if [[ $(($ROWNUM % 2)) -eq 0 ]]; then ROWNUM=$(($ROWNUM+1)); fi if [[ $(echo $INPUT | grep -c '" >> $OUTPUT_FILE.html else if [[ $(echo $INPUT | grep -c 'VM_NAME') -gt 0 ]]; then [[ $(($ROWNUM % 2)) -eq 0 ]] && echo "" >> $OUTPUT_FILE.html || echo "" >> $OUTPUT_FILE.html else [[ $(($ROWNUM % 2)) -eq 0 ]] && echo "" >> $OUTPUT_FILE.html || echo "" >> $OUTPUT_FILE.html fi fi ROWNUM=$(($ROWNUM+1)) done <<< "`awk 'BEGIN{IGNORECASE=1;RS=ORS="\n\n";FS=OFS="\n"}/'${VCENTER}'/' $OUTPUT_FILE`" echo "
') -gt 0 ]]; then echo "$INPUT" >> $OUTPUT_FILE.html; elif [[ $(echo $INPUT | grep -c 'NINCS MENTVE') -gt 0 ]]; then echo "
${INPUT//,/}
${INPUT//,/}
${INPUT//,/}
${INPUT//,/}
${INPUT//,/}

" >> $OUTPUT_FILE.html echo '

Kikapcsolt VMware hosztok

' >> $OUTPUT_FILE.html ROWNUM=1 echo '' >> $OUTPUT_FILE.html while read INPUT ; do [[ "$(echo $INPUT | grep -c '(Off)')" -eq 0 ]] && continue; if [[ $(echo $INPUT | grep -c '" >> $OUTPUT_FILE.html else if [[ $(echo $INPUT | grep -c 'VM_NAME') -gt 0 ]]; then [[ $(($ROWNUM % 2)) -eq 0 ]] && echo "" >> $OUTPUT_FILE.html || echo "" >> $OUTPUT_FILE.html else [[ $(($ROWNUM % 2)) -eq 0 ]] && echo "" >> $OUTPUT_FILE.html || echo "" >> $OUTPUT_FILE.html fi fi ROWNUM=$(($ROWNUM+1)) done <<< "`awk 'BEGIN{IGNORECASE=1;RS=ORS="\n\n";FS=OFS="\n"}/'${VCENTER}'/' $OUTPUT_FILE`" echo "
') -gt 0 ]]; then echo "$INPUT" >> $OUTPUT_FILE.html; elif [[ $(echo $INPUT | grep -c 'NINCS MENTVE') -gt 0 ]]; then echo "
${INPUT//,/}
${INPUT//,/}
${INPUT//,/}
${INPUT//,/}
${INPUT//,/}
" >> $OUTPUT_FILE.html done echo "
Kivetelek: $EXCEPTIONS
" >> $OUTPUT_FILE.html echo "" >> $OUTPUT_FILE.html echo -e "To: $MAILTO\nMIME-Version: 1.0\nContent-Type: text/html\nContent-Disposition: inline\nSubject: TSM VM kockazat riport\n$(cat $OUTPUT_FILE.html)" > $OUTPUT_FILE.html cat $OUTPUT_FILE.html | sendmail -B 8BITMIME -t -F $EMAIL_FROM