#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# adt_show_techsupport - Show tech-support script for adt
#
# Dec 2020, Nishad CM
#
# Copyright (c) 2020 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

# List each set of show commands to be run. Each set must finish with an empty
# string. Note that it is important to use single quotes rather than double
# quotes for the strings containing your commands.

__cardtype="unspecified"

node_name_internal=`uname -n`
node_number=`node_conversion -i $node_name_internal`
# This is a list of possible disks present
disk[0]="/disk0:/"
disk[1]="/disk1:/"
disk[2]="/bootflash:/"
disk[3]="/compactflash:/"
disk[4]="/dev/shmem/"
disk[5]=""

# Set the default values of the file name for which show tech-support license
# is to run and the file it is to write to.
# Read in the arguments to the script, setting node_required and filename
# according to these arguments.
# Note that it is important for security reasons that users can only enter
# alphanumeric filenames and nodes and that anywhere calling this script must
# enforce this.
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_acl_ipv4_fast: output file not specified"
    exit
fi

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


check_platform_type=`get_platform_type`

 # global commands on RP


###############################################################################
# Show commands that run once per LR                                          #
###############################################################################


sys_exec[1]='show install active'

if [[ "$check_platform_type" != "SCAPA" ]] &&
    [[ "$check_platform_type" != "PANINI" ]] &&
    [[ "$check_platform_type" != "IOS-XRv 9000" ]] &&
    [[ "$platform" != "panini" ]];  then

     if [[ "$check_platform_type" == "ASR9k" && "$platform" != "viking" ]]; then
         sys__ksh[1]='sdr_instcmd show install active'
     else
         sys__ksh[1]='instcmd show install active'
     fi
else

sys__ksh[1]='sdr_instcmd show install active'
fi

sys_exec[2]='show version'

if [[ "$check_platform_type" != "SCAPA" ]] &&
    [[ "$check_platform_type" != "PANINI" ]] &&
    [[ "$check_platform_type" != "IOS-XRv 9000" ]] &&
    [[ "$platform" != "panini" ]];  then

     if [[ "$check_platform_type" == "ASR9k" && "$platform" != "viking" ]]; then
         sys__ksh[2]='ng_show_version'
     else
         sys__ksh[2]='show_version'
     fi
else

sys__ksh[2]='ng_show_version'
fi

sys_exec[3]='show platform'

if [[ "$check_platform_type" != "SCAPA" ]] && 
    [[ "$check_platform_type" != "PANINI" ]] &&
    [[ "$check_platform_type" != "IOS-XRv 9000" ]] &&
    [[ "$platform" != "panini" ]];  then

     if [[ "$check_platform_type" == "ASR9k" && "$platform" != "viking" ]]; then
         sys__ksh[3]='show_platform_sysdb'
     else
         sys__ksh[3]='show_platform'
     fi
else

sys__ksh[3]='show_platform_sysdb'
fi


sys_exec[4]=''
sys__ksh[4]=''


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



rp_exec[1]='show context location all'
rp__ksh[1]='redcon_show -n all'

rp_exec[2]='show adt trace error'
rp__ksh[2]='adt_show_ltrace -E'

rp_exec[3]='show adt trace all'
rp__ksh[3]='adt_show_ltrace -A'

rp_exec[4]='show adt statistics'
rp__ksh[4]='adt_oper_command statistics'

rp_exec[5]='show adt subscription'
rp__ksh[5]='adt_oper_command subscription'

rp_exec[6]='show adt subscription details'
rp__ksh[6]='adt_oper_command subscription details'

rp_exec[7]='show adt events'
rp__ksh[7]='adt_show_output -e'

rp_exec[8]='show cli history detail'
rp__ksh[8]='show_parser_history -h 0x2'

rp_exec[9]='show process adt_main'
rp__ksh[9]='sysmgr_show -o -p adt_main'

rp_exec[10]='show logging'
rp__ksh[10]='show_logging'

rp_exec[11]='show running-config adt'
rp__ksh[11]='nvgen -c -q gl/adt/'

rp_exec[12]='show running-config'
rp__ksh[12]='nvgen -c -l 1 -t 1 -o 1'

rp_exec[13]='run tar -zcf $__tar_file_directory/adt_detector_release_note.tar /misc/disk1/adt/_MEI*/xradt_releasenotes.txt'
rp__ksh[13]='tar -zcf $__tar_file_directory/adt_detector_release_note.tar /misc/disk1/adt/_MEI*/xradt_releasenotes.txt'

rp_exec[14]='run tar -zcf $__tar_file_directory/adt_detector_log_data.tar /var/log/adt_detector.log*'
rp__ksh[14]='tar -zcf $__tar_file_directory/adt_detector_log_data.tar /var/log/adt_detector.log*'

rp_exec[15]='run tar -zcf $__tar_file_directory/adt_detector_log_debugall.tar /misc/disk1/adt/log/*'
rp__ksh[15]='tar -zcf $__tar_file_directory/adt_detector_log_debugall.tar /misc/disk1/adt/log/*'

rp_exec[16]=''
rp__ksh[16]=''


###############################################################################
# Show commands of ADT stats that run on every RP                             #
###############################################################################

# Parse the arguments to the script.
# Usage:
#
#sys.exit()
# A function called display() must be provided that calls the functions to
# Print the output heading
do_show_command() {
     print_main_heading "show tech-support adt"

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

     # Print the closing heading.
     print_main_heading "show tech-support adt complete"
}
# The display function.
display() {
        do_show_command
}

  # 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


