#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# statsd_show_tech - Show tech-support script for statsd
#
# February 2008, Michelle Hawke
#
# Copyright (c) 2008-2010, 2013-2014, 2018 by cisco Systems, Inc.
# All rights reserved.
#--------------------------------------------------------------------


. /pkg/bin/show_tech_main_fragment

# List each set of show commands to be run. Each set must finish with an empty
# string. Note that it is important to use single quotes rather than double 
# quotes for the strings containing your commands. 

###########
# Commands
###########

#
# 1 - Commands that run once per system
# 
sys_exec[1]='show logging'
sys__ksh[1]='show_logging'
sys_exec[2]='show stats requests detail'
sys__ksh[2]='smgr_show_requests -d'
sys_exec[3]='show statsd collectors brief'
sys__ksh[3]='statsd_show -c -b'
sys_exec[4]='show statsd collectors detail'
sys__ksh[4]='statsd_show -c -d'
sys_exec[5]='show statsd manager info'
sys__ksh[5]='statsd_show -m'
# For ifh to interface mapping
sys_exec[6]='show im database brief'
sys__ksh[6]='im_show database -l 0x1'
# For a record of who is polling the EDM
sys_exec[7]='show sysdb trace edm shared-plane'
sys__ksh[7]='sysdb_show_ltrace -T edm -s -R active'
sys__ksh[8]=''


#
# 2- Commands that run on RP and LC nodes
#
rplc_exec[1]='show statsd manager trace'
rplc__ksh[1]='smgr_show_ltrace'
rplc_exec[2]='show statsd library collector trace'
rplc__ksh[2]='statsd_show_ltrace -C'
rplc_exec[3]='show statsd library access trace'
rplc__ksh[3]='statsd_show_ltrace -D'
rplc_exec[4]='show statsd server trace'
rplc__ksh[4]='ssvr_show_ltrace'
rplc_exec[5]='show processes statsd_server'
rplc__ksh[5]='sysmgr_show -o -p statsd_server'
rplc_exec[6]='show processes statsd_manager_l'
rplc__ksh[6]='sysmgr_show -o -p statsd_manager_l'

# GSP groups used by statsd
# Note that RP-only groups are given in the list of RP-only commands
rplc_exec[7]='show gsp group name statsd_global_group'
rplc__ksh[7]='gsp_show -n statsd_global_group'
rplc_exec[8]='show gsp group name statsd_local_group'
rplc__ksh[8]='gsp_show -n statsd_local_group'
rplc_exec[9]='show gsp group name statsd_mgr_global_group'
rplc__ksh[9]='gsp_show -n statsd_mgr_global_group'
rplc_exec[10]='show gsp group name statsd_mgr_local_group'
rplc__ksh[10]='gsp_show -n statsd_mgr_local_group'
rplc_exec[11]='show gsp group name statsd_mgr_resolve_group'
rplc__ksh[11]='gsp_show -n statsd_mgr_resolve_group'
rplc_exec[12]='show gsp group name statsd_access_group'
rplc__ksh[12]='gsp_show -n statsd_access_group'
rplc_exec[13]='show gsp group name statsd_access_mgr_local'
rplc__ksh[13]='gsp_show -n statsd_access_mgr_local'
rplc_exec[14]='show gsp group name statsd_access_mgr_global'
rplc__ksh[14]='gsp_show -n statsd_access_mgr_global'

# For JID to name mapping
rplc_exec[15]='show processes'
# assumes "platform" is set for us by show_tech_main_fragment
rplc__ksh[15]='show_processes'

# For PID to name mapping
OS_STRING=`uname`

if [ "$OS_STRING" = "QNX" ]
then
    rplc_exec[16]='show processes pidin'
    rplc__ksh[16]='show_processes -d'
    rplc__ksh[17]=''
else
    rplc__ksh[16]=''
fi


#
# 3 - Commands that run on all SCs
#
sc__ksh[1]=''


#
# 4 - Commands that run on all SPs
#
sp__ksh[1]=''


#
# 5 - Commands that run on all RPs
#
rp_exec[1]='show processes statsd_manager_g'
rp__ksh[1]='sysmgr_show -o -p statsd_manager_g'
rp_exec[2]='show gsp group name "statsd_mgr_replication_group"'
rp__ksh[2]='gsp_show -n statsd_mgr_local_group'
rp__ksh[3]=''


###########
# Variables
###########

# The script has no variables at the moment
#

#
# Parse the arguments to the script
#
__cardtype="unspecified"

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


###########
# SCRIPT
###########

# A function called display() must be provided that calls the functions to 
# run the required show commands. The display() function will be called in 
# the /pkg/bin/show_tech_comp_file_frag
display() {

     # Print the output heading 
     print_main_heading "show tech-support statsd"

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

     # Print the closing heading. 
     print_main_heading "show tech-support statsd complete"
}

# This function calls the display() function and sends the output to file if
# the file option has been set. 
. /pkg/bin/show_tech_file_fragment

