#!/bin/sh
#
#
#    Copyright (c) 1996-2015 Brocade Communications Systems, Inc.
#    All rights reserved.
#
#    File name:   flowVision.sh
#    Desc: dumps supportInfo for flowVision


start_dump() {
        ORG_PATH=`echo $PATH`
        export PATH=/fabos/link_bin:/bin:/usr/bin:/sbin:/usr/sbin:/fabos/link_abin:/fabos/link_sbin:/fabos/link_rbin:/fabos/factory:/fabos/xtool:.:/

        #Dump NM Info
        /bin/echo "======== FLOW VISION Data Switch $FABOS_SWITCHNO ========================"
        /bin/echo ""
        /bin/echo "------------ The flows active on this switch---------------------------"
        flow --show
        /bin/echo "------------ All flows active on this switch---------------------------"
        flow --show all
        /bin/echo ""

		switchshow | grep switchMode | grep -q Analytics
		ANALYTICS=$?
		if [ "$ANALYTICS" == 0 ]; then
			/bin/echo "------------ All Analytic IT Flows on this switch---------------------------"
			flow --show sys_mon_analytics -srcdev "*" -dstdev "*"
			/bin/echo ""
			/bin/echo "------------ Flow PID DB related debug info -----------------"
			flow --debug pidlist
			/bin/echo ""
			/bin/echo "------------ Flows DB related debug info -----------------" 
			flow --debug flow
			/bin/echo ""
			if [ "$FABOS_SWITCHNO" == 0 ]; then
				/bin/echo "------------ Multipath dump --------------------------"
				flow --debug multipath
				/bin/echo "------------ NP sysdb dump ---------------------------"
				flow --debug sysdb
				/bin/echo "------------ Analytics resources on chassis ------------------------------"
	                        flow --show -resource
				/bin/echo "------------ Analytics Resources per FID -------------"
				flow --show -resource -fid
			fi
		else
			/bin/echo "------------ Flow Generator related debug info ---------------------------"
			flow --debug fg
			/bin/echo ""
			/bin/echo "------------ NP flow dump ---------------------------"
			flow --debug flow
			/bin/echo ""
			if [ "$FABOS_SWITCHNO" == 0 ]; then
				/bin/echo "------------ NP sysdb dump ---------------------------"
				flow --debug sysdb
				/bin/echo "------------ Flow Monitor related debug info ---------------------------"
				flow --debug fpm
				/bin/echo "------------ Flow Mirror related debug info -----------------"
				flow --debug mirror
			fi
		fi
		/bin/echo ""
		/bin/echo ""
		/bin/echo "------------ NP deamon (npd) info---------------------------"
		npd_pid=`pidof npd` 
		if [ "$npd_pid" == "" ]; then
			/bin/echo "npd is not running"
		else
			/bin/echo "------------output of ps aux---------------------------"
			/bin/ps aux | grep npd | grep -v grep
		fi

		if [ "$ANALYTICS" == 0 ]; then
			/bin/echo ""
			/bin/echo "===============OUTPUT OF FILES PRESENT IN SSD================="
			DP0_MNT_DIR=/nfsshare
			DP1_MNT_DIR=/nfsshare1
			PCAP_MNT_DIR=$DP0_MNT_DIR/pcapstore/
			SIZE=$PCAP_MNT_DIR/size
			if [ -d "$DP1_MNT_DIR" ]; then
				/bin/echo ""
				/bin/echo "----------------ls -l /nfsshare1----------------"
				/bin/ls -l /nfsshare1
			else
				/bin/echo ""
				/bin/echo "----------------ls -l /nfsshare1----------------"
				/bin/echo "The directory /nfsshare1 is not present"
			fi

			if [ -d "$DP0_MNT_DIR" ]; then
				/bin/echo ""
				/bin/echo "----------------ls -l /nfsshare----------------"
				/bin/ls -l /nfsshare
				/bin/echo ""
				if [ -d "$PCAP_MNT_DIR" ]; then
					/bin/echo ""
					/bin/echo "----------------ls -l /nfsshare/pcapstore--------------"
					/bin/ls -l /nfsshare/pcapstore

					if [ -e "$SIZE" ]; then
					/bin/echo ""
					/bin/echo "----------------cat /nfsshare/pcapstore/size--------------"
					/bin/cat /nfsshare/pcapstore/size
					else
					/bin/echo ""
					/bin/echo "The file /nfsshare/pcapstore/size is not present"
					fi
					for sw in 0 1 2 3
					do
						if [ -d "$PCAP_MNT_DIR/$sw" ]; then
						/bin/echo ""
						/bin/echo "-----------ls -l /nfsshare/pcapstore/$sw----------"
						/bin/ls -l /nfsshare/pcapstore/$sw
						fi
					done
						
				else
					/bin/echo ""
					/bin/echo "The directory /nfsshare/pcapstore is not present"
				fi
			else
				/bin/echo ""
				/bin/echo "----------------ls -l /nfsshare----------------"
				/bin/echo "The directory /nfsshare is not present"
			fi
		fi
		/bin/echo ""
		/bin/echo "------------NP Config files ---------------------------"
		/bin/echo "------------output of ls /etc/fabos/np.*--------------------"
		/bin/ls -lh /etc/fabos/ | grep -i np
		/bin/echo ""
}

start_dump
