Saminnet-Search Article Wiki Forum Blog SNS Cloud
TSM Report

TSM Report

Depending on the status of the result, you 'll have different colors green (OK), orange (WARNING), red (CRITICAL)

root@tsmsrv - /root/scripts > cat .env
# global variables for all scripts
export binpath=/root/scripts
export sn=`basename $0 | cut -d. -f1`
export HOSTNAME=`/usr/bin/hostname`
export logpath=/root/scripts/logs
export logname=$logpath/$sn.log
export configfile=$binpath/$sn.cfg
export destination="
 This email address is being protected from spambots. You need JavaScript enabled to view it.
 "
export mail_undeliverable="
 This email address is being protected from spambots. You need JavaScript enabled to view it.
 "
root@tsmsrv - /root/scripts > cat tsm _daily _report.cfg
export tsm_admin=admin
export tsm_password=passwd
export tsmservers="TSMS74 TSMC75"
export tsmemailreceiver="
 This email address is being protected from spambots. You need JavaScript enabled to view it.
 "
export node_expired="NODE1,NODE2"                # excluded nodes and filespace from expired report
root@tsmsrv - /root/scripts > cat tsm_daily_report.sh
#!/bin/ksh93
#set -x
#====================================================================
#@(#) Script to generate a HTML report on TSM activity
#       format of line before HMTL :
#          html_tag;nagios_tag;reserved;output_from_select_TSM
#====================================================================
# version 1.0
# version 1.1 report send by mail
# version 1.2 suppress unused informations
# version 1.3 add statistics on 5 latest daily backups, and dedup stats
# version 1.4 add expired nodes and filespaces

dir=`dirname $0`
. $dir/.env
. $configfile

os=$(uname -s | tr 'A-Z' 'a-z')

if [[ $os == "aix" ]]
then
  # Needs rpm package coreutil
  DATE_BIN=/opt/freeware/bin/date
  if [ ! -x /opt/freeware/bin/date ]
  then
    echo "Install coreutil package"
    exit 1
  fi
  DSMADMC1="/usr/tivoli/tsm/client/ba/bin64/dsmadmc -id=${tsm_admin} -pa=${tsm_password}"
  HOSTNAME=$(/usr/bin/hostname -s)
else
  if [[ $os == "linux" ]]
  then
    DATE_BIN=/bin/date
    DSMADMC1="/opt/tivoli/tsm/client/ba/bin/dsmadmc -id=${tsm_admin} -pa=${tsm_password}"
    HOSTNAME=$(/bin/hostname -s)
  else
    echo "ERROR: Unknown OS"
    exit 1
  fi
fi

expired=30 # number of days before node or filespace is consider as obsolet

YESTERDAY=$($DATE_BIN +%Y-%m-%d -d "1 day ago")
TODAY=$($DATE_BIN +%Y-%m-%d)
EXPIRED=$($DATE_BIN +%Y-%m-%d -d "$expired day ago")

OPT_COMMA="-comma"
OPT_TAB="-tab"
OPT_DATAONLY="-dataonly=yes"

tmplog=$logpath/tmp
TMPFILE=$tmplog/tsm_daily_result
min_scr=3               # Minimum number of scratch per library

#NAGIOSTAG="0=OK, 1=WARNING, 2=CRITICAL, 3=UNKNOWN"
COLOR[0]="#57E964"      # green
COLOR[1]="#F87217"      # orange #F7BE81
COLOR[2]="#FF2400"      # red    #DF013A
COLOR[3]="yellow"       # yellow #F3F781
COLOR[4]="#56A5EC"      # blue
COLOR[5]="#FFFFFF"      # white
#FFA500 : orange

TAG=TAG    # reserved for future
apachehost="
 This email address is being protected from spambots. You need JavaScript enabled to view it.
 "
apachepath="/var/www/htdocs"

db_log ()
{
echo "# Collect db_log"
# DB
db_info=$($DSMADMC $OPT_COMMA $OPT_DATAONLY "select DATABASE_NAME,TOT_FILE_SYSTEM_MB,USED_DB_SPACE_MB from db")
echo "TH;4;TAG;DB/LOG_NAME;TOTAL_FILESYSTEM_SIZE_GB;PERCENT_USED" > $TMPFILE.db_log
filesys_sz=$(echo $db_info | cut -d',' -f2)
filesys_used=$(echo $db_info | cut -d',' -f3)
db_name=$(echo $db_info | cut -d',' -f1)
(( filesys_sz_gb = filesys_sz / 1024 ))
(( pct_used = 100 * filesys_used / filesys_sz ))

if [ "$pct_used" -gt "90" ]
then
  NAGIOSTAG=2
else
  if [ "$pct_used" -gt "80" ]
  then
    NAGIOSTAG=1
  else
    NAGIOSTAG=0
  fi
fi
echo "TD;$NAGIOSTAG;$TAG;$db_name;$filesys_sz_gb;${pct_used} %" >> $TMPFILE.db_log

# Logs
log_info=$($DSMADMC $OPT_COMMA $OPT_DATAONLY "select TOTAL_SPACE_MB,USED_SPACE_MB,ARCHLOG_TOL_FS_MB,ARCHLOG_USED_FS_MB from log")
filesys_sz=$(echo $log_info | cut -d',' -f1)
filesys_used=$(echo $log_info | cut -d',' -f2)
(( filesys_sz_gb = filesys_sz / 1024 ))
(( pct_used = 100 * filesys_used / filesys_sz ))
NAGIOSTAG=0
echo "TD;$NAGIOSTAG;$TAG;ACTIVE_LOG;$filesys_sz_gb;${pct_used} %" >> $TMPFILE.db_log

filesys_sz=$(echo $log_info | cut -d',' -f3)
filesys_used=$(echo $log_info | cut -d',' -f4)
(( filesys_sz_gb = filesys_sz / 1024 ))
(( pct_used = 100 * filesys_used / filesys_sz ))

if [ "$pct_used" -gt "90" ]
then
  NAGIOSTAG=2
else
  if [ "$pct_used" -gt "80" ]
  then
    NAGIOSTAG=1
  else
    NAGIOSTAG=0
  fi
fi
echo "TD;$NAGIOSTAG;$TAG;ARCHIVE_LOG;$filesys_sz_gb;${pct_used} %" >> $TMPFILE.db_log
}

backup_vm ()
{
echo "# Collect backup_vm"
#ACTIVITY_DETAILS: VMware

$DSMADMC $OPT_COMMA $OPT_DATAONLY "select TO_CHAR(CHAR(START_TIME),'YYYY-MM-DD HH24:MI:SS') as START_TIME,TO_CHAR(CHAR(END_TIME),'YYYY-MM-DD HH24:MI:SS') as END_TIME,SUB_ENTITY as NODE_NAME,SCHEDULE_NAME,SUCCESSFUL,TRANSLATE('a bc:de:fg', DIGITS(END_TIME-START_TIME), '_______abcdefgh_____',' ') as ELAPTIME,cast(float(bytes)/1024/1024/1024 as dec(8,2)) as GB from summary_extended where ACTIVITY_DETAILS='VMware' and ACTIVITY<>'EXPIRATION' and SUB_ENTITY<>'' and START_TIME>=current_timestamp-24 hours" | sed 's/,/;/g' | sed 's/\ /|/g' | egrep -v "ANR2034E|ANS8001I" > $TMPFILE

echo "TH;4;TAG;START_TIME;END_TIME;NODE_NAME;SCHEDULE_NAME;SUCCESSFUL;ELAPTIME;GB" > $TMPFILE.backup_vm

cat $TMPFILE | while read line
do
  status=$(echo $line | cut -d';' -f5)
  if [ "$status" == "YES" ]
  then
    NAGIOSTAG=0
  else
    NAGIOSTAG=2
  fi
  echo "TD;$NAGIOSTAG;$TAG;$line" >> $TMPFILE.backup_vm
done
}

read_events ()
{
echo "# Collect events"
# Suppress REASON and add ELAPTIME : SCHEDULED_START;ACTUAL_START;DOMAIN_NAME;SCHEDULE_NAME;NODE_NAME;STATUS;RESULT;REASON;COMPLETED;ELAPTIME
$DSMADMC $OPT_COMMA $OPT_DATAONLY "select TO_CHAR(CHAR(SCHEDULED_START),'YYYY-MM-DD HH24:MI:SS') as SCHEDULED_START,TO_CHAR(CHAR(ACTUAL_START),'YYYY-MM-DD HH24:MI:SS') as ACTUAL_START,DOMAIN_NAME,SCHEDULE_NAME,NODE_NAME,STATUS,RESULT,TO_CHAR(CHAR(COMPLETED),'YYYY-MM-DD HH24:MI:SS') as COMPLETED,TRANSLATE('a bc:de:fg', DIGITS(COMPLETED-ACTUAL_START), '_______abcdefgh_____',' ') as ELAPTIME from events where SCHEDULED_START>=current_timestamp-24 hours" | egrep "$YESTERDAY|$TODAY" | sed 's/,/;/g' | sed 's/\ /|/g' > $TMPFILE
#echo "Client Schedules"
echo "TH;4;TAG;SCHEDULED_START;ACTUAL_START;DOMAIN_NAME;SCHEDULE_NAME;NODE_NAME;STATUS;RESULT;COMPLETED;ELAPTIME" > $TMPFILE.client
#echo "Admin Schedules"
echo "TH;4;TAG;SCHEDULED_START;ACTUAL_START;SCHEDULE_NAME;STATUS;RESULT;COMPLETED;ELAPTIME" > $TMPFILE.admin

cat $TMPFILE | while read line
do
  status=$(echo $line | cut -d';' -f6)
  if [ "$status" != "Future" ]
  then
    DOMAIN_NAME=$(echo $line | cut -d';' -f3)
    if [ "$DOMAIN_NAME" = "" ]
    then
      # Admin schedule
      if [ "$(echo $line | cut -d';' -f6-7)" = "Completed;0" ]
      then
        NAGIOSTAG=0
      else
        if [ "$status" = "Completed" ]
        then
          NAGIOSTAG=1
        else
          if [[ "$status" = "Started" || "$status" = 'In|Progress'  ]]
          then
            NAGIOSTAG=3
          else
            NAGIOSTAG=2
          fi
        fi
      fi
      line1=$(echo $line | cut -d';' -f1-2,4,6-)
      echo "TD;$NAGIOSTAG;$TAG;$line1" >> $TMPFILE.admin.$NAGIOSTAG
    else
      # Client schedule
      if [ "$(echo $line | cut -d';' -f6-7)" = "Completed;0" ]
      then
        NAGIOSTAG=0
      else
        if [ "$status" = "Completed" ]
        then
          NAGIOSTAG=1
        else
          if [[ "$status" = "Started" ]] || [[ "$status" = 'In|Progress' ]]
          then
            NAGIOSTAG=3
          else
            NAGIOSTAG=2
          fi
        fi
      fi
      echo "TD;$NAGIOSTAG;$TAG;$line" >> $TMPFILE.client.$NAGIOSTAG
    fi
  fi
done

$DSMADMC $OPT_COMMA $OPT_DATAONLY "SELECT activity, cast(float(sum(bytes))/1024/1024/1024 as dec(8,2)) as GB FROM summary WHERE activity<>'TAPE MOUNT' AND activity<>'EXPIRATION' AND start_time >current_timestamp-24 hours  GROUP BY activity" | sed 's/,/;/g' | sed 's/\ /|/g' > $TMPFILE.activitytotal
echo "TH;4;TAG;BACKUP;ARCHIVE;RESTORE;RETRIEVE;FULL_DBBACKUP;STGPOOL|BACKUP;DELETE|FILESPACE;MIGRATION;RECLAMATION;SW|MIGRATION" > $TMPFILE.total
value1=""
for act in $(head -1 $TMPFILE.total | cut -d';' -f4- | sed 's/;/\ /g')
do
  value=$(grep "^$act;" $TMPFILE.activitytotal | cut -d';' -f2)
  value1="$value1;$value"
done
echo "TD;5;TAG$value1" >> $TMPFILE.total

$DSMADMC $OPT_COMMA $OPT_DATAONLY "select SEVERITY,TO_CHAR(CHAR(DATE_TIME),'YYYY-MM-DD HH24:MI:SS') as DATE,ORIGINATOR,NODENAME,SCHEDNAME,DOMAINNAME,MESSAGE from actlog where ( SEVERITY='W' or SEVERITY='E' ) and date_time>=current_timestamp-24 hours" | sed 's/\ /|/g' | sed 's/;/\-/g' | sort > $TMPFILE.actlog
echo "TH;4;TAG;DATE_TIME;ORIGINATOR;NODENAME;SCHEDNAME;DOMAINNAME;MESSAGE ID;MESSAGE" > $TMPFILE.error

cat $TMPFILE.actlog | egrep -v "ANR2034E|ANR1701E|ANR2111W|ANR2992W" | sed 's/^W/3;TAG/g' |  sed 's/^E/2;TAG/g' | sed 's/^/TD;/g' | sed 's/,/;/1' | sed 's/,/;/1' | sed 's/,/;/1' | sed 's/,/;/1' | sed 's/,/;/1' | sed 's/,/;/1' | sed 's/|/;/2' | sed 's/"//g' >> $TMPFILE.error
}

stgpool_stats ()
{
# Add 10-2015
echo "TH;4;TAG;STGPOOL_NAME;STGPOOL_SIZE_GB" >> $TMPFILE.stgpool_occ
$DSMADMC $OPT_COMMA $OPT_DATAONLY "select stgpool_name,sum(logical_mb)/1024 from occupancy group by stgpool_name" | sed 's/,/;/g' | sed 's/\ /\|/g' > $TMPFILE.stgpool_occ.tmp
cat $TMPFILE.stgpool_occ.tmp | sed 's/^/TD;5;TAG;/' >> $TMPFILE.stgpool_occ
rm  $TMPFILE.stgpool_occ.tmp

echo "TH;4;TAG;STGPOOL_NAME;POOLTYPE;DEVCLASS;DEDUPLICATE;EST_CAPACITY_MB;PCT_UTILIZED;PCT_LOGICAL;MAXSCRATCH;NUMSCRATCHUSED;SPACE_SAVED_MB;DEDUP_RATE(%);DEDUP_RATIO" > $TMPFILE.stgpool_stats
$DSMADMC $OPT_COMMA $OPT_DATAONLY "select STGPOOL_NAME,POOLTYPE,DEVCLASS,DEDUPLICATE,EST_CAPACITY_MB,PCT_UTILIZED,PCT_LOGICAL,MAXSCRATCH,NUMSCRATCHUSED,SPACE_SAVED_MB from stgpools" | sed 's/,/;/g' | sed 's/\ /\|/g' > $TMPFILE.stgpool_stats.tmp

for line in $(cat $TMPFILE.stgpool_stats.tmp)
do
  MAXSCRATCH=$(echo $line | cut -d';' -f8)
  MAXSCRATCHUSED=$(echo $line | cut -d';' -f9)
  if [[ $MAXSCRATCH -eq "" ]]
  then
    NAGIOSTAG=0
  else
    if [ $MAXSCRATCH = 0 ]
    then
      if [ $MAXSCRATCHUSED = 0 ]
      then
        NAGIOSTAG=0
      else
        NAGIOSTAG=2
      fi
    else
      (( pctused = 100 * MAXSCRATCHUSED / MAXSCRATCH ))
      if [ $pctused -gt 90 ]
      then
        NAGIOSTAG=2
      else
        NAGIOSTAG=0
      fi
    fi
  fi
  SAVEDMB=$(echo $line | cut -d';' -f10)
  if [[ $SAVEDMB -ne "" ]]
  then
    typeset -F2 SAVEDMB STOREDMB ESTCAPMB PCTUTIL PCTDEDUP RATIO
    ESTCAPMB=$(echo $line | cut -d';' -f5)
    PCTUTIL=$(echo $line | cut -d';' -f6)
    (( STOREDMB = ( ESTCAPMB * PCTUTIL / 100 ) ))
    (( PCTDEDUP = 100 * SAVEDMB / ( SAVEDMB + STOREDMB ) ))
    (( RATIO = ( SAVEDMB + STOREDMB ) / STOREDMB ))
    pctdedup=$(printf "%.1f\n" $PCTDEDUP)
    ratio=$(printf "%.1f\n" $RATIO)
    end=$(echo "$pctdedup;$ratio"":1")
  else
    end=$(echo ";")
  fi
  echo "TD;$NAGIOSTAG;$TAG;$line;$end" >> $TMPFILE.stgpool_stats
done
rm $TMPFILE.stgpool_stats.tmp
}

check_library ()
{
echo "# Collect check_library"
COUNT='count(*)'
echo "TH;4;TAG;Library_name;scratch" > $TMPFILE.scratch
for libr in $($DSMADMC $OPT_TAB $OPT_DATAONLY "select LIBRARY_NAME from libraries" | egrep -v "^ANR|^ANE|^ANS")
do
  library=$(echo $libr | sed "s/^/\'/" | sed "s/$/\'/")
  scr=$($DSMADMC $OPT_COMMA $OPT_DATAONLY "select $COUNT as Scratch  from libvolumes WHERE status='Scratch' and library_name=$library")
  line=$(echo "$libr $scr")
  echo $line | sed 's/\ /\;/g' >> $TMPFILE.scratch1
done

#$DSMADMC $OPT_COMMA $OPT_DATAONLY "select library_name,$COUNT as Scratch  from libvolumes WHERE status='Scratch' group by library_name" | sed 's/,/;/g' | sed 's/\ /|/g' > $TMPFILE.scratch1

echo "TH;4;TAG;DESTINATION_TYPE;ONLINE;OFFLINE" > $TMPFILE.paths
$DSMADMC $OPT_COMMA $OPT_DATAONLY "select DESTINATION_TYPE,ONLINE from paths" | egrep -v "^ANR|^ANE|^ANS" | sed 's/,/;/g' | sed 's/\ /|/g' > $TMPFILE.paths1
    
echo "TH;4;TAG;LIBRARY_NAME;DRIVE_NAME;DEVICE_TYPE;ONLINE" > $TMPFILE.drives
$DSMADMC $OPT_COMMA $OPT_DATAONLY "select LIBRARY_NAME,DRIVE_NAME,DEVICE_TYPE,ONLINE from drives" | egrep -v "^ANR|^ANE|^ANS" | sed 's/,/;/g' | sed 's/\ /|/g' > $TMPFILE.drives1

NAGIOSTAG=0
TAG=TAG
for line in $(cat $TMPFILE.scratch1)
do
  if [ $(echo $line | cut -d';' -f2) -le $min_scr ]
  then
    NAGIOSTAG=2
  else
    NAGIOSTAG=0
  fi
  echo "TD;$NAGIOSTAG;$TAG;$line" >> $TMPFILE.scratch
done
rm $TMPFILE.scratch1

for type in $(cat $TMPFILE.paths1 | cut -d';' -f1 | sort | uniq)
do
  online=$(cat $TMPFILE.paths1 | grep "^$type" | cut -d';' -f2 | grep 'YES' | wc -l | awk '{print $1}')
  offline=$(cat $TMPFILE.paths1 | grep "^$type" | cut -d';' -f2 | grep -v 'YES' | wc -l | awk '{print $1}')
  if [ "$offline" -eq "0" ]
  then 
    NAGIOSTAG=0
  else
    if [ "$offline" -ge "$online" ]
    then
      NAGIOSTAG=2
    else
      NAGIOSTAG=1
    fi
  fi
  echo "TD;$NAGIOSTAG;$TAG;$type;$online;$offline" >> $TMPFILE.paths
done
rm $TMPFILE.paths1

for line in $(cat $TMPFILE.drives1)
do
  end=$(echo $line | cut -d';' -f4)
  if [ "$end" != "YES" ]
  then
    NAGIOSTAG=1
    echo "TD;$NAGIOSTAG;$TAG;$line" >> $TMPFILE.drives
  fi
done
for library in $(cat $TMPFILE.drives1 | cut -d';' -f1 | sort | uniq)
do
  online=$(cat $TMPFILE.drives1 | grep "^$library" | cut -d';' -f4 | grep 'YES' | wc -l | awk '{print $1}')
  total=$(cat $TMPFILE.drives1 | grep "^$library" | wc -l | awk '{print $1}') 
  ((offline = total - online))
  type=$(cat $TMPFILE.drives1 | grep "^$library" | cut -d';' -f3 | tail -1)
  if [ "$offline" -eq "0" ]
  then
    NAGIOSTAG=0
  else
    if [ "$offline" -ge "$online" ]
    then
      NAGIOSTAG=2
    else
      NAGIOSTAG=1
    fi 
  fi
  echo "TD;$NAGIOSTAG;$TAG;$library;"'|'";$type;$online"'|/|'"$total" >> $TMPFILE.drives
done
rm $TMPFILE.drives1
}

check_volume_error ()
{
echo "# Collect check_volume_error"
echo "TH;4;TAG;VOLUME_NAME;ACCESS;WRITE_ERRORS;READ_ERRORS" > $TMPFILE.volume_error
$DSMADMC $OPT_COMMA $OPT_DATAONLY "select VOLUME_NAME,ACCESS,WRITE_ERRORS,READ_ERRORS from volumes where ACCESS<>'READWRITE' and ACCESS<>'OFFSITE'" | sed 's/,/;/g' | sed 's/\ /|/g' | egrep -iv "found|return"| sed "s/^/TD;2;$TAG;/" >> $TMPFILE.volume_error
$DSMADMC $OPT_COMMA $OPT_DATAONLY "select VOLUME_NAME,ACCESS,WRITE_ERRORS,READ_ERRORS from volumes where WRITE_ERRORS<>'0' or READ_ERRORS<>'0'" | sed 's/,/;/g' | sed 's/\ /|/g' | egrep -iv "found|return" | sed "s/^/TD;1;$TAG;/" >> $TMPFILE.volume_error
}

auditocc ()
{
echo "# Collect auditocc"
NAGIOSTAG=0
TAG=TAG
echo "TH;4;TAG;NODE_NAME;BACKUP_MB;BACKUP_COPY_MB;ARCHIVE_MB;ARCHIVE_COPY_MB;TOTAL_MB;LASTACC_DATE;DOMAIN_NAME" > $TMPFILE.auditocc
#$DSMADMC $OPT_COMMA $OPT_DATAONLY "select NODE_NAME,BACKUP_MB,BACKUP_COPY_MB,ARCHIVE_MB,ARCHIVE_COPY_MB,TOTAL_MB from auditocc order by TOTAL_MB desc" | sed 's/,/;/g' | sed 's/\ /|/g' | sed "s/^/TD;$NAGIOSTAG;$TAG;/" >> $TMPFILE.auditocc
$DSMADMC $OPT_COMMA $OPT_DATAONLY "select n.NODE_NAME,a.BACKUP_MB,a.BACKUP_COPY_MB,a.ARCHIVE_MB,a.ARCHIVE_COPY_MB,a.TOTAL_MB,DATE(n.lastacc_time) as LASTACC_DATE,n.DOMAIN_NAME from  nodes n, auditocc a WHERE n.node_name=a.node_name order by TOTAL_MB desc" | sed 's/,/;/g' | sed 's/\ /|/g' | sed "s/^/TD;$NAGIOSTAG;$TAG;/" >> $TMPFILE.auditocc
}

daily_backuparch_per_node ()
{
echo "# Collect daily_backuparch_per_node"
NAGIOSTAG=0
TAG=TAG
HEADER="TH;4;TAG;DOMAIN_NAME;NODE_NAME"

$DSMADMC $OPT_COMMA $OPT_DATAONLY "SELECT node_name,domain_name FROM nodes"  | sed 's/,/;/g' | sed 's/\ /|/g' | sed 's/$/;/' > $TMPFILE.qnode

for days in {0..5}
do
  (( BEGIN = 24 * days ))
  (( END = (24 * days) + 24 ))
  HEADER=$(echo ${HEADER}';'DAY-${days}'(GB)')

  $DSMADMC $OPT_COMMA $OPT_DATAONLY "SELECT entity,cast(float(sum(bytes)) / 1024 / 1024 / 1024 AS DECIMAL(8,2)) as GB FROM summary where ( activity='ARCHIVE' OR activity='BACKUP' ) AND end_time>current_timestamp-$END hours and end_time<current_timestamp-$BEGIN hours GROUP BY entity"  | sed 's/,/;/g' | sed 's/\ /|/g' | grep -v '^;' | egrep -v "ANR2034E|ANS8001I" > $TMPFILE.daily_backup-arch_per_node.tmp

  cat /dev/null > $TMPFILE.daily_backup-arch_per_node.$days
  for line in $(cat $TMPFILE.daily_backup-arch_per_node.tmp)
  do
    node_name=$(echo $line | awk -F'|' '{print $1}' | awk -F';' '{print $1}')
    dom=$(grep "^$node_name;" $TMPFILE.qnode | cut -d';' -f2)
    line2=$(echo $line | cut -d';' -f2)
    echo "${dom};${node_name};${line2}" >> $TMPFILE.daily_backup-arch_per_node.$days
  done

  # Keep only 1 line per node
  cat /dev/null > $TMPFILE.daily_backup-arch_per_node.tmp
  for line in $(cat $TMPFILE.daily_backup-arch_per_node.$days)
  do
    domnode=$(echo $line | cut -d';' -f1,2)
    grep "^$domnode;" $TMPFILE.daily_backup-arch_per_node.tmp > /dev/null 2>&1
    if [ $? -ne 0 ]
    then
      numoccurence=$(grep "^$domnode;" $TMPFILE.daily_backup-arch_per_node.$days | wc -l | awk '{print $1}')
      if [ "$numoccurence" -gt 1 ]
      then
        final_amount="0.00"
        for amount in $(grep "^$domnode;" $TMPFILE.daily_backup-arch_per_node.$days | cut -d';' -f3)
        do
          final_amount=$(echo "${final_amount} + ${amount}" | bc | sed 's/^\./0\./')
        done
        echo "$domnode;$final_amount" >> $TMPFILE.daily_backup-arch_per_node.tmp
      else
        echo "$line" >> $TMPFILE.daily_backup-arch_per_node.tmp
      fi
    fi
  done
  mv $TMPFILE.daily_backup-arch_per_node.tmp $TMPFILE.daily_backup-arch_per_node.$days
done

if [ ! -f $TMPFILE.daily_backup-arch_per_node ]
then
  cat $TMPFILE.daily_backup-arch_per_node.* | cut -d';' -f1,2 | sort | uniq > $TMPFILE.daily_backup-arch_per_node
fi

count=0
while [[ $count -le $days ]] 
do
  cat $TMPFILE.daily_backup-arch_per_node | sed 's/$/;/' > $TMPFILE.daily_backup-arch_per_node.tmp
  for line in $(cat $TMPFILE.daily_backup-arch_per_node.${count})
  do
    domnode=$(echo $line | cut -d';' -f1,2)
    value=$(echo $line | cut -d';' -f3)
    grep "^$domnode;" $TMPFILE.daily_backup-arch_per_node.tmp > /dev/null 2>&1
    if [ $? -eq 0 ]
    then
        sed -e "/$domnode;/ s/$/$value/" $TMPFILE.daily_backup-arch_per_node.tmp > $TMPFILE.daily_backup-arch_per_node
        mv $TMPFILE.daily_backup-arch_per_node $TMPFILE.daily_backup-arch_per_node.tmp
    else
        echo "ERROR: field not found"
    fi
  done
  mv $TMPFILE.daily_backup-arch_per_node.tmp $TMPFILE.daily_backup-arch_per_node
  count=$(expr $count + 1)
done
mv $TMPFILE.daily_backup-arch_per_node $TMPFILE.daily_backup-arch_per_node.tmp
echo $HEADER > $TMPFILE.daily_backup-arch_per_node
cat $TMPFILE.daily_backup-arch_per_node.tmp | sort | sed "s/^/TD;$NAGIOSTAG;$TAG;/" >> $TMPFILE.daily_backup-arch_per_node
rm $TMPFILE.daily_backup-arch_per_node.* 
}

admin_shedule_status ()
{
echo "# Collect admin_shedule_status"
$DSMADMC $OPT_COMMA $OPT_DATAONLY "select START_TIME,END_TIME,TRANSLATE('a bc:de:fg', DIGITS(end_time-start_time), '_______abcdefgh_____',' ') as ELAPTIME,ENTITY,SUCCESSFUL from summary where ACTIVITY='PROCESS_END' and START_TIME>=current_timestamp-24 hours" | sed 's/,/;/g' | sed 's/\ /|/g' > $TMPFILE.sum_admin.tmp

echo "TH;4;TAG;SCHEDULED_START;SCHEDULED_STOP;DURATION;ADMIN_TASK;STATUS" > $TMPFILE.sum_admin

cat $TMPFILE.sum_admin.tmp | egrep "^$YESTERDAY|^$TODAY" | sort | while read line
do
  status=$(echo $line | cut -d';' -f5)
  if [ "$status" == "YES" ]
  then
    NAGIOSTAG=0
  else
    NAGIOSTAG=2
  fi
  echo "TD;$NAGIOSTAG;$TAG;$line" >> $TMPFILE.sum_admin
done

rm $TMPFILE.sum_admin.tmp
}

check_expired_data ()
{
echo "# Collect expired filespaces"
$DSMADMC $OPT_COMMA $OPT_DATAONLY "select NODE_NAME,FILESPACE_NAME,FILESPACE_ID,FILESPACE_TYPE,CAPACITY,PCT_UTIL,to_char(char(BACKUP_START),'YYYY-MM-DD') as LAST_ACCESS from filespaces where node_name<>'' order by node_name" | sed 's/,/;/g' | sed 's/\ /|/g' | sed -e 's/"//g' -e "s/'//g" | sed -e 's/\\a/\\A/g' -e 's/\\b/\\B/g' -e 's/\\c/\\C/g' -e 's/\\f/\\F/g' -e 's/\\n/\\N/g' -e 's/\\r/\\R/g' -e 's/\\t/\\T/g' -e 's/\\v/\\V/g' | sed -e 's/^/"/' -e "s/^/'/" | sed -e 's/$/"/' -e "s/$/'/" > $TMPFILE.filespaces_last_access.tmp

echo "TH;4;TAG;NODE_NAME;FILESPACE_NAME;FILESPACE_ID;FILESPACE_TYPE;CAPACITY;PCT_UTIL;LAST_ACCESS" > $TMPFILE.filespaces_last_access

for line in $(cat $TMPFILE.filespaces_last_access.tmp)
do
  end=$(echo $line | cut -d';' -f7 | sed -e 's/"//g' -e "s/'//g")
  node=$(echo $line | cut -d';' -f1 | sed -e 's/"//g' -e "s/'//g")
  node_exception=$(echo ${node_expired} | sed -e 's/^/;/' -e 's/,/;\|;/g' -e 's/$/;/')
  if [ $(echo ";$node;" | egrep "${node_exception}" > /dev/null;echo $?) -eq 0 ]
  then
    NAGIOSTAG=4
  else
    if [[ "$end" < "$EXPIRED" ]]
    then
      NAGIOSTAG=1
    else
      NAGIOSTAG=0
    fi
  fi
  echo "TD;$NAGIOSTAG;$TAG;$line" | sed -e 's/"//g' -e "s/'//g" >> $TMPFILE.filespaces_last_access
done

rm $TMPFILE.filespaces_last_access.tmp

echo "# Collect expired nodes"
$DSMADMC $OPT_COMMA $OPT_DATAONLY "SELECT node_name,domain_name,platform_name,client_os_level,TRIM(CHAR(client_version))||'.'||TRIM(CHAR(client_release))||'.'||TRIM(CHAR(client_level))||'-'||TRIM(CHAR(client_sublevel)) as TSM_Version,DATE(lastacc_time) AS LASTACC_TIME FROM nodes order by node_name" | sed 's/,/;/g' | sed 's/\ /|/g' > $TMPFILE.nodes_last_access.tmp

echo "TH;4;TAG;NODE_NAME;DOMAIN_NAME;PLATFORM_NAME;CLIENT_OS_LEVEL;TSM_LEVEL;LAST_ACCESS" > $TMPFILE.nodes_last_access

for line in $(cat $TMPFILE.nodes_last_access.tmp)
do
  end=$(echo $line | cut -d';' -f6)
  node=$(echo $line | cut -d';' -f1)
  node_exception=$(echo ${node_expired} | sed -e 's/^/;/' -e 's/,/;\|;/g' -e 's/$/;/')
  if [ $(echo ";$node;" | egrep "${node_exception}" > /dev/null;echo $?) -eq 0 ]
  then
    NAGIOSTAG=4
  else
    if [[ "$end" < "$EXPIRED" ]]
    then
      NAGIOSTAG=1
    else
      NAGIOSTAG=0
    fi
  fi
  echo "TD;$NAGIOSTAG;$TAG;$line" >> $TMPFILE.nodes_last_access
done

rm $TMPFILE.nodes_last_access.tmp
}

convert_html ()
{
#<TABLE BORDER="1" style="background:#FFFF00">
#  <CAPTION> Voici le titre du tableau </CAPTION>
#  <TR style="background:#80BFFF"><TH> Titre A1 </TH><TH> Titre A2 </TH><TH> Titre A3 </TH><TH> Titre A4 </TH></TR>
#  <TR style="background:#00FF00"><TH> Titre B1 </TH><TD> Valeur B2 </TD><TD> Valeur B3 </TD><TD> Valeur B4 </TD></TR>
#  <TR><TH> Titre B1 </TH><TD> Valeur B2 </TD><TD> Valeur B3 </TD><TD> Valeur B4 </TD></TR>
#</TABLE>
server=$1

echo '<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<h1>TSM Report' $server $(date "+%d-%m-%Y %H:%M")'</h1>
<body>
<br>
<h2>TSM events</h2>
<br>
<table border="1">
<tbody>'

for i in db_log admin volume_error scratch stgpool_stats paths drives client backup_vm error total sum_admin stgpool_occ auditocc daily_backup-arch_per_node filespaces_last_access nodes_last_access
do
  nb_line=$(cat $TMPFILE.$i* | wc -l)
  if [ "$nb_line" -gt "1" ]
  then
    echo '<h3>TSM '$(echo $i)'</h3><br>'
    cat $TMPFILE.$i* > $TMPFILE.tempo
    for nb in 0 1 2 3 4 5
    do
      for begin in TH TD
      do
        cat $TMPFILE.tempo | sed "s/^$begin;$nb;TAG;/\<TR\ style=\"background:${COLOR[$nb]}\"><TD>/g" > $TMPFILE.tempo1
        mv $TMPFILE.tempo1 $TMPFILE.tempo
      done
    done
    cat $TMPFILE.tempo | sed 's/;/<\/TD><TD>/g' | sed 's/|/\ /g' | sed 's/$/<\/TD><\/TR>/g'
    echo '</tbody>
</table>
<table border="1">
<tbody>
<BR><BR>'
  fi
done


echo '
</body>
</html>'
}

copy_to_apache ()
{
if [ -s $htmlfile ]
then
  #scp $htmlfile $apachehost:$apachepath
  newname=$(echo $htmlfile | sed "s/_${TODAY}//" | rev | cut -d'/' -f1 | rev)
  cp $htmlfile /home/lpar2rrd/lpar2rrd/www/$newname
  mv $htmlfile /report/TSM
fi
}

send_email ()
{
newname=$(echo $htmlfile | rev | cut -d'/' -f1 | rev)
uuencode $htmlfile $newname | mailx -r "${HOSTNAME}
 This email address is being protected from spambots. You need JavaScript enabled to view it.
 " -s "TSM daily report $TODAY from location $server" $tsmemailreceiver
}

main ()
{
date
for server in $(echo $tsmservers)
do
  echo "********Collecting info on TSM server: $server"
  mkdir -p $tmplog
  DSMADMC=$(echo "$DSMADMC1 -se=$server")
  rm  $TMPFILE* 2> /dev/null
  htmlfile=$logpath/tsm_daily_report_${TODAY}_${server}.html
  db_log
  backup_vm
  read_events
  check_library
  check_volume_error
  auditocc
  stgpool_stats
  admin_shedule_status
  daily_backuparch_per_node
  check_expired_data
  convert_html $server 1> $htmlfile
  send_email $server
  #copy_to_apache
  rm $TMPFILE*
done

date
}

main > $logname 2>&1

Comments   

 
0 #1 Guest 2018-10-19 14:40
SEO is now the thorn in lots of on-line advertising specialists facet.
The truth is that companies that are not using professional internet marketing agencies
to assist them with their own marketing all have not included regional into marketing
and their web internet sites, meaning that they are likely getting penalized now from the top search engines.


my weblog ... Malinda
Quote
 

Articles by Date

Category Database

TweetTweet Share on LinkedInShare on LinkedIn Share on Google+Google+ Submit to RedditReddit Publish on WordPress WordPress Send emailSend email