# $language = "VBScript"
# $interface = "1.0"
Sub Command(comm)
	crt.screen.send comm & chr(13)
	crt.screen.WaitForString "#"
End Sub
Sub Command1(comm)
	crt.screen.send comm & chr(13)
	crt.screen.WaitForString ">"
End Sub
Sub Main
    crt.Screen.Synchronous = False

    Command "enable"	
	Command "end"
    Command "enable"
	Command "terminal length 0"
    Command "show clock"
	Command "! Current client's system time is "&Date&" "&Time
	Command "等待1秒"
	crt.sleep 1000
	Command "高端及数据中心交换机信息收集开始"
	Command "第一部分：软件版本"
	Command "show version detail"
	Command "show version slot"
    currLine = crt.screen.CurrentRow    '截屏截至位置
    oldLine = currLine-30   '截屏开始位置
    strResult = Crt.Screen.Get2(oldLine,1,currLine,103) '截屏，取30行
	Command "show cpld version"
        DataHandle(strResult) 'DATA加载信息检测
	Command "等待1秒"
	crt.sleep 1000
	Command "第二部分：软件调试"
	Command "第二部分：软件调试--端口配置--接口配置规范"
	Command "show interfaces counters errors"
	Command "clear counters"
	Command "show interfaces status"
	Command "等待2秒"
        crt.sleep 2000
	Command "show interfaces counters summary"
	Command "show interfaces counters rate"
    Command "show poe interfaces status"
        crt.sleep 1000
	Command "第二部分：软件调试--生成树功能-生成树模式"
	Command "show spanning-tree"
	Command "第二部分：软件调试--生成树功能-生成树优先级控制"
	Command "show spanning-tree summary"
	Command "show spanning-tree counters"
	Command "第二部分：软件调试--生成树功能-生成树优化"
	Command "等待1秒"
        crt.sleep 1000
	Command "第二部分：软件调试--NFPP配置-ARP-Guard"
	Command "show nfpp arp-guard summary"
	Command "show nfpp arp-guard hosts"
	Command "show nfpp arp-guard scan"
	Command "show nfpp log buffer"
	Command "第二部分：软件调试--NFPP配置-DHCP-Guard"
	Command "show nfpp dhcp-guard summary"
	Command "show nfpp dhcp-guard hosts"
	Command "show nfpp arp host stat"
	Command "show net statistic"
        crt.sleep 1000
	Command "第三部分：可靠性实施检查"
	Command "第三部分：可靠性实施检查--VSU--VSL链路"
	Command "show switch virtual"
    Command "show switch virtual role"
	Command "show switch virtual config"
	Command "show switch virtual link"
	Command "show switch virtual link port"
	Command "第三部分：可靠性实施检查--VSU--双主机检测"
	Command "show switch virtual dual-active summary"
	Command "show switch virtual dual-active bfd"
	Command "第三部分：可靠性实施检查-VSU--跨机箱AP或ECMP"
	Command "show aggregatePort summary"
    Command "show aaa user all"
	Command "show lacp summary"
    Command "show access-group"
	Command "show aggregatePort load-balance"
	Command "show aggregatePort capacity"
	Command "第四部分：软硬件缺陷检查"
        Command "run-system-shell"
        Command "tipc-config -n"
        Command "ls -l /var/tmp/coredump/"
    Command "time dd if=/dev/zero of=/dev/emmcblk0p7 count=1 bs=16801792"
	Command "等待3秒"
        crt.sleep 3000
        Command "cat /tmp/proxy/defout/ssa_process"
	Command "exit"
	Command "第五部分：基本运行状态"
	Command "show power"
	Command "show fan"
	Command "show temperature"
    Command "show card voltage"
	Command "等待2秒"
        crt.sleep 2000
	Command "show cpu"
	Command "show cpu-protect mboard"			
	Command "等待3秒"
        crt.sleep 3000
	Command "show cpu"
	Command "show cpu-protect mboard"
	Command "等待3秒"
        crt.sleep 3000
	Command "show cpu"
	Command "show cpu-protect mboard"
	Command "show memory"
    ShowCpu(strResult) 'CPU防护信息收集
    	Command "等待1秒"
        crt.sleep 1000
	Command "show memory"
        Command "等待1秒"
        crt.sleep 1000
	Command "show memory"	
	Command "等待3秒"
        crt.sleep 3000
        Command "show cpu"
        Command "等待3秒"
        crt.sleep 3000	
	Command "show exception"
	Command "等待2秒"
        crt.sleep 2000
	Command "show efmp fpa"
	Command "show redundancy states"
	Command "收集扩展信息"
	Command "show ip route"
	Command "等待2秒"
        crt.sleep 2000
	Command "show ip route count"
	Command "等待2秒"
        crt.sleep 2000
	Command "show arp detail"
	Command "show arp count"
	Command "show mac-address-table count"
        Command "show ipv6 neighbors"
        Command "show ipv6 neighbors statistics"        
	Command "等待2秒"
        crt.sleep 2000
	Command "show ip dhcp snooping"	
	Command "show ip dhcp binding"
        Command "show ip dhcp server statistics"        
	Command "等待2秒"
        crt.sleep 2000
	Command "show vsd all"
	Command "show direct-vlan"	
	Command "show monitor"	
	Command "show supervlan"	
	Command "show aaa user all"	
	Command "等待2秒"
        crt.sleep 2000	
        Command "show interfaces transceiver"
		Command "show interfaces transceiver dia"
        Command "show interfaces transceiver diagnosis"
        Command "show interfaces transceiver manuinfo"
        Command "等待2秒"
        crt.sleep 2000
        Command "show erps"
        Command "show debugging"
        Command "debug dp display bc misc"
        Command "fpga read 0x1b 1"
        Command "config"
        Command "dot1x multi-mab quiet-period ?"
        Command "end"
        Command "等待2秒"
        crt.sleep 2000
        Command "show run"
        Command "more config.text"
        Command "show logging"
        Command "show interface status"
		Command "show interf counters errors"
    Command "end"
    Command "show clock"
	Command "信息收集结束"
	Command "等待1秒"
        crt.sleep 1000
        Command "terminal no length"

End Sub  

'###############################################################
'#函数名:DataHandle
'#函数功能:data加载信息收集
'#2015-07-13 邹显华
'###############################################################
public function DataHandle(strResult)
   dim a
   dim b
   dim Dev
   Dev=GetDev(strResult)
   a = Split(strResult, vbcrlf)
   Command "run-system-shell"
   Command "df -h | grep data"
   Command "exit"
   for i=0 To UBound(a)
      str = trim(ChangeStr(a(i)))
      if IsBackup(str) then
          if Dev=2 then
              b=split(str, "  ")
              Command1 "session device "&trim(b(0))&" slot "&trim(b(1))
              crt.sleep 2000
              Command "en"
              Command "run-system-shell"
              Command "df -h | grep data"
              Command "exit"
              Command "exit"
          end if
          if Dev=1 then
              b=split(str, "  ")
              Command1 "session slot "&trim(b(1))
              crt.sleep 2000
              Command "en"
              Command "run-system-shell"
              Command "df -h | grep data"
              Command "exit"
              Command "exit"
          end if
      end if
   Next
end function


'###############################################################
'#函数名:ShowCpu
'#函数功能:CPU防护相关信息收集
'#2015-07-31 邹显华
'###############################################################
public function ShowCpu(strResult)
   dim a
   dim Dev  '判断单机还是VSU
   dim b
   Dev=GetDev(strResult)
   a=split(strResult, vbcrlf)
   if Dev=1 then
      for i=0 To ubound(a)
         str = ChangeStr(a(i))
         if IsOkState(str) then
            b=split(str, "  ")
            Command "show cpu-protect slot "&trim(b(1))
         end if
      next
   end if
   if Dev=2 then
      for i=0 to ubound(a)
         str = ChangeStr(a(i))
         if IsOkState(str) then
            b=split(str, "  ")
            Command "show cpu-protect dev "&trim(b(0))&" slot "&trim(b(1))
         end if
      next
   end if
end function
 
'###############################################################
'#函数名:GetDev
'#函数功能:获取组网类型
'#2015-07-31 邹显华
'###############################################################
public function GetDev(strResult)
   GetDev=1
   a=split(strResult, vbcrlf)
   for i=0 To ubound(a)
      str = trim(ChangeStr(a(i)))
      'msgbox str
      dim b
      b=split(str, "  ")
      if ubound(b)>=5 then
         if b(0)=2 then
            GetDev=2
         end if
      end if
   next
end function

'###############################################################
'#函数名:ChangeStr
'#函数功能:将线卡显示格式进行转换
'#2015-07-13 邹显华
'###############################################################
public function ChangeStr(str)
      Dim regEx, retVal    ' 建立变量。
      Set regEx = New RegExp    ' 建立正则表达式。
      regEx.Pattern = "   "     ' 设置模式。
      regEx.IgnoreCase = False     ' 设置是否区分大小写。
      while regEx.Test(str)     ' 执行搜索测试。
         Dim regEx1, str1      ' 建立变量。
         Set regEx1 = New RegExp     ' 建立正则表达式。
         regEx1.Pattern = "   "    ' 设置模式。
         regEx1.IgnoreCase = True     ' 设置是否区分大小写。
         str = regEx.Replace(str, "  ")    ' 作替换。
      wend
      ChangeStr=str
end function


'###############################################################
'#函数名:IsOkState
'#函数功能:判断线卡状态是否为ok
'#2015-07-13 邹显华
'###############################################################
public function IsOkState(str)
   dim b
   b=split(str, "  ")
   if ubound(b)>=5 then
      if b(5)="ok" then
         IsOkState=1
      end if
   end if
end function

'###############################################################
'#函数名:IsBackup
'#函数功能:判断是否从管理板
'#2015-09-29 邹显华
'###############################################################
public function IsBackup(str)
   dim b
   b=split(str, "  ")
   if ubound(b)>=5 then
      if trim(b(5))="backup" then
         IsBackup=1
      end if
      if trim(b(5))="canditate" then
         IsBackup=1
      end if
   end if
end function
