#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_perfmgmt - Script to colelct showtech for perfmgmt
#
# August  2014 - hemamoha
#
# Copyright (c) 2014 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 [ "$__filename" = "unspecified" ]; then
    echo "show_tech_testing: output file not specified"
    exit
fi
if [ "$__cardtype" == "unspecified" ]; then
    __cardtype=`node_type`
fi
uname -a | grep hfr > /dev/null 2>&1;  RC=$?
uname -a | grep prp > /dev/null 2>&1;  RC1=$?
uname -a | grep enxr > /dev/null 2>&1; RC2=$?
uname -a | grep asr9k > /dev/null 2>&1; RC3=$?
uname -a | grep xrvr > /dev/null 2>&1; RC4=$?
uname -a | grep x86_64 > /dev/null 2>&1; RC5=$?
if [[ "$RC" -eq "0" ]]; then
    platform="hfr"
elif [[ "$RC1" -eq "0" ]]; then
    platform="prp"
elif [[ "$RC2" -eq "0" ]]; then
    platform="enxr"
elif [[ "$RC3" -eq "0" ]]; then
    platform="viking"
elif [[ "$RC4" -eq "0" ]]; then
    platform="xrvr"
elif [[ "$RC5" -eq "0" ]]; then
    platform="panini"
else
    platform="Unsupported Platform"
fi

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


#############################################################
# Show commands that run once per system                    #
# perfmgmt is a rp only component. Both pm_server &         #
# pm_collector run on RP only.                              #
#############################################################
sys_show_exec[1]='show version'
if [[ "$platform" = "viking" ]]; then
     sys_show__ksh[1]='show_version -b'
elif [[ "$platform" = "panini" ]]; then
     sys_show__ksh[1]='ng_show_version'
else
     sys_show__ksh[1]='show_version'
fi

sys_show_exec[2]='show logging'
sys_show__ksh[2]='show_logging'

sys_show_exec[3]='show platform'
if [[ "$platform" = "viking" ]]; then
     sys_show__ksh[3]='show_platform_vkg -e'
elif [[ "$platform" = "panini" ]]; then
     sys_show__ksh[3]='show_platform_sysdb -v'
else
     sys_show__ksh[3]='show_platform '
fi

sys_show_exec[4]='show install active summary'
if [[ "$platform" = "panini" ]]; then
     sys_show__ksh[4]='sdr_instcmd show install active'  #show install active summary
else
     sys_show__ksh[4]='instcmd show install active summary' #show install active summary
fi

sys_show_exec[5]='show process pm_server'
sys_show__ksh[5]='sysmgr_show -o -p pm_server'

sys_show_exec[6]='show process pm_collector'
sys_show__ksh[6]='sysmgr_show -o -p pm_collector'

sys_show_exec[7]='show running-config'
sys_show__ksh[7]='nvgen -c -l 1 -t 1 -o 1'   # show running-config

sys_show_exec[8]='show interfaces brief'
sys_show__ksh[8]='show_interface -a -o 0x2'

sys_show_exec[9]='show ipv4 interface brief'
sys_show__ksh[9]='show_ip_interface -b -v default'

sys_show_exec[10]='show ipv6 interface brief'
sys_show__ksh[10]='show_ipv6_interface -b -v default'

sys_show_exec[11]='show bgp summary'
sys_show__ksh[11]='bgp_show -V default -A 0x1 -W 0x1 -n -s -instance default'

sys_show_exec[12]='show ospf'
sys_show__ksh[12]='ospf_show -T + -v + -l active'

sys_show_exec[13]='show ospfv3'
sys_show__ksh[13]='ospfv3_show_ospf -T + -v + -L active'

sys_show_exec[14]='show mpls ldp neighbor brief'
sys_show__ksh[14]='mpls_ldp_show -t 0x4 -v default 0x1 -Z false -b'

sys_show_exec[15]='show checkpoint dynamic process pm_server'
sys_show__ksh[15]='chkpt_cli -p pm_server'

sys_show_exec[16]='show checkpoint dynamic process pm_server table name 0 version 0'
sys_show__ksh[16]='chkpt_cli -p pm_server -n 0 -v 0'

sys_show_exec[17]='show checkpoint dynamic process pm_collector'
sys_show__ksh[17]='chkpt_cli -p pm_collector'

sys_show_exec[18]='show checkpoint dynamic process pm_collector table name 0 version 0'
sys_show__ksh[18]='chkpt_cli -p pm_collector -n 0 -v 0'

sys_show_exec[19]='show performance-mgmt trace pm-collector'
sys_show__ksh[19]='show_pm_coll_ltrace -G'

sys_show_exec[20]=''
sys_show__ksh[20]=''

#############################################################
# Commands that run on RP and LC nodes seperately           #
#############################################################
local_exec[1]='show sysdb trace edm location $location'
local__ksh[1]='sysdb_show_ltrace -T edm -i $fq_nodeid'

local_exec[2]='show processes blocked location $location' 
if [[ "$platform" = "panini" ]]; then
     local__ksh[2]='sh_proc_ng_blocked ' #show process blocked
elif [[ "$platform" = "enxr" ]]; then
     local__ksh[2]='show_processes -b -n $location' #show process blocked
else
     local__ksh[2]='show_processes -b -n $fq_nodeid' #show process blocked
fi

local_exec[3]='run top procs'
if [[ "$platform" = "panini" ]]; then
    local__ksh[3]='top -bn1' # run top procs
else
    local__ksh[3]='top_procs -n10 -D -i1'  # run top procs
fi

local_exec[4]=''
local__ksh[4]=''

#############################################################
#  Display function for show tech testing Script       #
#############################################################
display() {
    print_main_heading "show tech-support performance-mgmt "
    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys_show
    else
        exec_commands local
    fi
    print_main_heading "show tech-support performance-mgmt 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
