#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_resmon - resmon 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_resmon: output file not specified"
    exit
fi

if [ "$__cardtype" == "unspecified" ]; then
    __cardtype=`node_type`
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__ksh[1]='ng_show_version'
sys_show_exec[2]='show logging'
sys_show__ksh[2]='show_logging'
sys_show_exec[3]="show install active summary"
sys_show__ksh[3]='sdr_instcmd show install active'
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'
sys_show__ksh[6]='show_platform_sysdb -v'
sys_show_exec[7]="show watchdog memory-state location all"
sys_show__ksh[7]='show_watchdog -n all'
sys_show_exec[8]="show watchdog overload state location all "
sys_show__ksh[8]='show_watchdog_overload -n all -s'
sys_show_exec[9]="show watchdog threshold memory configured location all"
sys_show__ksh[9]='show_watchdog -n all -c'
sys_show_exec[10]="show watchdog threshold memory defaults location all"
sys_show__ksh[10]='show_watchdog -n all -d'
sys_show_exec[11]="show memory summary location all"
sys_show__ksh[11]='show_memory_ng -n all -s'
sys_show__ksh[12]=''

#############################################################
# Commands that run on RP and LC nodes                      #
#############################################################
rplc_show_exec[1]='show process blocked location $location'
rplc_show__ksh[1]='sh_proc_ng_blocked -l $fq_nodeid'
rplc_show_exec[2]="show watchdog trace"
rplc_show__ksh[2]='show_watchdog_trace'
rplc_show_exec[3]='run top procs'
rplc_show__ksh[3]='top -bn1'
rplc_show_exec[4]='show processes cpu location $location'
rplc_show__ksh[4]='show_watchdog -p -n $fq_nodeid'
rplc_show_exec[5]='show processes memory location $location'
rplc_show__ksh[5]='sh_proc_memory_sort "sh_proc_memory    -l $fq_nodeid"'
rplc_show_exec[6]='show processes all location $location'
rplc_show__ksh[6]='sysmgr_show -o -a -n $fq_nodeid'
rplc_show_exec[7]='show processes files location $location'
rplc_show__ksh[7]='sh_proc_files -l $fq_nodeid'
rplc_show__ksh[8]=''



#############################################################
#  Display function for show tech resmon Script       #
#############################################################

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

    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 resmon 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
