#!/bin/sh
# This script checks the Sentinel License Monitor on hosts
# and reports each key's usage and details.
# In your bb-hosts file, use the following syntax:
# sentinel[:port][,hexval=name[,hexval=name...]]
# Where port is the port for your Sentinel License Monitor (default 6002),
# hexval is 4 digits corresponding to the serial number, name is whatever.
# For example:
# 0.0.0.0 example1 # sentinel
# 0.0.0.0 examplep # sentinel:6202
# 0.0.0.0 examplen # sentinel,3573=Master,0045=Slave
# Note: this has only been tested with SuperPro keys.
#
# Requirements:
# wget and printf must be available.
# Notes:
# For some keys, the detail columns should be (7.3.2):
# IP Address User Name Log Time Client PID LicenseID
# But this always uses the same method: (7.4.2):
# Client/Access Mode User Name Client login time Client PID
#
# This uses the machine name, and not the IP address, when checking.
BBHTAG=sentinel # What we put in bb-hosts to trigger this test
COLUMN=$BBHTAG # Name of the column, often same as tag in bb-hosts
TABLEH="<table class=sortable border=1 cellpadding=5>" #HTML for table start
EMPTYTABLES=0 #Show empty tables if non-zero
#Make sure we have required executables. Allow interactive run from ext.
[ "`which wget`" -a "`which printf`" ] || { echo "wget and printf required"; exit 1; }
[ "$BBHOME" ] || { BBHOME=..; . ../etc/hobbitserver.cfg; BB=echo; }
#Just to avoid some excessive indenting, define a function
check_usage()
{
echo "$TABLEH
<thead><tr><th>Client/Access Mode<th>User Name<th>Client Login Time<th>Client PID</tr></thead><tbody>" >> $COLUMN.$$
#Although the keys are relatively easy to get, the counts are harder.
#The server requires getting the counts page followed by xml.
#Timing is everything. Grr...
wget "${URL}licenseinfo.html?$KEY?$SERIALNUMBER" -O /dev/null -q
wget "${URL}licenseinfo.xml" -O - -q | $SED 's/\r/\
/g' | $SED 's/<\/.*//g;s/>\(.\+\)/ : \1/g;s/.*>//;s/.*<//' | while read LLL; do
tag=`echo "$LLL" | $SED 's/ : .*//'` #'s/[ \t]<//; s/>.*//'
val=`echo "$LLL" | $SED 's/.* : //'` #'s/<\/.*//;s/.*>//'
case $tag in
ClientIPAddress) IPADDRESS="$val" ;;
ClientUserName) USERNAME="$val" ;;
ClientLogTime) LOGTIME="$val" ;;
ClientProcessID) PID="$val"
#Start with a colon to avoid NCV processing ($LOGTIME has colons)
echo "<!--:--><tr><td>$IPADDRESS<td>$USERNAME<td>$LOGTIME<td>$PID</tr>" >> $COLUMN.$$
;;
#LicenseID) LICENSEID="$val" ;;
#*) ;;
esac
done
echo "</tbody></table>" >> $COLUMN.$$
}
#The main loop
#echo '10.1.207.3 crplic2 # sentinel,7532=Liscad,759c=LGO' | while read L; do
$BBHOME/bin/bbhostgrep --no-down $BBHTAG\* | while read L; do
set $L # To get one line of output from bbhostgrep
HOSTIP="$1"
MACHINEDOTS="$2"
MACHINE=`echo "$2" | $SED 's/\./,/g'`
PORT=`echo $4 | $SED "s/$BBHTAG//;s/,.*//"`
if [ -z "$PORT" ]; then
PORT=":6002"
fi
SUBST="`echo $4 | $SED 's/[^,]*//'`,"
# either "http://$MACHINE$PORT/" or "http://$HOSTIP$PORT/"
URL="http://$MACHINE$PORT/"
COLOR=green
KEY=0
wget "${URL}keyinfo.xml" -O - -q | $SED 's/\r/\
/g' | $SED 's/<\/.*//g;s/>\(.\+\)/ : \1/g;s/.*>//;s/.*<//' | while read LL; do
tag=`echo "$LL" | $SED 's/ : .*//'` #'s/[ \t]<//; s/>.*//'
val=`echo "$LL" | $SED 's/.* : //'` #'s/<\/.*//;s/.*>//'
case $tag in
ServerVersion) echo "Sentinel Protection Server Version is $val" > $COLUMN.$$;;
SerialNumber)
SERIALNUMBER="$val"
SERIALSHORT="`echo $val | $SED 's/^0\+//'`"
HEXSERIAL="`printf '%04x' $SERIALSHORT`"
APPEND=$HEXSERIAL
NAME="unknown"
#Check for substitution
#echo "Testing $HEXSERIAL (,$HEXSERIAL=) on $SUBST"
#echo "$SUBST" | $GREP ",$HEXSERIAL="
#echo "Testin $HEXSERIAL (,$HEXSERIAL=) on $SUBST"
if [ `echo "$SUBST" | $GREP ",$HEXSERIAL="` ]; then
NAME=`echo $SUBST | $SED "s/.*,$HEXSERIAL=//;s/,.*//"`
APPEND=$NAME
fi
#echo "SERIAL: $SERIALNUMBER / $SERIALSHORT / $HEXSERIAL"
;;
HardLimit) HARDLIMIT="$val" ;;
LicenseInUse) INUSE="$val" ;;
NumTimeOut) TIMEOUT="$val" ;;
HighestUse) HIGHESTUSE="$val" ;;
PartNumber) #PARTNUMBER="$val"
USEPERCENT=$((INUSE * 100 / $HARDLIMIT))
echo "<HR>Details for key $SERIALNUMBER (0x$HEXSERIAL) [$NAME]:
InUse_$APPEND : $INUSE ($USEPERCENT%)<!--
UsePercent_$APPEND : $USEPERCENT -->
HighestUse_$APPEND : $HIGHESTUSE ($((HIGHESTUSE * 100 / $HARDLIMIT))%)
HardLimit_$APPEND : $HARDLIMIT
" >> $COLUMN.$$
if [ "$EMPTYTABLES" != "0" -o "$INUSE" != "0" ]; then
KEY=$(($KEY+1))
check_usage
fi
;;
#*) ;;
esac
done
MSG="status $MACHINE.$COLUMN $COLOR `date` [$MACHINEDOTS] $BBHTAG status
`cat $COLUMN.$$`"
$BB $BBDISP "$MSG"
$RM $COLUMN.$$
done
exit 0