#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# nacm_show_techsupport - Show tech-support script for nacm
#
# Oct 2020, Ravi Shankar
#
# 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'
sys__ksh[1]='sdr_instcmd show install active'                               
                                                                                

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 logging'
rp__ksh[1]='show_logging'

rp_exec[2]='show redundancy location all'
rp__ksh[2]='redcon_show -n all'

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

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

rp_exec[5]='show nacm summary'
rp__ksh[5]='show_nacmd -o 0x4'

rp_exec[6]='show nacm groups'
rp__ksh[6]='show_nacmd -o 0x1'

rp_exec[7]='show nacm users'
rp__ksh[7]='show_nacmd -o 0x2'

rp_exec[7]='show nacm rule-list'
rp__ksh[7]='show_nacmd -o 0x3'

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

###############################################################################
# Show commands of nacm traces that run on every RP/LC                      #
###############################################################################
rplc_exec[1]='show nacm trace generic'
rplc__ksh[1]='nacmd_show_ltrace -G 1'

rplc_exec[2]='show nacm trace config'
rplc__ksh[2]='nacmd_show_ltrace -C 1'

rplc_exec[3]='show nacm trace author'
rplc__ksh[3]='show_nacm_ltrace -R 1'

###############################################################################
# Show commands of nacm that run on every RP/LC                             #
###############################################################################
rplc_exec[4]='show process nacmd'
rplc__ksh[4]='sysmgr_show -o -p nacmd'

rplc_exec[5]='show process blocked'
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
       rplc__ksh[5]='sh_proc_ng_blocked'
   else
       rplc__ksh[5]='show_processes -b'
   fi
else

rplc__ksh[5]='sh_proc_ng_blocked'
fi

rplc_exec[6]='show nacm location $location '
rplc__ksh[6]='show_nacm -y -l $node_number'

rplc_exec[7]=''
rplc__ksh[7]=''
###############################################################################
# Show commands of nacm stats that run on every RP/LC                       #
###############################################################################

# 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 nacm"

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

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


