#!/pkg/bin/ksh
#------------------------------------------------------------------
# show tech-support config-group command
#
# This command will be deprecated, as it is not in use and is 
# subset of "show tech sysdb". Hence sysdb team decided to deprecate
# it using CSCvk06159.
#
# March 2012, Nishant Burte 
#
# Copyright (c) 2012-2013, 2018 by cisco Systems, Inc.
# All rights reserved.
#------------------------------------------------------------------

#
# Include the standard show tech-support functions
#
. /pkg/bin/show_tech_main_fragment

PLATFORM_TYPE=`uname -m`

#
# Commands to run, grouped by location/plane. Collect the traces first, as 
# these are more likely to wrap.
#

#
# Local Plane Commands
#
local_exec[1]='show sysdb trace config-grp location $location'
local__ksh[1]='sysdb_show_ltrace -T config_grp -i $fq_nodeid'


#
# Shared Plane Commands
#

shared_exec[1]="show sysdb trace config-grp shared-plane"
shared__ksh[1]='sysdb_show_ltrace -T config_grp -s active'

#
# Admin Plane Commands
#

#
# Find the process IDs of the four SysDB processes
#
sysdb_mc_pid=`pidin | grep sysdb_mc | cut -c1-8 | head -n 1`
sysdb_shared_nc_pid=`pidin | grep sysdb_shared_nc | cut -c1-8 | head -n 1`
sysdb_shared_sc_pid=`pidin | grep sysdb_shared_sc | cut -c1-8 | head -n 1`
sysdb_admin_pid=`pidin | grep sysdb_svr_admin | cut -c1-8 | head -n 1`
sysdb_local_pid=`pidin | grep sysdb_svr_local | cut -c1-8 | head -n 1`

#
# Follow (attach_process) Commands
#

attach_exec[1]="follow process $sysdb_mc_pid iteration 1 verbose"
attach__ksh[1]="attach_process -p $sysdb_mc_pid -i 1"
attach_exec[2]="follow process $sysdb_shared_nc_pid iteration 1 verbose"
attach__ksh[2]="attach_process -p $sysdb_shared_nc_pid -i 1"
attach_exec[3]="follow process $sysdb_shared_sc_pid iteration 1 verbose"
attach__ksh[3]="attach_process -p $sysdb_shared_sc_pid -i 1"
attach_exec[4]="follow process $sysdb_admin_pid iteration 1 verbose"
attach__ksh[4]="attach_process -p $sysdb_admin_pid -i 1"
attach_exec[5]="follow process $sysdb_local_pid iteration 1 verbose"
attach__ksh[5]="attach_process -p $sysdb_local_pid -i 1"

#
# process Commands
#

block_exec[1]="show processes block"
block__ksh[1]='show_processes -b'

logging_exec[1]="show logging"
logging__ksh[1]='show_logging'

system_exec[1]="show redundancy"
system__ksh[1]='redcon_show'
if [[ "${PLATFORM_TYPE}" == "enxr" ]]; then
    system_exec[2]="admin show platform"
    system__ksh[2]='show_platform -a'
elif [[ "${PLATFORM_TYPE}" == "asr9k"* ]]; then
    system_exec[2]="admin show platform"
    system__ksh[2]='show_platform_vkg -a'
elif [[ "${PLATFORM_TYPE}" == "hfr-rp" ]]; then
    system_exec[2]="admin show platform"
    system__ksh[2]='shelfmgr_show_hfr -a'
fi

#
# Variable used to enable admin mode and shared plane commands
# 
admin=0;
shared=0;
location=0;
__cardtype=0;

#
# We are interested in the -A (admin plane), -S (shared plane) options now.
# -L (specific node) and -t options are reserved for furture release.
# Each option collect follows information.
#   -A : admin + shared + local plane.
#   -S : shared + local plane.
# Notice: current 'show tech multi config-group' doesn't collect any information
#        from SP because of memory shortage on SP.
#
while [ "$#" -gt "0" ]; do
    case "$1" in
        -A) admin=1;                    shift 1;;
        -S) shared=1;                   shift 1;;
        -L) location="$2";              shift 2;;
        -t) __cardtype="$2";            shift 2;;
        *)  default_parser_function $@; shift $#;;
    esac
done


#
# Our display function
#
display() {
    #
    # Display a header
    #
    if [ $admin -eq 1 ]; then
        print_main_heading "show tech-support multi-chassis config-group on admin plane"
    elif [ $shared -eq 1 ]; then
        print_main_heading "show tech-support multi-chassis config-group on shared plane"
    else
        print_main_heading "show tech-support multi-chassis config-group on location $location"
    fi  

    if [ "$__cardtype" == "SYS" ]; then
        #
        # Display the nodes in the LR or system
        # Display the redundancy status of the system
        #
        exec_commands system

        #
        # Run all the admin plane show commands
        #
        if [ $admin -eq 1 ]; then
            exec_commands admin
        fi;

        #
        # run the shared plane commands
        #
        exec_commands shared

        #
        # Collect the logging output as this is always helpful in
        # debugging issues.
        #
        exec_commands logging

    else
        #
        # Collect follow for all SysDB processes.
        #  - Collect once here and once towards the end of the show tech to
        # avoid the sleep which is normally between the iterations of follow
        # @@@ Note that because follow will not allow us to specify a process 
        # name we can only follow the process on the current node. If follow
        # ever adds this function, we should change these commands to use the
        # process name 
        #
        print_command_heading "follow sysdb processes"
        cat <<EOF
These commands are run once now and once towards the end of the
command. This is to avoid the delay between iterations of follow
EOF

        #
        # attach_process
        #
        exec_commands attach

        #
        # run the local plane commands
        #
        exec_commands local

        #
        # attach_process
        # Collect follow for all SysDB processes for the second time. 
        #
        exec_commands attach

        exec_commands block

    fi

    #
    # Display a footer
    #
    print_main_heading "show tech-support multi-chassis config-group complete"

}

#
# Use the standard show tech-support infra to call our display function and
# send the output to console or file
#
. /pkg/bin/show_tech_file_fragment

