#!/pkg/bin/ksh
#------------------------------------------------------------------------------
# Service Infrastructure show tech-support command
#
# February 2008, Paul Taylor
#
# Copyright (c) 2008, 2013-2014, 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)
#
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'
sys_exec[3]='show version'
# assumes "platform" is set for us by show_tech_main_fragment
if [ "$platform" = "panini" ]
then
   sys__ksh[3]='ng_show_version' 
else
   sys__ksh[3]='show_version' 
fi
sys_exec[4]='show interfaces brief'
sys__ksh[4]='show_interface -a -o 0x2'
sys_exec[5]='show logging'
sys__ksh[5]='show_logging'
sys_exec[6]='show services role detail'
sys__ksh[6]='srd_show -A -D'
sys_exec[7]='show services redundancy internal'
sys__ksh[7]='sdir_show -I'
sys_exec[8]='show services interfaces'
sys__ksh[8]='svii_show'
sys_exec[9]='show services db manager'
sys__ksh[9]='svii_mgr_show -a -d'
sys_exec[10]='show services role trace server'
sys__ksh[10]='srd_show_trace'
sys_exec[11]='show services redundancy trace verbose'
sys__ksh[11]='sdir_show_ltrace -A -C'
sys_exec[12]='show services interfaces trace manager all'
sys__ksh[12]='svii_show_ltrace -B -XYZ'
sys_exec[13]=''
sys__ksh[13]=''

#
# Commands to be run on all nodes
#
all_exec[1]='show processes pidin location $location'
# assumes "platform" is set for us by show_tech_main_fragment
if [ "$platform" = "panini" ]
then
   all__ksh[1]='sh_proc_ng_blocked' 
else
   all__ksh[1]='show_processes -d -n $fq_nodeid' 
fi
all_exec[2]='show services db ea location $location'
all__ksh[2]='svii_ea_show -a -h $fq_nodeid -d'
all_exec[3]='show services db adjacency interfaces location $location'
all__ksh[3]='svii_adj_show -I -h $fq_nodeid'
all_exec[4]='show services db adjacency services location $location'
all__ksh[4]='svii_adj_show -S -h $fq_nodeid'
all_exec[5]='show services interfaces trace ea all location $location'
all__ksh[5]='svii_show_ltrace -C -XYZ'
all_exec[6]='show services interfaces trace adjacencies all location $location'
all__ksh[6]='svii_show_ltrace -D -XYZ'
all_exec[7]=''
all__ksh[7]=''

#
# Commands to be run on RP node only
#
rp_exec[1]='show services role trace agent location $location'
rp__ksh[1]='srd_agent_show_trace'
rp_exec[2]=''
rp__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 svi"

    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys
    else
        case $__cardtype in
        "DRP" | "RP")
            exec_commands rp
        ;;
        esac
	  exec_commands all
    fi

    #
    # Done
    #
    print_main_heading "show tech-support services svi 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
