#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show tech-support parser - show commands for parser show tech-support
#                     spawned by show_tech_fast
#
# March 2014, Sakshi Aggarwal 
#
# Copyright (c) 2007-2009, 2013-2014, 2016-2017 by cisco Systems, Inc.
# All rights reserved.
# --------------------------------------------------------------------

. /pkg/bin/show_tech_main_fragment

# Password flag to indicate whether log will include pw or not
__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_parser_techsupport_fast: 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
# ***********************************************************

# Commands that run on once per system
sys_exec[1]="show running-config"
sys__ksh[1]='nvgen -c -l 1 -t 1 -o 1'
sys_exec[2]="show configuration failed startup"
sys__ksh[2]='cfgmgr_show_failed -l'
sys_exec[3]="show configuration trace"
sys__ksh[3]='show_config_ltrace'
sys_exec[4]="show configuration history detail"
sys__ksh[4]='cfgmgr_show_history -s -f -n 0x5dc -t all -d'
sys_exec[5]="show cfgmgr commitdb"
sys__ksh[5]='cfgmgr_show_commitdb'
sys_exec[6]="show install active"
if [ "$platform" = "panini" ]
then
    sys__ksh[6]='sdr_instcmd show install active'
else 
    sys__ksh[6]='instcmd show install active'
fi
sys_exec[7]="show inventory location all"
sys__ksh[7]='show_inventory -e -t'
sys_exec[8]="show filesystem"
sys__ksh[8]='filesys_cli show_file -s systems'
sys_exec[9]="show cli history brief"
sys__ksh[9]='show_parser_history -h 0x1'
sys_exec[10]="show cli history detail"
sys__ksh[10]='show_parser_history -h 0x2'
sys__ksh[11]=''

#############################################################
# Commands that run on RP nodes                      #
#############################################################
rplc_exec[1]='show parser trace parsing location $location'
rplc__ksh[1]='show_parser_ltrace -i $fq_nodeid -P 1 -U'
rplc_exec[2]='show parser trace interface-mgr location $location'
rplc__ksh[2]='show_parser_im_ltrace -i $fq_nodeid -P 1'
rplc_exec[3]='show parser trace inventory location $location'
rplc__ksh[3]='show_parser_ltrace -i $fq_nodeid -P 1 -T'
rplc_exec[4]='show parser trace memory location $location'
rplc__ksh[4]='show_parser_ltrace -i $fq_nodeid -P 1 -M'
rplc_exec[5]='show parser trace resource-mgr location $location'
rplc__ksh[5]='show_parser_ltrace -i $fq_nodeid -P 1 -R'
rplc_exec[6]='show parser trace tree location $location'
rplc__ksh[6]='show_parser_ltrace -i $fq_nodeid -P 1 -Q'
rplc_exec[7]='show parser trace client location $location'
rplc__ksh[7]='show_parser_ltrace -i $fq_nodeid -P 4 -S'
rplc_exec[8]='show parser trace history location $location'
rplc__ksh[8]='show_parser_ltrace -i $fq_nodeid -P 1 -H'
rplc_exec[9]='show parser trace config-grp location $location'
rplc__ksh[9]='show_parser_ltrace -i $fq_nodeid -P 1 -C'
rplc_exec[34]='show parser trace extension location $location'
rplc__ksh[34]='show_parser_ltrace -i $fq_nodeid -P 1 -X'

###########################################################
# Run all the nvgen trace commands                        #
###########################################################

rplc_exec[10]='show nvgen trace ascii-backup location $location'
rplc__ksh[10]='show_nvgen_ltrace -i $fq_nodeid -P 5 -B'
rplc_exec[11]='show nvgen trace resource-mgr location $location'
rplc__ksh[11]='show_nvgen_ltrace -i $fq_nodeid -P 2 -R'
rplc_exec[12]='show nvgen trace client location $location'
rplc__ksh[12]='show_nvgen_ltrace -i $fq_nodeid -P 3 -C'
rplc_exec[13]='show nvgen trace tree location $location'
rplc__ksh[13]='show_nvgen_ltrace -i $fq_nodeid -P 2 -Q'
rplc_exec[14]='show nvgen trace error location $location'
rplc__ksh[14]='show_nvgen_ltrace -i $fq_nodeid -P 2 -E'
rplc_exec[15]='show nvgen trace general location $location'
rplc__ksh[15]='show_nvgen_ltrace -i $fq_nodeid -P 6 -B'
rplc_exec[16]='show nvgen trace persistent last 4'
rplc__ksh[16]='show_nvgen_persistent_trace 0x4'

##########################################################
# Run all the exec trace commands                        #
##########################################################
rplc_exec[17]='show exec trace event location $location'
rplc__ksh[17]='show_exec_ltrace -i $fq_nodeid -Y'
rplc_exec[18]='show exec trace error location $location'
rplc__ksh[18]='show_exec_ltrace -i $fq_nodeid -Z'

#########################################################
# Run all the config trace commands                     #
#########################################################
rplc_exec[19]='show config trace event location $location'
rplc__ksh[19]='show_config_ltrace -i $fq_nodeid -V'
rplc_exec[20]='show config trace error location $location'
rplc__ksh[20]='show_config_ltrace -i $fq_nodeid -E'
rplc_exec[21]='show config trace library location $location'
rplc__ksh[21]='show_config_ltrace -i $fq_nodeid -L'
rplc_exec[22]='show configuration backup trace location $location'
rplc__ksh[22]='show_sconbkup_ltrace -i $fq_nodeid'
rplc_exec[23]='show cli history brief location $location'
rplc__ksh[23]='show_parser_history -h 0x1 -n $fq_nodeid'
rplc_exec[24]='show cli history detail location $location'
rplc__ksh[24]='show_parser_history -h 0x2 -n $fq_nodeid'
rplc_exec[25]='show process parser_server location $location'
rplc__ksh[25]='sysmgr_show -o -p parser_server -n $fq_nodeid'
rplc_exec[26]='show process nvgen_server location $location'
rplc__ksh[26]='sysmgr_show -o -p nvgen_server -n $fq_nodeid'

#########################################################
# Display the contents of the LR plane CFS for the LR   # 
# in which we are running                               #
#########################################################
rplc_exec[27]="ls -lLR `/pkg/bin/cfgmgr_boot_media`config/lr"
rplc__ksh[27]="ls -lLR `/pkg/bin/cfgmgr_boot_media`config/lr"
rplc_exec[28]="ls -lLR `/pkg/bin/cfgmgr_boot_media`config/running/alternate_cfg"
rplc__ksh[28]="ls -lLR `/pkg/bin/cfgmgr_boot_media`config/running/alternate_cfg"

rplc_exec[29]="cat /etc/cfg/lr/running/nvgen/nv_cur.cfg"
rplc_exec[30]="cat /etc/cfg/alt_cfg/router.cfg"
rplc_exec[31]="cat /etc/cfg/alt_cfg/last_used.cfg"
rplc_exec[32]="run ls -l /pkg/parser/"
rplc__ksh[32]='ls -l /pkg/parser/'
rplc_exec[33]="run nvgen -l 5"
rplc__ksh[33]='nvgen -l 5'

if [[ "$platform" = "panini" ]]; then
rplc__ksh[29]="cat `/pkg/bin/cfgmgr_boot_media`config/lr/running/nvgen/nv_cur.cfg"
rplc__ksh[30]="cat `/pkg/bin/cfgmgr_boot_media`config/running/alternate_cfg/router.cfg"
rplc__ksh[31]="cat `/pkg/bin/cfgmgr_boot_media`config/running/alternate_cfg/last_used.cfg"
else
rplc__ksh[29]="cat /cfs/cfg/lr/running/nvgen/nv_cur.cfg"
rplc__ksh[30]="cat /cfs/cfg/alt_cfg/router.cfg"
rplc__ksh[31]="cat /cfs/cfg/alt_cfg/last_used.cfg"
fi

rplc__ksh[35]=''

#############################################################                   
#  Display function for show tech parser Script             #
#############################################################

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

    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys
    else
        case "$__cardtype" in
        "RP")
            exec_commands rplc
            ;;
        "DRP")
            exec_commands rplc
            ;;
        esac

    fi

    print_main_heading "show tech-support parser 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

