#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_bng - Show tech-support script bng
#
# Hazaratham Kakumani
#
# Copyright (c) 2020-2021 by cisco Systems, Inc.
# All rights reserved.
#--------------------------------------------------------------------


#
# Load the script provided by show-tech infra, which provides worker functions
#
. /pkg/bin/show_tech_main_fragment

# Initialise any variables used.
__cardtype="unspecified"
session_id="unspecified"
summary=0
#location=""
directory=""
memory_only=0

# Parse the arguments to the script.
# -S  : Run commands for a specific session
# -B  : Run commands that display summary information
while [ $# -gt 0 ]; do
  case "$1" in
     -S) session_id="$2"; shift 2;;
     -B) summary=1; shift 1;;
     
     -t) __cardtype="$2"; shift 2;;

     -M) memory_only=1; shift 1;;
     *)  default_parser_function "$@"; shift $#;;
  esac
done

directory=$__tar_file_directory_on_node

if [ "$__filename" = "unspecified" ]; then
    echo "$0: output file not specified"
    exit

    fi

if [ "$__cardtype" == "unspecified" ]; then
    __cardtype=`node_type`
fi

# Variable used to gather data in HA scenario
session_option=""
if [ "$session_id" != "unspecified" ]; then
    session_option="-S $session_id"
fi

# Variable used to gather data in HA scenario
summary_option=""
if [ $summary -eq 1 ]; then
    summary_option="-B"
fi

#node_name_internal=`uname -n`
#node_number=`node_conversion -i $node_name_internal`
location=`node_list_generation -f MY`
node_name_internal=`node_conversion -N $location`
node_number=`node_conversion -i $node_name_internal`

###############################################################################
# Show commands that run on every RP                                          #
###############################################################################

# System information 
rp_exec[1]='show running-config'
rp__ksh[1]='nvgen -c -l 1 -t 1 -o 1'

rp_exec[2]=''
rp__ksh[2]=''




###############################################################################
# Show commands that run on all RP or LC                                      #
###############################################################################


echo "Calling cnbng_snapshot"
rplc_exec[1]='run cnbng_snapshot -d $directory'
rplc__ksh[1]='cnbng_snapshot -d $directory'


rplc_exec[2]=''
rplc__ksh[2]=''
 
###############################################################################
# Show commands that run on all RP or LC for memory data                      #
###############################################################################


echo "Calling cnbng_memory"
rplcmem_exec[1]='run cnbng_mem_snapshot -d $directory'
rplcmem__ksh[1]='cnbng_mem_snapshot -d $directory'


rplcmem_exec[2]=''
rplcmem__ksh[2]=''
 


# A function called display() must be provided that calls the functions to
# run the required show commands. The display() function will be called in
# the /pkg/bin/show_tech_comp_file_frag

display() {
     
   # Print the output heading
   print_main_heading "show tech-support cnbng_snapshot"

    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys
    else
        case "$__cardtype" in
        "DRP"|"RP")
            exec_commands rplc_summary
            if [ $summary -eq 0 ]; then
                if [ $memory_only -eq 1 ]; then
                    exec_commands rplcmem
                else
                    exec_commands rp
                    exec_commands rplc
# See comment for ha_rplc
#                exec_commands ha_rplc
                fi
            fi
            if [ "$session_id" != "unspecified" ]; then
                exec_commands session_rplc
            fi
            ;;
        "LC")
            exec_commands rplc_summary
            if [ $summary -eq 0 ]; then
                if [ $memory_only -eq 1 ]; then
                    exec_commands rplcmem
                else 
                    exec_commands rplc
# See comment for ha_rplc
#                exec_commands ha_rplc
                fi
            fi
            if [ "$session_id" != "unspecified" ]; then
                exec_commands session_rplc
            fi
            ;;
        esac
    fi

    # Print the closing heading.
    print_main_heading "show tech-support cnbng_snapshot"
}

# This function calls the display() function and sends the output to file if
# the file option has been set.
. /pkg/bin/show_tech_file_fragment

