#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_ntp - ntp show tech commands
#
# March 2014 - Aditya Dogra
#
# Copyright (c) 2014-2015 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_ntp: 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=$?

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"
else
    platform="panini"
fi


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

#############################################################
# Show commands that run once per system                    #          
#############################################################
sys_show_exec[1]='show version'
sys_show_exec[2]='show logging'
sys_show__ksh[2]='show_logging'
sys_show_exec[3]="show install active summary"
sys_show_exec[4]="show placement"
sys_show__ksh[4]='placed_show -c node/'
sys_show_exec[5]='show running-config'
sys_show__ksh[5]='nvgen -c -l 1 -t 1 -o 1'
sys_show_exec[6]='show platform'
if [[ "$platform" = "viking" ]]; then
     sys_show__ksh[1]='show_version -b'
     sys_show__ksh[3]='instcmd show install active summary'
     sys_show__ksh[6]='show_platform_vkg -e'
elif [[ "$platform" = "panini" ]]; then
     sys_show__ksh[1]='ng_show_version'
     sys_show__ksh[3]='sdr_instcmd show install active'
     sys_show__ksh[6]='show_platform_sysdb -v'
else
     sys_show__ksh[1]='show_version -b'
     sys_show__ksh[3]='instcmd show install active summary'
     sys_show__ksh[6]='show_platform -a'
fi
sys_show_exec[7]='show ntp drift'
sys_show__ksh[7]='ntp_command show -c'
sys_show_exec[8]='show interfaces'
sys_show__ksh[8]='show_interface -a'
sys_show__ksh[9]=''

#############################################################
# Commands that run on RP and LC nodes                      #
#############################################################
rplc_show_exec[1]='show process blocked location $location'
rplc_show_exec[2]='show ntp associations'
rplc_show__ksh[2]='ntp_command show -a'
rplc_show_exec[3]='show ntp status'
rplc_show__ksh[3]='ntp_command show -s'
rplc_show_exec[4]='show ntp history'
rplc_show__ksh[4]='ntp_command show -h'
rplc_show_exec[5]='show ntp trace'
rplc_show__ksh[5]='ntp_show_ltrace'
rplc_show_exec[6]='show clock'
rplc_show__ksh[6]='iosclock -d 0x0'
rplc_show_exec[7]='run top procs'
if [[ "$platform" = "panini" ]]; then
    rplc_show__ksh[1]='sh_proc_ng_blocked -l $fq_nodeid'
    rplc_show__ksh[7]='top -bn1'
else
    rplc_show__ksh[1]='show_processes -b $fq_nodeid'
    rplc_show__ksh[7]='top_procs -n10 -D -i1'
fi
rplc_show__ksh[8]=''



#############################################################
#  Display function for show tech ntp Script       #
#############################################################

display() {
    print_main_heading "show tech-support ntp"

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

    print_main_heading "show tech-support ntp 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
