#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_show_techsupport - Show tech-support fast script for iEdge
#
# September 2011, Luca Trentinaglia
#
# Copyright (c) 2011-2014, 2017-2019 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
ha=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;;
     -E) ha=1; shift 1;;

     -t) __cardtype="$2"; shift 2;;
     *)  default_parser_function "$@"; shift $#;;
  esac
done

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

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

node_name_internal=`uname -n`
node_number=`node_conversion -i $node_name_internal`

PLATFORM_TYPE=`uname -m`

###############################################################################
# Show commands that run once per LR                                          #
###############################################################################
sys_exec[1]='show version'

sys_exec[2]='show install active'

if [[ "${PLATFORM_TYPE}" == "x86_64" ]]; then
    sys__ksh[1]='ng_show_version'
    sys__ksh[2]='sdr_instcmd show install active'
else
    sys__ksh[1]='show_version'
    sys__ksh[2]='instcmd show install active'
fi 

sys_exec[3]='show running-config'
sys__ksh[3]='nvgen -c -l 1 -t 1 -o 1'

sys_exec[4]='show process iedged location all'
sys__ksh[4]='sysmgr_show -o -p iedged -n all'

sys_exec[5]='show context location all'
if [[ "${PLATFORM_TYPE}" == "x86_64" ]]; then
    sys__ksh[5]='corehelper_context -c 0x1 -n all'
else
    sys__ksh[5]='dumper_context -c 0x1 -n all'
fi

sys_exec[6]='show redundancy location all'
sys__ksh[6]='redcon_show -n all'

sys_exec[7]='show logging'
sys__ksh[7]='show_logging'

sys_exec[8]=''
sys__ksh[8]=''

# subscriber session summary
sys_summary_exec[1]='show subscriber session all summary'
sys_summary__ksh[1]='show_iedge_subscriber -c session -w -a'

sys_summary_exec[2]='show subscriber feature accounting ma summary'
sys_summary__ksh[2]='show_acct_ma_feature -U'

sys_summary_exec[3]='show subscriber feature accounting ma SRG-Summary all'
sys_summary__ksh[3]='show_acct_ma_feature -A'

sys_summary_exec[4]=''
sys_summary__ksh[4]=''

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

# misc info
rp_exec[1]='show cli history detail'
rp__ksh[1]='show_parser_history -h 0x2'

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

###############################################################################
# Show commands that run on all RP or LC                                      #
###############################################################################
rplc_exec[1]='show process blocked'
if [[ "${PLATFORM_TYPE}" == "x86_64" ]]; then
    rplc__ksh[1]='sh_proc_ng_blocked all'
else
    rplc__ksh[1]='show_processes -b'
fi

rplc_exec[2]='show subscriber manager trace all location $location'
rplc__ksh[2]='show_iedge_ltrace -A -i $node_number'

rplc_exec[3]='show subscriber feature accounting ma trace all location $location'
rplc__ksh[3]='show_acct_ma_ltrace -i $node_number -A'

rplc_exec[4]='show subscriber feature accounting ma statistics debug location $location'
rplc__ksh[4]='show_acct_ma_feature -D -L $node_number'

rplc_exec[5]='show subscriber manager disconnect-history unique location $location'
rplc__ksh[5]='show_iedge_stats -l -h $node_number'

rplc_exec[6]='show subscriber manager disconnect-history last location $location'
rplc__ksh[6]='show_iedge_stats -q -h $node_number'

rplc_exec[7]='show subscriber manager fadb location $location'
rplc__ksh[7]='show_fadb_records -l -h $node_number'
 
rplc_exec[8]='show subscriber session all detail internal all location $location'
rplc__ksh[8]='show_iedge_subscriber -c session -z -a -e -o -h $node_number -g'

rplc_exec[9]='show subscriber session filter state disconnecting detail internal location $location'
rplc__ksh[9]='show_iedge_subscriber -c session -z -t dn -e -h $node_number'

rplc_exec[10]='show subscriber manager checkpoint label-management allocator location $location'
rplc__ksh[10]='show_iedge_checkpoint -l 0x1 -h $node_number'

rplc_exec[11]='show subscriber manager checkpoint service-profile location $location'
rplc__ksh[11]='show_iedge_checkpoint -v -h $node_number'

rplc_exec[12]='show radius'
rplc__ksh[12]='show_radius -y'

rplc_exec[13]='show subscriber manager disconnect-history last brief location $location'
rplc__ksh[13]='show_iedge_stats -u -h $node_number'

rplc_exec[14]=''
rplc__ksh[14]=''

# statistics
rplc_stats_exec[1]='show subscriber manager statistics debug total location $location'
rplc_stats__ksh[1]='show_iedge_stats -d db_total -h $node_number'

rplc_stats_exec[2]='show subscriber manager statistics HA location $location'
rplc_stats__ksh[2]='show_iedge_stats -a ha -h $node_number'

rplc_stats_exec[3]='show subscriber manager statistics PPSM server api detail location $location'
rplc_stats__ksh[3]='show_iedge_stats -m server-api-detail -h $node_number'

rplc_stats_exec[4]='show subscriber manager statistics PPSM server api total location $location'
rplc_stats__ksh[4]='show_iedge_stats -m server-api-total -h $node_number'

rplc_stats_exec[5]='show subscriber manager statistics PPSM server aipc total location $location'
rplc_stats__ksh[5]='show_iedge_stats -m server-aipc-total -h $node_number'

rplc_stats_exec[6]='show subscriber manager statistics PPSM client api location $location'
rplc_stats__ksh[6]='show_iedge_stats -m client -h $node_number'

rplc_stats_exec[7]='show subscriber manager statistics PPSM client aipc location $location'
rplc_stats__ksh[7]='show_iedge_stats -m client-aipc -h $node_number'

rplc_stats_exec[8]='show subscriber manager statistics PRE action total location $location'
rplc_stats__ksh[8]='show_iedge_stats -e act_total -h $node_number'

rplc_stats_exec[9]='show subscriber manager statistics PRE event total location $location'
rplc_stats__ksh[9]='show_iedge_stats -e ev_total -h $node_number'

rplc_stats_exec[10]='show subscriber manager statistics PRE internal total location $location'
rplc_stats__ksh[10]='show_iedge_stats -e in_total -h $node_number'

rplc_stats_exec[11]='show subscriber manager statistics AAA accounting total location $location'
rplc_stats__ksh[11]='show_iedge_stats -c acct_total -h $node_number'

rplc_stats_exec[12]='show subscriber manager statistics AAA authorization total location $location'
rplc_stats__ksh[12]='show_iedge_stats -c author_total -h $node_number'

rplc_stats_exec[13]='show subscriber manager statistics AAA authentication total location $location'
rplc_stats__ksh[13]='show_iedge_stats -c authen_total -h $node_number'

rplc_stats_exec[14]='show subscriber manager statistics AAA COA total location $location'
rplc_stats__ksh[14]='show_iedge_stats -o coa_total -h $node_number'

rplc_stats_exec[15]='show subscriber manager statistics SVM summary location $location' 
rplc_stats__ksh[15]='show_iedge_stats -v sum -h $node_number'

rplc_stats_exec[16]='show subscriber manager statistics SVM associate location $location' 
rplc_stats__ksh[16]='show_iedge_stats -v as -h $node_number'

rplc_stats_exec[17]='show subscriber manager statistics SVM events location $location' 
rplc_stats__ksh[17]='show_iedge_stats -v ev -h $node_number'

rplc_stats_exec[18]='show subscriber manager statistics SVM service location $location' 
rplc_stats__ksh[18]='show_iedge_stats -v se -h $node_number'

rplc_stats_exec[19]='show subscriber manager statistics SVM subscriber-data location $location' 
rplc_stats__ksh[19]='show_iedge_stats -v sub -h $node_number'

rplc_stats_exec[20]='show subscriber manager statistics SVM user-profile-data location $location' 
rplc_stats__ksh[20]='show_iedge_stats -v us -h $node_number'

rplc_stats_exec[21]='show subscriber manager statistics summary total location $location'
rplc_stats__ksh[21]='show_iedge_stats -c summ_total -h $node_number'

rplc_stats_exec[22]='show subscriber manager statistics SRG location $location'
rplc_stats__ksh[22]='show_iedge_stats -s -h $node_number'

rplc_stats_exec[23]='show subscriber feature accounting ma SRG-Summary all location $location'
rplc_stats__ksh[23]='show_acct_ma_feature -A -L $node_number'

rplc_stats_exec[24]='show subscriber manager statistics periodic total location $location'
rplc_stats__ksh[24]='show_iedge_stats -H -T -h $node_number'

rplc_stats_exec[25]='show subscriber manager statistics SRG master parent-interface location $location'
rplc_stats__ksh[25]='show_iedge_stats -s -M -h $node_number'

rplc_stats_exec[26]='show subscriber manager statistics SRG slave parent-interface location $location'
rplc_stats__ksh[26]='show_iedge_stats -s -S -h $node_number'

rplc_stats_exec[27]='show subscriber manager statistics FSM location $location'
rplc_stats__ksh[27]='show_iedge_stats -f -h $node_number'

rplc_stats_exec[28]=''
rplc_stats__ksh[28]=''

# subscriber session summary
rplc_summary_exec[1]='show subscriber session all summary location $location'
rplc_summary__ksh[1]='show_iedge_subscriber -c session -w -a -h $node_number'

rplc_summary_exec[2]='show subscriber manager session-history summary location $location'
rplc_summary__ksh[2]='show_iedge_stats -j -h $node_number'

rplc_summary_exec[3]='show subscriber manager disconnect-history unique summary location $location'
rplc_summary__ksh[3]='show_iedge_stats -p -h $node_number'

rplc_summary_exec[4]='show subscriber feature accounting ma summary location $location'
rplc_summary__ksh[4]='show_acct_ma_feature -U -L $node_number'

rplc_summary_exec[5]='show subscriber srg master session all summary  location $location'
rplc_summary__ksh[5]='show_iedge_subscriber -c session -w -a -M -h $node_number'

rplc_summary_exec[6]='show subscriber srg slave session all summary  location $location'
rplc_summary__ksh[6]='show_iedge_subscriber -c session -w -a -S -h $node_number'

rplc_summary_exec[7]='show subscriber manager disconnect-history last summary location $location'
rplc_summary__ksh[7]='show_iedge_stats -r -h $node_number'

rplc_summary_exec[8]=''
rplc_summary__ksh[8]=''

###############################################################################
# Session specific commands                                                   #
###############################################################################
session_rplc_exec[1]='show subscriber session subscriber-label $session_id location $location'
session_rplc__ksh[1]='show_iedge_subscriber -c session -s $session_id -h $node_number'

session_rplc_exec[2]='show subscriber manager checkpoint session subscriber-label $session_id location $location'
session_rplc__ksh[2]='show_iedge_checkpoint -s $session_id -h $node_number'

session_rplc_exec[3]=''
session_rplc__ksh[3]=''

###############################################################################
# Extra commands for HA and checkpointing information                         #
###############################################################################
ha_rplc_exec[1]='show subscriber manager checkpoint session all detail location $location'
ha_rplc__ksh[1]='show_iedge_checkpoint -a 0x0 -h $node_number'

ha_rplc_exec[2]=''
ha_rplc__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 iedge"

    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys
        exec_commands sys_summary
    else
        exec_commands rplc_summary
        case "$__cardtype" in
        "DRP"|"RP")
            if [ $summary -eq 0 ]; then
                exec_commands rp
                exec_commands rplc
            fi
            if [ "$session_id" != "unspecified" ]; then
                exec_commands session_rplc
            fi
            exec_commands rplc_stats
            if [ $ha -eq 1 ]; then
                exec_commands ha_rplc
            fi
            ;;
        "LC")
            if [ $summary -eq 0 ]; then
                exec_commands rplc
            fi
            if [ "$session_id" != "unspecified" ]; then
                exec_commands session_rplc
            fi
            exec_commands rplc_stats
            if [ $ha -eq 1 ]; then
                exec_commands ha_rplc
            fi
            ;;
        esac
    fi

    # Print the closing heading.
    print_main_heading "show tech-support iedge 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

