#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_telemetry - Telemetry tech-support show command
#
# October 2015, Tristan Shephard
#
# Copyright (c) 2015-2017 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 [ "$__cardtype" == "unspecified" ]; then
    __cardtype=`node_type`
fi

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

#############################################################
# All show commands that run once per RP

# User telemetry commands
rp_exec[1]='show telemetry policy-driven policies verbose'
rp__ksh[1]='telemetry_show_policy --verbose'

rp_exec[2]='show telemetry policy-driven tcp-endpoints verbose'
rp__ksh[2]='telemetry_show_endpoints --verbose'

# Internal telemetry commands
rp_exec[3]='show telemetry policy-driven internal database'
rp__ksh[3]='telemetry_show_db'

# Trace telemetry commands
rp_exec[4]='show telemetry policy-driven internal bte trace'
rp__ksh[4]='bte_trace_decode'
rp_exec[5]='show telemetry policy-driven trace'
rp__ksh[5]='show_telemetry_trace -b periodic events errors'

rp_exec[6]='show processes telemetry_encoder'
rp__ksh[6]='sysmgr_show -o -p telemetry_encoder'

# General Commands
rp_exec[7]='show running'
rp__ksh[7]='nvgen -c -l 1 -t 1 -o 1'
rp_exec[8]='show logging'
rp__ksh[8]='show_logging'
rp_exec[9]='show platform'
# rp__ksh[9] below
rp_exec[10]='show install active'
# rp__ksh[10] below
rp_exec[11]='show version brief'
# rp__ksh[11] below
rp_exec[12]='show context all'
#rp__ksh[12] below

# Determine the right ksh command for "show platform"
if [ "$platform" == "viking" ]; then
    rp__ksh[9]='show_platform_vkg -e'
elif [ "$platform" == "panini" ]; then
    rp__ksh[9]='show_platform_sysdb'
else
    rp__ksh[9]='show_platform'
fi

# Determine the right ksh commands for "show install/ver/context"
if [ "$platform" == "panini" ]; then
    rp__ksh[10]='sdr_instcmd show install active'
    rp__ksh[11]='ng_show_version'
    rp__ksh[12]='corehelper_context -c 0x1 -n all'
else
    rp__ksh[10]='instcmd show install active'
    rp__ksh[11]='show_version -b'
    rp__ksh[12]='dumper_context -c 0x1 -n all'
fi

#############################################################
# Script

display() {
    print_main_heading "show tech-support telemetry"
    case "$__cardtype" in
	"RP")
	    exec_commands rp
	    ;;
	"DRP")
	    exec_commands rp
	    ;;
	esac
    print_main_heading "show tech-support telemetry complete"
}

# Run the appropriate function depending on the node specified and if a
# file is specified write the output to that file.
. /pkg/bin/show_tech_file_fragment
