#!/pkg/bin/ksh
#------------------------------------------------------------------------------
# Service CGv6 show tech-support command
#
# November 2009, Raghav Kaushik
# October 2011, Somnath Roy (changed for ISM)
#
# Copyright (c) 2009-2011, 2018 by cisco Systems, Inc.
# All rights reserved.
#------------------------------------------------------------------------------

# This script fragment contains the code for the following functions
# - print_main_heading
# - print_command_heading
# - run_single_command
# - run_commands
# - run_single_command_on_all_nodes
# - run_commands_on_all_nodes
# - default_parser_function
. /pkg/bin/show_tech_main_fragment

#
# Parse the arguments to the script.
#
__cardtype="unspecified"
while [ "$#" -gt "0" ]; do
    case "$1" in
        -t) __cardtype="$2"; shift 2;;
        *)  default_parser_function "$@"; shift $#;;
    esac
done

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

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

#
# List of commands to be run. Each set must finish with a pair of empty
# strings. Single quotes rather than double quotes must be used.
#
# The __ksh variable is the process which will be spawned, the _exec variable
# is just for displaying in the output.
#


#
# Global commands (run once per LR) - General
#
sys_exec[1]='show running-config'
sys__ksh[1]='nvgen -c -l 1 -t 1 -o 1'
sys_exec[2]='show platform'
sys__ksh[2]='show_platform_vkg -e'
sys_exec[3]='show platform summary location all'
sys__ksh[3]='show_platform_vkg -e -s -l -a'
sys_exec[4]='show version'
sys__ksh[4]='show_version'
sys_exec[5]='show install active'
sys__ksh[5]='instcmd show install active'
sys_exec[6]='show interfaces brief'
sys__ksh[6]='show_interface -a -o 0x2'
sys_exec[7]='show logging'
sys__ksh[7]='show_logging'
sys_exec[8]='show config failed'
sys__ksh[8]='cfgmgr_show_failed -c'
sys_exec[9]='show config failed startup'
sys__ksh[9]='cfgmgr_show_failed -l'
sys_exec[10]='show configuration commit list 20'
sys__ksh[10]='config_history -r -b -n 0x14'
sys_exec[11]='show services sesvi trace ea all location all'
sys__ksh[11]='sesvi_ea_show_ltrace -M -XYZ -i all'
sys_exec[12]='show services sesvi trace mgr pd location all'
sys__ksh[12]='sesvi_mgr_pd_show_ltrace -i all'
sys_exec[13]='show services platform trace ea location all'
sys__ksh[13]='sesvi_ea_pd_show_ltrace -i all'
sys_exec[14]='show services p2mp traces all location all'
sys__ksh[14]='show_p2mp_srvr_ltrace -i all all'
sys_exec[15]='show cgn trace services all location all'
sys__ksh[15]='cgv6_services_show_ltrace -i all all'
sys_exec[16]='show cgn trace execution-agent loc all'
sys__ksh[16]='show_cgn_ea_ltrace -i all -L'
sys_exec[17]='show cgn trace core event location all'
sys__ksh[17]='cgv6_services_show_ltrace -i all core-event'
sys_exec[18]='show cgn trace core error location all'
sys__ksh[18]='cgv6_services_show_ltrace -i all core-error'
sys_exec[19]='show cgn trace master-agent'
sys__ksh[19]='show_cgn_ma_ltrace -A'
sys_exec[20]='show cgn vrf-db'
sys__ksh[20]='show_cgn_nat44_vrfdb -a'
#sys_exec[21]='show controllers pse statistics location all'
#sys__ksh[21]='pse_cli -t 0x5'
#sys_exec[22]='show controllers pse utilization location all'
#sys__ksh[22]='pse_cli -t 0x8'
sys_exec[23]='show interfaces * accounting'
sys__ksh[23]='show_interface -i .* -o 0x4'
sys_exec[24]='show services interfaces'
sys__ksh[24]='svii_show'
sys_exec[25]='show service-module trace sm location all'
sys__ksh[25]='sim_show_ltrace -s -i all'
sys_exec[26]=''
sys__ksh[26]=''

# Following are removed from CRS list (as FYI)
# sys_exec[14]='show uidb data'
# sys__ksh[14]='uidb_show data -a'
# sys_exec[19]='show logging service-cpu all location all'
# sys__ksh[19]='oct_uart_logger_cli all all'
# sys_exec[22]='show controllers pse trace all all all location  all'
# sys__ksh[22]='show_pse_ltrace -D all -E all -T all -L 0x0 -i all'
# sys_exec[24]='show cef platform trace all all location all'
# sys__ksh[24]='show_hfr_fib_ltrace -i all -9 -A'

#
# Commands to be run on all nodes
#
all_exec[1]='show processes pidin location $location'
all__ksh[1]='show_processes -d -n $fq_nodeid'
all_exec[2]=''
all__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() {
    #
    # Preamble
    #
    print_main_heading "show tech-support services cgn"

    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys
    else
	exec_commands all
    fi

    #
    # Invoke the SVII fragment 
    #
    . /pkg/bin/show_tech_svii_fragment

    print_main_heading "show tech-support services cgn complete"
}

#
# 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

