#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_rsi - show commands for show tech-support rsi
#                     spawned by show_tech_fast
#
# March 2009, Deepak Narula
#
# Copyright (c) 2009-2014, 2018 by cisco Systems, Inc.
# All rights reserved.
# --------------------------------------------------------------------

. /pkg/bin/show_tech_main_fragment

__cardtype="unspecified"

# Parse the arguments to the script.
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_rsi: output file not specified"
    exit
fi

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

# ***********************************************************
#  Show commands to be run by the show tech-support commands
# ***********************************************************

cmd="ls /pkg/bin/instcmd 2>/dev/null"
eval $cmd
plat=$?

# Commands that run on once per system
sys_exec[1]="show running-config"
sys__ksh[1]='nvgen -c -l 1 -t 1 -i1 -o 1'
if [[ $plat -eq 0 ]]
then
    sys_exec[2]='show install active summary'
    sys__ksh[2]='instcmd show install active summary'
else
    sys_exec[2]='show install active'
    sys__ksh[2]='sdr_instcmd show install active'
fi
sys_exec[3]="show redundancy"
sys__ksh[3]='redcon_show'
sys_exec[4]="show logging"
sys__ksh[4]='show_logging'
sys_exec[5]="show process rsi_master"
sys__ksh[5]='sysmgr_show -o -p rsi_master'
sys_exec[6]='show rsi queue-depths'
sys__ksh[6]='show_rsi_master -c 0x46'
sys_exec[7]='show svd state'
sys__ksh[7]='show_rsi_master -c 0x47'
sys_exec[8]='show svd role'
sys__ksh[8]='show_rsi_agent -c 0x48'
sys_exec[9]='show rsi producer-clients detail'
sys__ksh[9]='show_rsi_master -c 0x4a -d'
sys__ksh[10]=''

#############################################################
# Commands that run on all nodes
lc_exec[1]="show process rsi_agent"
lc__ksh[1]='sysmgr_show -o -p rsi_agent'
lc_exec[2]="show rsi vr all"
lc__ksh[2]='show_rsi_agent -c 0xc'
lc_exec[3]="show rsi vrf all"
lc__ksh[3]='show_rsi_agent -c 0x17'
lc_exec[4]="show rsi table hierarchichal"
lc__ksh[4]='show_rsi_agent -c 0x20'
lc_exec[5]="show rsi table colocation"
lc__ksh[5]='show_rsi_agent -c 0x1f -h'
lc_exec[6]="show rsi clients"
lc__ksh[6]='show_rsi_agent -c 0x29'
lc_exec[7]="show rsi producers"
lc__ksh[7]='show_rsi_agent -c 0x33'
lc_exec[8]="show rsi interface all global"
lc__ksh[8]='show_rsi_agent -c 0x3d -h'
lc_exec[9]="show rsi state"
lc__ksh[9]='show_rsi_agent -c 0x50'
lc_exec[10]="show rsi role-transactions"
lc__ksh[10]='show_rsi_agent -c 0x51'
lc_exec[11]='show rsi trace'
lc__ksh[11]='rsi_show_ltrace'
lc_exec[12]="show vrf-group all internal"
lc__ksh[12]='show_rsi_agent -c 0x5d'
lc_exec[13]="show rsi table"
lc__ksh[13]='show_rsi_agent -c 0x1f'
lc__ksh[14]=''

#############################################################
# Commands that run on all RPs
rp__ksh[1]=''

display() {
    print_main_heading "show tech-support rsi"

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

    print_main_heading "show tech-support rsi complete"
}

# Run the appropriate function depending on the node specified and if a
# file is specified write the output to that file. We need to redirect
# stderr to stdout when writing to a file because some of the show
# commands output to stderr instead of stdout
. /pkg/bin/show_tech_file_fragment
