#!/bin/bash # ------------------------------------------------------------------- # # Author: James Wells # Title: Ehealth license info # Description: This script is used to generate dynamic info on the ehealth licenses # # # Revision History: # # 18/02/2005 Initial creation date # 11/03/2005 Removed dependency of external commands # 21/03/2005 Added a customer filter option to list number of used licenses. # 21/03/2005 Adjusted mailing feature when threshold is set and updated documentation. # 24/03/2005 Added a command syntax call to print out duplicate elements consuming a poller license. # 09/08/2005 Added more documentation and examples. # 22/09/2005 Changed methodolgy of working out total used licenses. # 22/09/2005 Added a option to display Livehealth license usage. # 30/01/2007 Adjusted the method to extract total used licenses. # 16/10/2007 Added percentage used to the report output. # 22/02/2008 Adjusted list customer function to test no customers. # 22/02/2008 Added option to filter by IPaddress or name. # 25/02/2008 Added option to report on LiveHealth license percentage. # 17/04/2008 Added option to report on LiveHealth license percentage. # 18/05/2011 Added new method to extract license information from eHealth version 6.2 # 18/05/2011 Adjusted method of calculating licenses based on name or ip filters # 18/05/2011 Added group filter to be able to list a group and how many licenses are in use. # # ------------------------------------------------------------------- # Constants # ------------------------------------------------------------------- PROGNAME=$(basename $0) HOSTNAME=`hostname` VERSION="1.6" DATE=`date +%d-%M-%Y` NH_VER=`$NH_HOME/bin/nhShowRev -quiet | awk '{print $1}'` USER_ID=`/usr/xpg4/bin/id -un` NH_INSTALLF="/etc/nh.install.cfg" # ------------------------------------------------------------------- # Functions # ------------------------------------------------------------------- function source_ehealth { # ---------------------------------------------------------------------- # This function will execute the required files for the ehealth system # No arguments # ---------------------------------------------------------------------- if [ -f "$NH_INSTALLF" ] then FIND_USERID=`cat $NH_INSTALLF | egrep -e "NH_USER" | awk -F"=" '{print $2}'` if [ "$USER_ID" = "$FIND_USERID" ] then . $NH_HOME/nethealthrc.sh else echo " " echo "please switch user to the ehealth user" echo " " graceful_exit fi else echo " " echo "eHealth not installed" echo " " graceful_exit fi } function error_exit { # ----------------------------------------------------------------------- # Function for exit due to fatal program error # Accepts 1 argument: # string containing descriptive error message # ----------------------------------------------------------------------- echo "${PROGNAME}: ${1:-"Unknown Error"}" >&2 exit 1 } function graceful_exit { # ----------------------------------------------------------------------- # Function called for a graceful exit # No arguments # ----------------------------------------------------------------------- exit } function signal_exit { # ----------------------------------------------------------------------- # Function to handle termination signals # Accepts 1 argument: # signal_spec # ----------------------------------------------------------------------- case $1 in INT) echo "$PROGNAME: Program aborted by user" >&2 exit ;; TERM) echo "$PROGNAME: Program terminated" >&2 exit ;; *) error_exit "$PROGNAME: Terminating on unknown signal" ;; esac } function usage { # ----------------------------------------------------------------------- # Function to display usage message (does not exit) # No arguments # ----------------------------------------------------------------------- echo "Usage: ${PROGNAME} [-h | --help] [-i display-info ] [-l list] [-e Livehealth] [-f filter-type] [-c cust prefix] [-t threshold] [-r recipient] [-m mail] [-d duplicate] [-g group-name]" } function helptext { # ----------------------------------------------------------------------- # Function to display help message for program # No arguments # ----------------------------------------------------------------------- local tab=$(echo -en "\t\t") cat <<- -EOF- ${PROGNAME} ver. ${VERSION} $(usage) Options: -h, --help Display this help message and exit. -i Display this help message and exit. -l list List current installed licenses -e list LiveHealth List Livehealth license usage -c cust prefix List current used licenses using customer filter -f filter type USed to filter the results based on SQL field -t threshold Set a license threshold -r recipient Mail recipient -m mail Mail of a report of the license status -d duplicates Prints a list of duplicate elements using a license -g group-name Prints total used licenses based on a group filter -EOF- } function mail_exception { # ----------------------------------------------------------------------- # Function for results to be mailed to eHealth admins if needed # ----------------------------------------------------------------------- if [ $TOT_LEFT -le $THRESHOLD ] then echo "$TOT_LEFT EHealth licenses left, please verify" | mailx -s "ehealth-license-info" $MAIL_ADMIN else echo "number of licenses are OK for now" fi } function license_info { # ----------------------------------------------------------------------- # Function to display info on total license usage # No arguments # ----------------------------------------------------------------------- LIST=`$NH_HOME/lmgr/bin/lmstat -A` TOT_LIC=`echo "$LIST" | grep poller | grep -v "v1.0" | awk -F" " '{print $6}'` TOT_USED=`$NH_HOME/bin/nhListElements -where "name matches *" | nhListElementLicenses -count -inFile - | egrep -e "Total Licenses" | awk '{print $3}'` TOT_LEFT=`expr $TOT_LIC - $TOT_USED` TOT_PERC=`echo "scale = 3; ${TOT_USED}/${TOT_LIC}*100" | bc -l` HEADING=`echo "Type: Number:" | nawk '{printf "%-15s %-10s\n", $1, $2}'` RESULT=`echo "$LIST" | sed '/^ *$/d' | sed 's/Users of //g' | sed 's/(//g' | sed 's/)//g' | awk '{print $1" "$4" ""License"}' | egrep -ve "ccilmgrd|UP|^License|nodelocked" | egrep -ve "v1.0" | egrep -ve "floating" | egrep -ve "lmstat" | egrep -ve "Vendor" | egrep -ve "Flexible" | egrep -ve "Feature" | nawk '{printf "%-15s %-10 s\n", $1, $2}'` } function livehealth_info { # ----------------------------------------------------------------------- # Function to display info on LiveHealth license usage # No arguments # ----------------------------------------------------------------------- case $NH_VER in '6.2.0') DYN_DEBUG=YES ;; '5.7.0') DYN_DEBUG=YES ;; '5.6.5') DYN_DEBUG=YES ;; '5.0.2') DYN_DEBUG=NO ;; *) DYN_DEBUG=YES ;; esac if [ "$DYN_DEBUG" = "YES" ] then TEST_LH=`cat $NH_HOME/lmgr/license.dat | grep liveHealth | awk '{print $6}'` if [ -n "$TEST_LH" ] then LH_LIC=`$NH_HOME/bin/nhDebugLiveEngine -element all | egrep -e "MonitorInLe: Yes" | wc -l | sed 's/ //g'` TOT_LH_LEFT=`expr "$TEST_LH" - "$LH_LIC"` TOT_PERC=`echo "scale = 3; ${LH_LIC}/${TEST_LH}*100" | bc -l` else echo " " echo "LiveHealth is not installed on $HOSTNAME" echo " " fi else echo "ehealth version 5.0.2 uses a different method to work out liveHealth license usage" echo "please visit the Concord Support site http://search.support.concord.com" echo "select search by solution ID and enter TS5372" fi } function list_cust { # ----------------------------------------------------------------------- # Function to display info on the number of licenses used by a single # customer # No arguments # ----------------------------------------------------------------------- if [ -n "$SQL_FILTER" ] then LICENSE_INFO=`$NH_HOME/bin/nhListElements -where "$SQL_FILTER matches $CUST_FILTER*" | nhListElementLicenses -count -inFile - | egrep -ve "Total Licenses|secondary|unlicensed" | egrep -e "primary" | wc -l | sed 's/ //g'` if [ "$LICENSE_INFO" != 0 ] then echo " " echo "Customer $CUST_FILTER has used $LICENSE_INFO licenses" echo " " else echo " " echo "Customer $CUST_FILTER does not exist or is not consuming any poller licenses" echo " " fi else LICENSE_INFO=`$NH_HOME/bin/nhListElements -where "name matches $CUST_FILTER*" | nhListElementLicenses -count -inFile - | egrep -ve "Total Licenses|secondary|unlicensed" | egrep -e "primary" | wc -l | sed 's/ //g'` if [ "$LICENSE_INFO" != 0 ] then echo " " echo "Customer $CUST_FILTER has used $LICENSE_INFO licenses" echo " " else echo " " echo "Customer $CUST_FILTER does not exist or is not consuming any poller licenses" echo " " fi fi } function print_group_lic { # ----------------------------------------------------------------------- # Function to display number of used licenses based on a group filter # customer # No arguments # ----------------------------------------------------------------------- if [ -n "$GROUP_FILTER" ] then LICENSE_INFO=`$NH_HOME/bin/nhListElements -inGroup $GROUP_FILTER | nhListElementLicenses -count -inFile - | egrep -ve "Total Licenses|secondary|unlicensed" | egrep -e "primary" | wc -l | sed 's/ //g'` if [ "$LICENSE_INFO" != 0 ] then echo " " echo "Group $GROUP_FILTER has used $LICENSE_INFO licenses" echo " " else echo " " echo "Group $GROUP_FILTER does not exist or is not consuming any poller licenses" echo " " fi else echo "No group filter was passed to the script" fi } function print_dup { # ----------------------------------------------------------------------- # Function to display info on the number of duplicate elements # customer # No arguments # ----------------------------------------------------------------------- NH_LIST_NAMES=`$NH_HOME/bin/nhListElementLicenses -primaryOnly | egrep -ve "copy"` NH_DUP=`echo "$NH_LIST_NAMES" | awk -F"," '{print $1}' | uniq -c | awk '{print $1" "$2}' | grep ^2 | awk '{print $2}'` IP_LIST=`$NH_HOME/bin/sys/nhisql "SELECT name,ip_address from NH_ELEMENT"` echo " " echo "List of duplicate elements in the eHealth DB on `hostname`" echo "------------------------------------------------------------" for i in `echo "$NH_DUP"` do EXCEPTIONS=`echo "$NH_LIST_NAMES" | /usr/xpg4/bin/grep -w ^$i` printf "$EXCEPTIONS\n" done } function display_info { # ----------------------------------------------------------------------- # Function to display info on using the script when scheduling reports # No arguments # ----------------------------------------------------------------------- local tab=$(echo -en "\t\t") cat <<- -EOF- The purpose of this script is to display any info from the ehealth system in regards to licenses. The license usage is calculated via the -primaryOnly option from the command nhListElementLicense. This is the subtracted from the total purchased via the license file and the value remaining is total free licenses or available license. It is also possible to CRONTAB this script and setup a theshold license usage and if it is exceeded then the result can be sent to an eHealth administrator. You will need to have mail setup on the UNIX system for this to occur. Examples: List all licenses in use: ------------------------- ./${PROGNAME} -l List all liveHealth licenses in use: ------------------------- ./${PROGNAME} -e List all duplicate elements consuming a license: ------------------------------------------------ ./${PROGNAME} -d List license usage using a element PREFIX filter: ------------------------------------------------- ./${PROGNAME} -c gt ./${PROGNAME} -c 172. -f ipAddr ./${PROGNAME} -c gt -f name Sets a threshold up of 300 and mails a report off if exceeded: -------------------------------------------------------------- ./${PROGNAME} -l -t 300 -r eh_admin@somedomain.com -m Lists license usage based on a group filter: --------------------------------------------- ./${PROGNAME} -g ALL_WAN_ROUTERS -EOF- } # ------------------------------------------------------------------- # Program starts here # ------------------------------------------------------------------- ##### Initialization And Setup ##### source_ehealth # Trap TERM, HUP, and INT signals and properly exit trap "signal_exit TERM" TERM HUP trap "signal_exit INT" INT ##### Command Line Processing ##### if [ "$1" = "--help" ] || [ $# -le 0 ] then helptext graceful_exit fi while getopts ":hidmr:t:f:c:g:el" opt; do case $opt in l) license_info ;; e) livehealth_info ;; g) GROUP_FILTER="$OPTARG" print_group_lic ;; c) CUST_FILTER="$OPTARG" ;; f) SQL_FILTER="$OPTARG" ;; t) THRESHOLD="$OPTARG" ;; r) MAIL_ADMIN="$OPTARG" ;; m) mail_exception ;; d) print_dup graceful_exit ;; i) display_info graceful_exit ;; h) helptext graceful_exit ;; *) usage exit 1 esac done ##### MAIN LOGIC ##### if [ -n "$CUST_FILTER" ] then list_cust else if [ "$1" = "-l" ] && [ $# -eq 1 ] then cat <<- -EOF- $HEADING $RESULT Total used poller licenses = $TOT_USED Total poller licenses left = $TOT_LEFT Total percentage in use = $TOT_PERC% -EOF- elif [ "$1" = "-e" ] && [ $# -eq 1 ] && [ -n "$TEST_LH" ] then cat <<- -EOF- Total used livehealth licenses = $LH_LIC Total liveHealth licenses left = $TOT_LH_LEFT Total percentage in use = $TOT_PERC% -EOF- elif [ "$1" = "-l" ] && [ "$2" = "-e" ] && [ -n "$TEST_LH" ] then cat <<- -EOF- $HEADING $RESULT Total used poller licenses = $TOT_USED Total poller licenses left = $TOT_LEFT Total used livehealth licenses = $LH_LIC Total liveHealth licenses left = $TOT_LH_LEFT Total percentage in use = $TOT_PERC% -EOF- fi fi ##### THE END ######## graceful_exit