' ------------------------------------------------------------ ' IMPORT agents in Ciscoworks DCRv3 format into Unbrowse SNMP ' ' Usage: impagent ' ------------------------------------------------------------Const ForReading=1 Set Stdout = WScript.Stdout Set FSO = CreateObject("Scripting.FileSystemObject") ' ----------------------- ' Check usage & arguments ' ----------------------- if WScript.Arguments.Count 1 then Stdout.WriteLine "Usage: impagent " WScript.Quit end if DCRFileName = WScript.Arguments.Item(0) ' ---------------------------------- ' Open input file and read all lines ' ---------------------------------- Set InputFile = FSO.OpenTextFile( DCRFileName, ForReading) InputFileContents = InputFile.ReadAll If Not Err.Number = 0 Then If Err.Number = 424 Then StdOut.WriteLine "Input DCR File not found" & DCRFileName & vbCRLF StdOut.WriteLine "Error : " & Err.Description WScript.Quit End If InputFileLines = Split(InputFileContents,vbCRLF) ' ---------------------------------- ' Create the Unbrowse Agent Manager ' ---------------------------------- Set AgentMgr = CreateObject("UnbrowseSNMP.AgentManager") AgentMgr.Init() validLinesBegin = False dcrCheck = False For Each sLine In InputFileLines Trim(sLine) ' Skip comments and zero length If Len(sLine) > 0 AND Mid(sLine,1,1) ";" Then If validLinesBegin Then ProcessLine (sLine) Else If dcrCheck Then If InStr(sLine,"management_ip_address") Then validLinesBegin = True End If Else If InStr(sLine,"Type=DCRCSV") Then dcrCheck = True End If End If End If End If Next If Not dcrCheck Then StdOut.WriteLine "The input file is not in CiscoWorks DCRv3 format : filename " & DCRFileName & vbCRLF End If ' ------------------------------------------------------------------------------ ' Process a single line ' Create an agent and set attributes as specified in the input line (CSV format) ' ------------------------------------------------------------------------------ Sub ProcessLine (Line) LineFields = Split(Line,",") If UBound(LineFields) > 3 Then ipaddr = LineFields(0) hostname = LineFields(1) rcomm = LineFields(8) wcomm = LineFields(9) Set OneAgent = AgentMgr.NewAgent OneAgent.Name = hostname OneAgent.IPAddress = ipaddr OneAgent.ReadComm = rcomm OneAgent.WriteComm = wcomm StdOut.WriteLine "Added agent " & hostname & " to Unbrowse repository" & vbCRLF End If End Sub