
#!/bin/sh
# File	: upd_atostechlab-status.sh
# By	: Maarten.deBoer@Atos.net, 210106
# Subject	: Script to update status of Atos TechLab
#(0.2)	: Removed 1st &2nd part of IP
PGM=`basename $0|cut -d\. -f1`
VER="0.2"
TMP="/tmp/${PGM}.$$"
LOG="${HOME}/log/${PGM}.log"
DATI=`date +%Y-%m-%d-%H-%M-%S`

PAGE="/var/www/vhosts/status.atostechlab.nl/html/index.html"
PREV_PAGE="/var/www/vhosts/status.atostechlab.nl/html/index_${DATI}.html"
DATA_CSV="${HOME}/data/atostechlab-status.csv"

COLOR="white"
BGCOLOR="#0066A1"
TBORDER=0
FSIZE=5
FFACE="Verdana"

if [ ! -f ${PAGE} ]; then
  echo "  PAGE (${PAGE}) NOT found. Exiting ..."|tee -a ${LOG}
  exit 3
fi
if [ ! -f ${DATA_CSV} ]; then
  echo "  DATA(CSV) (${DATA_CSV}) NOT found. Exiting ..."|tee -a ${LOG}
  exit 4
fi

echo "`date` ${PGM} v${VER} started."|tee -a ${LOG}
touch ${TMP}

# Creating HEAD
echo "<!DOCTYPE HTML> " > ${TMP}
echo "<HTML> " >> ${TMP}
echo "  <HEAD> " >> ${TMP}
echo "  <META NAME='generator' content='Agrarix.IT:${PGM} v${VER}' /> " >> ${TMP}
echo "  <META NAME='up-date' content='${DATI}' /> " >> ${TMP}
echo "  <meta http-equiv='Content-Language' content='en-us'>" >> ${TMP}
echo "  <meta http-equiv='Content-Type' content='text/html; charset=windows-1252'>" >> ${TMP}
echo "  <meta name='author' content='Maarten@Agrarix.IT' />" >> ${TMP}

echo "  <link rel="icon" href="TechLab_logo.png" type="image/png">" >> ${TMP}

echo "  <title>AtosTechLab</title>" >> ${TMP}
echo "  </HEAD> " >> ${TMP}
echo "  <BODY aLink=white link=white vLink=white>" >> ${TMP}

# 1st TABLE
echo "<TABLE class='table1-class' border=${TBORDER} width='100%' id='table1' cellpadding='0' cellspacing='0'> " >> ${TMP}

echo "  <tr>" >> ${TMP}
echo "    <td>" >> ${TMP}
echo "      <table class='table2-class' border=${TBORDER} width='100%' id='table2' cellspacing='0'> " >> ${TMP}
echo "  <TR>" >> ${TMP}
echo "    <TD> <A HREF="//atos.net"><IMG SRC="Logo_Atos_215x72_RGB.jpg"></A></TD>" >> ${TMP}
echo "    <TD> <A HREF="//www.atostechlab.nl"><IMG SRC="Atos_Technology-Lab-banner-black-blue-150.png" height="100"></A></TD>" >> ${TMP}
echo "    <TD> <CENTER> <H1> STATUS page </H1> </CENTER> </TD>" >> ${TMP}
echo "  </TR>" >> ${TMP}
echo "</TABLE>" >> ${TMP}
echo "    </td>" >> ${TMP}
echo "  </tr>" >> ${TMP}

echo "  <tr>" >> ${TMP}
echo "    <td>" >> ${TMP}
echo "    <table class='table3-class' border=${TBORDER} width='100%' id='table3' cellspacing='0'> " >> ${TMP}
echo "      <tr>" >> ${TMP}
echo "        <td bgcolor="${BGCOLOR}" width="5">" >> ${TMP}
echo "        </td>" >> ${TMP}
echo "        <td bgcolor="${BGCOLOR}" align='left' height="30">" >> ${TMP}
echo "          <font size='2' color=white face=${FFACE}> " >> ${TMP}
echo "            <a href='//atos.net' target="_blank"> <B>Atos</a>  " >> ${TMP}
echo "            <a href='//myatos.net' target="_blank"> <B>MyAtos</a>  " >> ${TMP}
echo "          </font>" >> ${TMP}
echo "        </td>" >> ${TMP}

echo "        <td bgcolor="${BGCOLOR}" align='right'>" >> ${TMP}

echo "          <font size='2' color=white face=${FFACE}>" >> ${TMP}
echo "          For updates:" >> ${TMP}
echo "          </font>" >> ${TMP}
echo "          <a href='mailto:maarten@agrarix.it?subject=atostechlab.nl' target="_blank">" >> ${TMP}
echo "            <font size='2' color=white face=${FFACE}>" >> ${TMP}
echo "              <B>Contact</B>" >> ${TMP}
echo "            </font>" >> ${TMP}
echo "          </a>" >> ${TMP}
echo "        </td>" >> ${TMP}
echo "        <td bgcolor="${BGCOLOR}" width="5">" >> ${TMP}
echo "        </td>" >> ${TMP}
echo "      </tr>" >> ${TMP}
echo "    </table>" >> ${TMP}

echo "    </td>" >> ${TMP}
echo "  </tr>" >> ${TMP}

echo "  <tr>" >> ${TMP}
echo "    <td>" >> ${TMP}

echo "    <table class='table4-class' border=${TBORDER} id='table4' cellspacing='0'> " >> ${TMP}

echo "      <tr width=100%>" >> ${TMP}
echo "        <TH bgcolor=${STATUS_COL}><font size=${FSIZE} color=${BGCOLOR} face=${FFACE}> DATE+TIME </TH>" >> ${TMP}
echo "        <TH bgcolor=${STATUS_COL}><font size=${FSIZE} color=${BGCOLOR} face=${FFACE}> CHECK </TH>" >> ${TMP}
echo "        <TH bgcolor=${STATUS_COL}><font size=${FSIZE} color=${BGCOLOR} face=${FFACE}> NAME </TH>" >> ${TMP}
echo "        <TH bgcolor=${STATUS_COL}><font size=${FSIZE} color=${BGCOLOR} face=${FFACE}> IP </TH>" >> ${TMP}
echo "        <TH bgcolor=${STATUS_COL}><font size=${FSIZE} color=${BGCOLOR} face=${FFACE}> STATUS </TH>" >> ${TMP}
echo "      </tr>" >> ${TMP}
# STATUS's
cat ${DATA_CSV}|grep -v ^#|sort|while read LINE
do
  echo "  ${LINE}"
  CSV_DATI=`echo ${LINE}|awk -F\; '{print $1}'`
  NAME=`echo ${LINE}|awk -F\; '{print $2}'|cut -d\. -f1`
  IP="x.x.`echo ${LINE}|awk -F\; '{print $3}'|cut -d\. -f3,4`"
  STATUS=`echo ${LINE}|awk -F\; '{print $4}'|awk '{print $1}'`
  STATUS_COL=`echo ${LINE}|awk -F\; '{print $4}'|cut -d\( -f2|cut -d\) -f1`
  CHECK=`echo ${LINE}|awk -F\; '{print $5}'`
  echo "  ${CSV_DATI}:${CHECK}:${NAME}(${IP})=${STATUS}(${STATUS_COL})"

echo "  <tr width=100%>" >> ${TMP}
echo "    <td bgcolor=${STATUS_COL}>" >> ${TMP}
echo "      <font size=${FSIZE} color=white face=${FFACE}><CENTER>${CSV_DATI}</font>" >> ${TMP}
echo "    </td>" >> ${TMP}
echo "    <td bgcolor=${STATUS_COL}>" >> ${TMP}
echo "      <font size=${FSIZE} color=white face=${FFACE}><CENTER>${CHECK}</font>" >> ${TMP}
echo "    </td>" >> ${TMP}
echo "    <td bgcolor=${STATUS_COL}>" >> ${TMP}
echo "      <font size=${FSIZE} color=white face=${FFACE}><CENTER>${NAME}</font>" >> ${TMP}
echo "    </td>" >> ${TMP}
echo "    <td bgcolor=${STATUS_COL}>" >> ${TMP}
echo "      <font size=${FSIZE} color=white face=${FFACE}><CENTER>${IP}</font>" >> ${TMP}
echo "    </td>" >> ${TMP}
echo "    <td bgcolor=${STATUS_COL}>" >> ${TMP}
echo "      <font size=${FSIZE} color=white face=${FFACE}><CENTER>${STATUS}</font>" >> ${TMP}
echo "    </td>" >> ${TMP}
echo "  </tr>" >> ${TMP}

done  # cat ${DATA_CSV}

echo "      </table>" >> ${TMP}
echo "    </td>" >> ${TMP}
echo "  </tr>" >> ${TMP}


# Last row
cat << EOT >> ${TMP}
  <tr>
    <td bgcolor=${BGCOLOR} align='center'>
      <a href='//agrarix.it' target="_blank">
        <font size='1' color=${COLOR} face='Arial'>
Design by Agrarix-IT
        </font>
      </a>
    </td>
  </tr>
EOT

# End of 1st table
echo "</TABLE>" >> ${TMP}
# table1

echo "  </BODY>" >> ${TMP}
echo "</HTML>" >> ${TMP}




cp ${PAGE} ${PREV_PAGE}
cp ${TMP} ${PAGE}
rm ${TMP}
echo "`date` ${PGM} v${VER} finished."|tee -a ${LOG}
exit 0

