下面就我的工作性质,跟我同事一块制作的一个脚本程序——维护着N台路由器设备,每天需要对这些设备进行例行巡检。下面是程序的所有代码,希望对各位有所帮助
**********************************************************************************************************
**********************************************************************************************************
#$language = "VBScript"
#$interface = "1.0"
'说明:
'本代码可在CRT工具中实现Cosico,华为,爱立信路由器交换机数据的自动配置或作为设备巡检之用;
Set screen = crt.Screen            '创建屏幕对象
'定义全局变量:
'Device变量为操作设备对象数组,作为存储设备名用;
'CiscoAggreOfCommands变量为思科设备命令集合数组,作为存储思科设备命令用;
'NE40EAggreOfCommands变量为华为NE40E设备命令集数组,作为存储华为NE设备命令用;
'SE800AggreOfCommands变量为爱立信SE800设备命令集数组,作为存储爱立信SE800设备命令用;
'ArrreOfRiskCommands变量为各厂家设备存在风险性操作命令的数组,作为存储过滤风险操作命令之用;
'DeviceNumth变量为Device数组序号;
'CommandNumth变量为各厂家命令数组的序号;
'ResultOfType变量为判断设备类型标识符;
'TypeOfCommand变量作为存储当前命令类型用;
Dim Device,CiscoAggreOfCommands,NE40EAggreOfCommands,SE800AggreOfCommands,ArrreOfRiskCommands
Dim DeviceNumth , CommandNumth ,ResultOfType
Dim TypeOfCommand
'爱立信设备集合
'Device = Array("CE35-ERICSE800","CE36-ERICSE800","CE37-ERICSE800","CE38-ERICSE800")
'华为设备集合
Device = Array( "CE07-HWNE40E","CE08-HWNE40E",_
                    "CE09-HWNE40E","CE10-HWNE40E",_
                    "CE11-HWNE40E","CE12-HWNE40E",_
                    "CE21-HWNE40E","CE22-HWNE40E",_
                    "CE23-HWNE40E","CE24-HWNE40E",_
                    "CE25-HWNE40E","CE26-HWNE40E",_
                    "CE29-HWNE40E","CE30-HWNE40E",_
                    "CE33-HWNE40E","CE34-HWNE40E",_
                    "CE45-HWNE40E","CE46-HWNE40E",_
                    "CE47-HWNE40E","CE48-HWNE40E",_
                    "CE49-HWNE40E","CE50-HWNE40E")
'思科设备命令集合
    CiscoAggreOfCommands = Array("show cdp",_
                                                         "show conf",_
                                                         "show hard",_
                                                         "show interface",_
                                                         "show ip route",_
                                                         "show conf")
'华为NE40E设备命令集合
'健康检查
'告警检查
'日志检查
'单板运行状态检查
'CPU占用率检查
'内存占用率检查
'接口和链路状态以及流量检查
'NE40E接口状态检查
'OSPF邻居状态检查
'路由信息检查
  NE40EAggreOfCommands = Array("display health",_
                               "display trapbuffer",_
                               "display logbuffer",_
                               "display device",_
                               "display cpu-usage",_
                               "display memory-usage",_
                               "display interface",_
                               "dis ospf peer",_
                               "display ip routing-table") 
'爱立信SE800设备命令集合
'单板注册信息
'办卡加电自检
'单板运行状态检查
'检查背板运行状态   
'检查主控板冗余性   
'存储设备利用率
'CPU利用率
'内存利用率检查
'端口运行状态检查
'端口数据收发状态检查
'电源使用情况检查
'检查OSPF状态                               
  SE800AggreOfCommands = Array("show chassis",_
                                                           "show diag on-demand detail",_
                                                           "show hardware",_
                                                           "show backplane-status",_
                                                           "show redundancy",_
                                                           "show disk",_
                                                           "show process",_
                                                           "show memory",_
                                                           "show port detail",_
                                                           "show port counters detail",_
                                                           "show chassis power",_
                                                           "context ChinaMobile_NGN_SG",_
                                                           "show ospf neighbor",_
                                                           "context ChinaMobile_NGN_Media",_
                                                           "show ospf neighbor")
'风险命令过滤集合 
  ArreOfRiskCommands = Array("reb","rel")
'CE汇聚网管平台登陆子函数
Function LandIPNET
      screen.Send ""&chr(13)
      screen.WaitForString "ogin:"
      screen.Send "XXXXXXXXXX" & chr(13)
      screen.WaitForString "Password:"
      screen.Send "XXXXXXXXXX"& chr(13)
End Function
'各厂家设备选择登陆子函数
Function LandDevice
        screen.Send ""&chr(13)
        screen.WaitForString "Console>>"
        screen.Send "open " & Device(DeviceNumth)
        ResultOfType = screen.WaitForStrings("Cisco","NE40E","SE800",4)
        If ResultOfType = 1 Then
            TypeOfCommand = CiscoAggreOfCommands
            'CommandNumth=0
        ElseIf ResultOfType = 2 Then
            TypeOfCommand = NE40EAggreOfCommands
            'CommandNumth=0
        ElseIf ResultOfType = 3 Then
            TypeOfCommand = SE800AggreOfCommands
            'CommandNumth=0
        Else
            MsgBox "Error Type Of Device"
            Do
            Loop
        End If
        screen.Send ""&chr(13)
        screen.WaitForStrings "Username:","ogin:"
        screen.send "XXXXXXXXXX"& chr(13)
        screen.WaitForString "Password:"
        screen.Send "XXXXXXXXXX"& chr(13)   
        Do
        Loop Until (screen.WaitForStrings("NE40E&gt;","SE800#",5)<>False)
End Function
'退出设备子函数
Function ExitDevice
        If ResultOfType = 1 Then
        ElseIf ResultOfType = 2 Then
            screen.Send "                          "&"quit" & chr(13)
          Do
              screen.Send ""&chr(13)
          Loop Until (screen.WaitForString("Console&gt;&gt;",1)<>False)
        ElseIf ResultOfType = 3 Then
            screen.Send "                          "&"exit" & chr(13)
            Do
              screen.Send ""&chr(13)
          Loop Until (screen.WaitForString("Console&gt;&gt;",1)<>False)
        Else
        End If
End Function
Function ShowAll
   Do while (screen.WaitForStrings("More","more",3)<>False)
      crt.Screen.Send " "
   Loop 
End Function
'风险命令过滤子函数
Function RiskCommands
      Dim result
      result = screen.WaitForStrings(ArreOfRiskCommands,1)
      If result <> False Then
          MsgBox "The command  you are importing exists risk!"
            Do
            Loop
        End If
End Function
Sub Main
    crt.Screen.Synchronous = True
    LandIPNET
    For DeviceNumth=LBound(Device) To UBound(Device)
        LandDevice
        CommandNumth=0
      For CommandNumth = LBound(TypeOfCommand) To UBound(TypeOfCommand)
          screen.Send "                                    "&TypeOfCommand(CommandNumth)
            RiskCommands
            screen.Send "" & chr(13)
        ShowAll
        If screen.WaitForString("More",1)<>False Then ShowAll
        crt.Sleep 4000
            screen.Send "" & chr(13)
      Next
      ExitDevice
  Next
    crt.Screen.Synchronous = False
End Sub