# $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 Command2(comm)
	crt.screen.send comm & chr(13)
	crt.screen.WaitForString "ngsa-cli>"
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 ver"
	Command "show version slot"
'###############################################################
'#开始硬件部分log收集
'#2015-07-13 邹显华
'###############################################################
   currLine = crt.screen.CurrentRow    '截屏截至位置
   oldLine = currLine-30   '截屏开始位置
   strResult = Crt.Screen.Get2(oldLine,1,currLine,103) '截屏，取30行
   Command "debug ssp enable slot all"
	Command1 "sd"
	Command1 "su 0"    '主管理板
	Command1 "cons on"
	Command1 "show temp"
   VoltageHandle(strResult)   '电压
	Command1 "show c hg"
	Command1 "show exception"
	Command1 "dump all L2_entry 0 1"
	Command1 "cons off"
	Command1 "su 6"    '从管理板
	Command1 "cons on"
	Command1 "show temp"
   crt.sleep 3000
	Command1 "show c hg"
   crt.sleep 12000
	Command1 "show exception"
   crt.sleep 3000
	Command1 "dump all L2_entry 0 1"
   crt.sleep 5000
	Command1 "cons off"
   'HandleBegin(strResult)    '线卡
	Command "dexit"
	Command "no debug ssp enable slot all"
'###############################################################
'#结束硬件部分log收集，开始全局和用户模式log收集
'#2015-07-13 邹显华
'###############################################################
   Command "第二部分：软件调试"
   Command "第二部分：软件调试--端口配置--接口配置规范"
   Command "show interfaces counters errors"
   Command "show interfaces status"
   Command "等待2秒"
   crt.sleep 2000
   Command "show interfaces counters summary"
   Command "show interfaces counters rate"
   crt.sleep 1000
   Command "第二部分：软件调试--生成树功能-生成树模式"
   Command "show spanning-tree"
   Command "第二部分：软件调试--生成树功能-生成树优先级控制"
   Command "show spanning-tree summary"
   Command "show spanning-tree"
   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"
   crt.sleep 1000
   Command "第三部分：可靠性实施检查"
   Command "第三部分：可靠性实施检查--VSU--VSL链路"
   Command "show switch virtual link port"
   Command "show switch virtual link"
   Command "show switch virtual"
   Command "show switch virtual role"
   Command "show switch virtual config"
   Command "第三部分：可靠性实施检查--VSU--双主机检测"
   Command "show switch virtual config"
   Command "show switch virtual dual-active summary"
   Command "show switch virtual dual-active bfd"
   Command "第三部分：可靠性实施检查-VSU--跨机箱AP或ECMP"
   Command "show aggregatePort summary"
   Command "第三部分：可靠性实施检查--链路聚合"
   Command "show aggregatePort summary"
   Command "show lacp summary"
   Command "show aggregatePort load-balance"
   Command "第四部分：基本运行状态"
   Command "show power"
   Command "show fan"
   Command "show temperature"
   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 "show cpu-protect slot 1"
   'Command "show cpu-protect slot 2"
   'Command "show cpu-protect slot 3"
   'Command "show cpu-protect slot 4"
   'Command "show cpu-protect slot 5"
   'Command "show cpu-protect slot 6"
   'Command "show cpu-protect slot 7"
   'Command "show cpu-protect slot 8"
   'Command "show cpu-protect slot 9"
   'Command "show cpu-protect slot 10"
   'Command "show cpu-protect slot 11"
   'Command "show cpu-protect slot 12"
   'Command "show cpu-protect slot 1/1"
   'Command "show cpu-protect slot 1/2"
   'Command "show cpu-protect slot 1/3"
   'Command "show cpu-protect slot 1/4"
   'Command "show cpu-protect slot 1/5"
   'Command "show cpu-protect slot 1/6"
   'Command "show cpu-protect slot 1/7"
   'Command "show cpu-protect slot 1/8"
   'Command "show cpu-protect slot 1/9"
   'Command "show cpu-protect slot 1/10"
   'Command "show cpu-protect slot 1/11"
   'Command "show cpu-protect slot 1/12"
   'Command "show cpu-protect slot 2/1"
   'Command "show cpu-protect slot 2/2"
   'Command "show cpu-protect slot 2/3"
   'Command "show cpu-protect slot 2/4"
   'Command "show cpu-protect slot 2/5"
   'Command "show cpu-protect slot 2/6"
   'Command "show cpu-protect slot 2/7"
   'Command "show cpu-protect slot 2/8"
   'Command "show cpu-protect slot 2/9"
   'Command "show cpu-protect slot 2/10"
   'Command "show cpu-protect slot 2/11"
   'Command "show cpu-protect slot 2/12"
       Command "等待1秒"
   crt.sleep 1000
   Command "show memory"
   Command "等待1秒"
   crt.sleep 1000
   Command "show memory"   
   Command "等待3秒"
   crt.sleep 3000
   Command "show resource owner all slot M1"
   Command "show resource owner all slot M2"
   Command "show resource owner all slot 1"
   Command "show resource owner all slot 2"
   Command "show resource owner all slot 3"
   Command "show resource owner all slot 4"
   Command "show resource owner all slot 5"
   Command "show resource owner all slot 6"
   Command "show resource owner all slot 7"
   Command "show resource owner all slot 8"
   Command "show resource owner all slot 9"
   Command "show resource owner all slot 10"
   Command "show resource owner all slot 11"
   Command "show resource owner all slot 12"
   Command "show resource owner all slot 1/M1"
   Command "show resource owner all slot 1/M2"
   Command "show resource owner all slot 2/M1"
   Command "show resource owner all slot 2/M2"
   Command "show resource owner all slot 1/1"
   Command "show resource owner all slot 1/2"
   Command "show resource owner all slot 1/3"
   Command "show resource owner all slot 1/4"
   Command "show resource owner all slot 1/5"
   Command "show resource owner all slot 1/6"
   Command "show resource owner all slot 1/7"
   Command "show resource owner all slot 1/8"
   Command "show resource owner all slot 1/9"
   Command "show resource owner all slot 1/10"
   Command "show resource owner all slot 1/11"
   Command "show resource owner all slot 1/12"
   Command "show resource owner all slot 2/1"
   Command "show resource owner all slot 2/2"
   Command "show resource owner all slot 2/3"
   Command "show resource owner all slot 2/4"
   Command "show resource owner all slot 2/5"
   Command "show resource owner all slot 2/6"
   Command "show resource owner all slot 2/7"
   Command "show resource owner all slot 2/8"
   Command "show resource owner all slot 2/9"
   Command "show resource owner all slot 2/10"
   Command "show resource owner all slot 2/11"
   Command "show resource owner all slot 2/12"
   Command "等待3秒"
   crt.sleep 3000   
   Command "debug support"
   Command "show exception"
   Command "show skbuff"
   Command "show queue"
   Command "show tipc nodes"
   Command "exec debug_show_exception_all"
   Command "exec debug_show_outband_link"
   Command "pnc show error slot all"
   Command "pnc show exception"
   Command "exit"
   Command "收集扩展信息"
   Command "show ip route"
   Command "等待2秒"
   crt.sleep 2000
   Command "show ip route count"
   Command "show arp count"
   Command "show mac-address-table count"
   Command "show ipv6 neighbors statistics"   
   Command "等待2秒"
   crt.sleep 2000
   Command "show ip dhcp binding"
   Command "show ip dhcp server statistics"   
   Command "等待2秒"
   crt.sleep 2000
   Command "show interfaces transceiver"
   Command "show interfaces transceiver dia"
   Command "show interfaces transceiver diagnosis"
   Command "show erps"
   Command "show poe interfaces"
   Command "show poe interfaces status"
   Command "等待2秒"
   crt.sleep 2000
   Command "show debugging"      
   Command "等待2秒"
   crt.sleep 2000
   Command "show run"
   Command "等待1秒"
   crt.sleep 1000
   Command "more config.text"
   Command "等待1秒"
   crt.sleep 1000
   Command "show logging"
   Command "show logging | inc 电压读取原始值"
   Command "show interf counters errors"
   Command "debug ssp enable slot all"
	Command1 " sd"
   HandleEnd(strResult)  '新增带内link对应log收集
	Command "dexit"
	Command "no debug ssp enable slot all"
	Command "no debug ssp enable slot all"
	Command "信息收集结束"
	Command "等待1秒"
   crt.sleep 1000
   Command "end"
   Command "show clock"
   Command "terminal no length"

End Sub

'###############################################################
'#函数名: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 "&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 slot "&b(0)&"/"&b(1)
         end if
      next
   end if
end function

'###############################################################
'#函数名:ShowCpu
'#函数功能:CPU防护相关信息收集
'#2015-07-31 邹显华
'###############################################################
public function GetDev(strResult)
   GetDev=1
   a=split(strResult, vbcrlf)
   for i=0 To ubound(a)
      str = ChangeStr(a(i))
      dim b
      b=split(str, "   ")
      if ubound(b)>=6 then
         if b(0)=2 then
            GetDev=2
         end if
      end if
   next
end function

'###############################################################
'#函数名:VoltageHandle
'#函数功能:电压值log收集
'#2015-07-13 邹显华
'###############################################################
public function VoltageHandle(strResult)
   dim a
   dim Dev
   a = Split(strResult, vbcrlf)
   for i=0 To UBound(a)
      str = ChangeStr(a(i))
      if IsAddVoltage(str) then
         AddVoltageCmd str,Dev
      end if
   Next
end function

'###############################################################
'#函数名:AddVoltageCmd
'#函数功能:根据主管理板和-DA卡所在槽位，添加命令
'#2015-07-13 邹显华
'###############################################################
public function AddVoltageCmd(str,Dev)
   dim b
   b=split(str, "   ")
   if b(0)=Dev and b(4)="M12000-CM III" then
      if b(1)="M1" then
         Command1 "ucdtest vol_read 9"
      end if
      if b(1)="M2" then
         Command1 "ucdtest vol_read 10"
      end if
   end if

   Dim regEx    '-DA卡
   Set regEx = New RegExp
   regEx.Pattern = "-DA"
   regEx.IgnoreCase = False

   if b(0)=Dev and regEx.Test(b(4)) then
      Command1 "ucdtest vol_read " & b(1)
   end if
   
end function

'###############################################################
'#函数名:FindMaster
'#函数功能:获取主机所在的机箱号
'#2015-07-13 邹显华
'###############################################################
public function FindMaster(strResult)
   FindMaster=1
   dim a
   a = Split(strResult, vbcrlf)
   for i=0 To UBound(a)
      str = ChangeStr(a(i))
      dim b
      b=split(str, "   ")
      if ubound(b)>=6 then
         if b(6)="master" then
            FindMaster=b(0)
         end if
      end if
   Next
end function

'###############################################################
'#函数名:IsAddVoltage
'#函数功能:判断是否符合电压值收集的板卡
'#2015-07-13 邹显华
'###############################################################
public function IsAddVoltage(str)
   IsAddVoltage=0
   dim b
   b=split(str, "   ")
   if ubound(b)>=6 then
      if b(4)="M12000-CM III" then
         IsAddVoltage=1
      end if
      if b(6)="ok" then
         Dim regEx    '-DA卡
         Set regEx = New RegExp
         regEx.Pattern = "-DA"
         regEx.IgnoreCase = False
         if regEx.Test(b(4)) then
           IsAddVoltage=1
         end if
      end if
   end if
end function

'###############################################################
'#函数名:HandleBegin
'#函数功能:开始收集硬件相关Log
'#2015-07-13 邹显华
'###############################################################
public function HandleBegin(strResult)
   Dim a
   dim Chips    '芯片个数
   dim SlotCounts   'Dev1槽位数
   SlotCounts=GetSlotCounts(strResult)
   'msgbox SlotCounts
   a = Split(strResult, vbcrlf)
   for i=0 To UBound(a)
      str = ChangeStr(a(i))
      if IsOkState(str) then
         Chips=GetChips(str)
         for j=0 to Chips-1
            suID=GetSuID(str,j,SlotCounts)
	         Command1 "su " & suID
	         Command1 "cons on"
	         Command1 "show c hg"
            crt.sleep 12000
	         Command1 "show exception"
            crt.sleep 3000
	         Command1 "dump all L2_entry 0 1"
            crt.sleep 5000
	         Command1 "cons off"
         next
      end if
   Next
end function

'###############################################################
'#函数名:GetSlotCounts
'#函数功能:计算槽位数
'#2015-07-31 邹显华
'###############################################################
public function GetSlotCounts(strResult)
   Dim a
   dim b
   dim n
   n =0
   dim Chips    '芯片个数
   a = Split(strResult, vbcrlf)
   for i=0 To UBound(a)
      str = ChangeStr(a(i))
      b=split(str, "   ")
      if UBound(b)>6 then
         if b(0)="1" then
            n=n+1
         end if
      end if
   Next
   GetSlotCounts=10
   if n<=4 then
      GetSlotCounts=6
   end if
   if n<=8 then
      GetSlotCounts=10
   end if
   if n<=12 then
      GetSlotCounts=14
   end if
end function

'###############################################################
'#函数名:HandleEnd
'#函数功能:结尾处，再次收集show c hg相关的log
'#2015-07-13 邹显华
'###############################################################
public function HandleEnd(strResult)
   Dim a
   dim Chips    '芯片个数
   dim SlotCounts   'Dev1槽位数
   SlotCounts=GetSlotCounts(strResult)
   a = Split(strResult, vbcrlf)
   for i=0 To UBound(a)
      str = ChangeStr(a(i))
      if IsOkState(str) then
         Chips=GetChips(str)
         for j=0 to Chips-1
            suID=GetSuID(str,j,SlotCounts)
	         Command1 "su " & suID
	         Command1 "cons on"
	         Command1 "show c hg"
            crt.sleep 12000
	         Command1 "cons off"
         next
      end if
   Next
end function

'###############################################################
'#函数名:GetSuID
'#函数功能:计算suID
'#2015-07-13 邹显华
'###############################################################
public function GetSuID(str,Chip,SlotCounts)
   dim b
   dim suID
   dim Dev   '机箱号
   dim SlotID
   b=split(str, "   ")
   Dev=b(0)
   Slot=NewID(SlotCounts,b(1))    '槽位号
   suID = (Dev-1)*320+Slot*10+Chip
   GetSuID=suID
end function

'###############################################################
'#函数名:ChangeSlotID
'#函数功能:对板卡ID进行转换
'#2015-07-31 邹显华
'###############################################################
public function NewID(DevType,OldID)
   if DevType=6 then
      if OldID=1 then
         NewID=1
      end if
      if OldID=2 then
         NewID=4
      end if
      if OldID=3 then
         NewID=5
      end if
      if OldID=4 then
         NewID=8
      end if
   end if
   if DevType=10 then
      if OldID=1 then
         NewID=1
      end if
      if OldID=2 then
         NewID=2
      end if
      if OldID=3 then
         NewID=3
      end if
      if OldID=4 then
         NewID=4
      end if
      if OldID=5 then
         NewID=5
      end if
      if OldID=6 then
         NewID=6
      end if
      if OldID=7 then
         NewID=7
      end if
      if OldID=8 then
         NewID=8
      end if
   end if
   if DevType=14 then
      if OldID=1 then
         NewID=1
      end if
      if OldID=2 then
         NewID=2
      end if
      if OldID=3 then
         NewID=3
      end if
      if OldID=4 then
         NewID=4
      end if
      if OldID=5 then
         NewID=5
      end if
      if OldID=6 then
         NewID=6
      end if
      if OldID=7 then
         NewID=7
      end if
      if OldID=8 then
         NewID=8
      end if
      if OldID=9 then
         NewID=11
      end if
      if OldID=10 then
         NewID=12
      end if
      if OldID=11 then
         NewID=13
      end if
      if OldID=12 then
         NewID=14
      end if
   end if
end function

'###############################################################
'#函数名:GetChips
'#函数功能:计算线卡芯片个数
'#2015-07-13 邹显华
'###############################################################
public function GetChips(str)  '获取芯片个数
   dim b
   dim CardType
   b=split(str, "   ")
   CardType=b(3)
   dim i
   i=1
   GetChips=1
   Dim regEx    '48GT/4SFP
   Set regEx = New RegExp
   regEx.Pattern = "48GT/4SFP"
   regEx.IgnoreCase = False
   
   Dim regEx1    '04XFP
   Set regEx1 = New RegExp
   regEx1.Pattern = "04XFP"
   regEx1.IgnoreCase = False

   Dim regEx2    '48SFP/4GT
   Set regEx2 = New RegExp
   regEx2.Pattern = "48SFP/4GT"
   regEx2.IgnoreCase = False

   Dim regEx3    '08XFP
   Set regEx3 = New RegExp
   regEx3.Pattern = "08XFP"
   regEx3.IgnoreCase = False

   if regEx.Test(CardType) then
      GetChips=2
   end if
   
   if regEx1.Test(CardType) then
      GetChips=2
   end if

   if regEx2.Test(CardType) then
      GetChips=2
   end if

   if regEx3.Test(CardType) then
      GetChips=4
   end if

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)>=6 then
      if b(6)="ok" then
         IsOkState=1
      end if
   end if
end function



