# Copyright ?? 2024 Broadcom Inc. and its subsidiaries. All Rights Reserved.
#
# Useful constants
BASIC=1
DETAIL=2
EVERYTHING=3

#
#  Library of routines supporting collector scripts

function preModule
{

    echo "**********"
    echo "* START MODULE: $1"
    echo "*"
}

function postModule
{
    echo "*"
    echo "* END MODULE: $1"
    echo "**********"
    echo
}

function logCommand
{
	echo "|- COMMAND: $*"
}

function logAndRunCmd
{
    logCommand "$*"
    eval "$*"
}

function logAndRunCmdAsGatewayUser
{
    logAndRunCmd su -c \""$*"\" -s /bin/sh gateway
}

function beginCompression
{
    echo "**********"
    echo "* BEGIN COMPRESSION OF ALL COLLECTED DATA"
    echo "*"
}

function endCompression
{
    echo "*"
    echo "* COMPLETE: FINAL COMPRESSED OUTPUT AVAILABLE AT $*"
    echo "**********"
}

function beginTestCompression
{
    echo "**********"
    echo "* BEGIN TEST COMPRESSION OF ALL COLLECTED DATA"
    echo "*"
}

function endTestCompression
{
    echo "*"
    echo "* COMPLETE: TEST OF $* OK"
    echo "**********"
}

# obtain and set SSG PID
function setGatewayPID
{    
    if ! command -v ps &> /dev/null
    then
      echo "Attempting to obtain and set Gateway PID. ps command could not be found, setting PID with java class instead."
      GATEWAYPID="com.l7tech.server.boot.GatewayMain"
    else
      GATEWAYPID=$(ps awwx | grep Gateway.jar | grep -v grep | awk '{print $1}')
      if [ -z "$GATEWAYPID" ]
        then
          echo "Error: Cannot get Gateway PID"
      fi
    fi
}

