#! /bin/sh
# @(#)getcpload         Version  1.00   5/12/98  Dow Corning Corp.
#
# this file is   getcpload
#
# This script file uses OM commands to produce a report of loading
# measurements for control stations (CP, MG, and AB stations). It
# was written to replace a Prelude spreadsheet that accomplishes
# the same task using OM function calls in Prelude.     
#
#################################################################
#
# COPYRIGHT NOTICE:
#
# Copyright ©1998 Duc M. Do (ducdo@mis.net). All rights reserved.
#
# This script file is being distributed as freeware. It may
# be used and modified by anyone, so long as this copyright
# notice and the header above remain intact. By using this
# script file, you agree to indemnify the author, Duc M. Do,
# from any liability.
#
# Selling the code for this script file without prior written
# consent is expressly forbidden. Please obtain permission
# before redistributing this script file over the Internet
# or by any other medium. In all cases, the copyright notice
# and header must remain intact.
#
#################################################################
#
# Revision History:
#
#  5/05/98  DMD         Original concept and script file
#  5/12/98  DMD  v1.00  working script

activate()
{
    ACTIVE=`/opt/fox/bin/tools/omget -v $1_STA:STATION.LODSW | \
           awk '{print $3}'`
    if [ $ACTIVE = FALSE ]
    then
        /opt/fox/bin/tools/omset -b TRUE $1_STA:STATION.LODSW
        sleep 5         # give the station block time to become active
    fi
}

getparm1()
{
    param=`/opt/fox/bin/tools/omget -v $1_STA:STATION.$2 | \
           awk '{printf("%7.1f"), $3}'`
}

getparm2()
{
    param=`/opt/fox/bin/tools/omget -v $1_STA:STATION.$2 | \
           awk '{printf("%5d"), $3}'`
}

if [ $# -eq 0 ]
then
    echo "\nUsage: `basename $0` CPlbug [CPlbug CPlbug ...] | all\n"
    exit
elif [ "$1" = "all" ]
then
    CPlist="`sort /etc/cplns`"
    PrintCount=1
else
    CPlist="$*"
    PrintCount=0
fi

PARM10="CPLOAD IOLOAD BPLOAD SQLOAD"
PARM30="CPLOAD IOLOAD BPLOAD SQLOAD OMLDAV IDLETM"
PARMALL="PP_TOT PP_DSC PP_DEL PP_NFD"
CP10=0
CP30=0
CP40=0

echo "CP Loading Report created on `date '+%A, %B %e, %Y at %r'` by DMDo\n"
echo "                        CP Loading (%)                Peer-to-Peer Status"
echo "         --------------------------------------------------------------"
echo "           Total    I/O   Cont    Seq    OM    Idle   Total  Pts  Pts Pts"
echo "         Control   Scan   Blks   Blks   Scan   Time    Pts  Disc  Del NF\n"

for sta in $CPlist
do
    activate $sta
    TYPE=`grep $sta /usr/fox/sp/hldb | awk '{print $2}'`
    if [ $TYPE = 201 -o $TYPE = 3001 ]          # CP-10 or MG-10
    then
        echo "$sta   \c"; CP10=`expr $CP10 + 1`
        for parm in $PARM10
        do
            getparm1 $sta $parm
            echo "$param\c"
        done
        echo "                \c"
        sleep 1
    elif [ $TYPE = 203 -o $TYPE = 204 -o $TYPE = 205 -o $TYPE = 3002 ]
    then
        if [ $TYPE != 205 ]
        then echo "$sta * \c"; CP30=`expr $CP30 + 1`
        else echo "$sta **\c"; CP40=`expr $CP40 + 1`
        fi
        for parm in $PARM30
        do
            getparm1 $sta $parm
            echo "$param\c"
        done
        echo "  \c"
        sleep 1
    fi
    for parm in $PARMALL
    do
        getparm2 $sta $parm
        echo "$param\c"
    done
    echo
    sleep 1
done
if [ $PrintCount -eq 1 ]
then
    if [ $CP10 -lt 10 ]; then CP10=" $CP10"; fi
    if [ $CP30 -lt 10 ]; then CP30=" $CP30"; fi
    if [ $CP40 -lt 10 ]; then CP40=" $CP40"; fi
    echo "\n                               -- Counts --"
    echo "Notes: unmarked: CP-10/MG-10   $CP10 FT Modules"
    echo "              *: CP-30/MG-30   $CP30 FT Modules"
    echo "             **: CP-40         $CP40 FT Modules"
else
    echo "\n\nNotes: unmarked: CP-10/MG-10"
    echo "              *: CP-30/MG-30"
    echo "             **: CP-40"
fi

#    ----  __0   ----  _~@ __@
#------  _`\<,_  --  _-\<,-\<,_
#  ---- (*)/ (*)    (*)/---/-(*)
#+-------------------------------+
#|   http://ducdo.iperweb.com/   |
#+-------------------------------+
#
1