'--------------------------------------------------------------------------------------------------------------' SOLAR WINDS REPORTING TOOL Dave Anderson 07-20-2006'--------------------------------------------------------------------------------------------------------------' This tool opens the SolarWinds Cirrus Configuration Management report file and' creates a nicely formatted email showing the device download status.' ' The results are in a file called RESULTS.HTM' This file can be copied to a server share on a webserver for public access.' The report will be emailed using the website address as the body.''' VERSIONS:' 01 = 07-20-2006 Original App' - Basic app. Reads the SolarWinds report file. Outputs data to straight text file.'' 02 = 07-20-2006 Sectioned Report' - Runs though the app two times. First time finds all failures and logs them to a table' - Second time goes through and logs the success'' 03= 07-21-2006 Searching Date' - Runs through the Cirrus report to locate only today's report information.' - Runs through the app three times. First=Error connected to device, Second=Difference in Config, Third=Successes'' 04= 07-24-2006 Emailing Functions' - Added code to copy the report to a network share. This location is a web server' - Then create an email with the body of the email being the HTML file from the web server''' Remember to tweak the following variables for your own environment:' Source Report File' Web Server file locations' Web Server Browsing Path' Email Addresses and Email server to bounce the email'###########################################################################################################'Pause at the begining. Allow time for user to exit script if they really don't want to run On Error Resume Next 'Put the number of seconds here...5 = 5 Second pause IntroPause "5"'###########################################################################################################'Create General Objects used throughout script Set objShell = CreateObject("WScript.shell") Set objFSO = WScript.CreateObject("Scripting.FileSystemObject") Dim objMessage Set objMessage=CreateObject("CDO.Message") Dim objMessConfig Set objMessConfig=CreateObject("CDO.Configuration") Dim objFields Set objFields=objMessConfig.Fields'Variables for the Text File Operations Const ForWriting = 2 Const forReading = 1 Const forAppending = 8'###########################################################################################################' MAIN SCRIPT'###########################################################################################################'Create the DataFile to Log the Results Dim strResultsFile, objResultsFile strResultsFile = "Results.htm" Set objResultsFile = objFSO.OpenTextFile (strResultsFile, ForWriting, True)'Create the HTML header info in the results file. ResultsFileHeader objResultsFile 'create a variable to hold the contents of one line of the input file Dim strInputFileLine'Create variable for the two types of reports: SUCCESS and FAILURE Dim strStatusType strStatusType = "EMPTY" 'proper values are FAILURE or SUCCESS or DIFFERENCE'Create variable to represent todays date. This is the same date format you are looking for in the Cirrus report Dim strTodaysDate strTodaysDate = (Month(Now()) & "/" & Day(Now()) & "/" & Year(Now()))'Create variable to point at the source (input) file Dim strSourceFile strSourceFile = "Job-560296.Log" Dim objSourceFile'----------------------------------------------------------------------------------------------------------------------------------------------------' LOOKING FOR FAILURES IN CONFIG REPORT'----------------------------------------------------------------------------------------------------------------------------------------------------'OpenDataFile to Read Servernames 'Opening the source file from begining Set objSourceFile = objFSO.OpenTextFile (strSourceFile, ForReading, True) Dim strFoundToday 'variable used to identify when todays results are located strFoundToday = "FALSE" 'proper values are FALSE or TRUE'Open the Cirrus Text File and read line by line the report results looking for FAILURES 'Create the HTML table in the results file FAILURES strStatusType = "FAILURE" CreateTableHTML objResultsFile, strStatusType wscript.echo "Checking for FAILURES" Dim x1, intMaxLoop 'used to prevent ininite looping x1 = 1 intMaxLoop = 200000 While Not ((objSourceFile.AtEndOfStream) or (x1 > intMaxLoop)) 'exit the loop if it runs too many times strInputFileLine = trim(objSourceFile.ReadLine) 'Check for today's date. If the line contains the date, the value = 1. Then start parsing the If (InStr(LCase(strInputFileLine), LCase(strTodaysDate)) > 0) Then wscript.echo "line no: " & x1 wscript.echo "strInputFileLine: " & strInputFileLIne strFoundToday = "TRUE" End If 'wscript.echo "Loop # " & x1 & " strFoundToday: " & strFoundToday If (strFoundToday = "TRUE") Then AnalyzeData strInputFileLine, objResultsFile, strStatusType End If x1 = (x1+1) 'increment counter to make sure you are not stuck in a never ending loop Wend'Finish HTML table that has the results data inside CloseTableHTML objResultsFile 'Close Source File because we already looped through it objSourceFile.Close'---------------------------------------------------------------------------------------------------------------------------------------------------- ' LOOKING FOR DIFFERENCES IN CONFIG REPORT'----------------------------------------------------------------------------------------------------------------------------------------------------'OpenDataFile to Read Servernames 'Opening the source file from begining (again) Set objSourceFile = objFSO.OpenTextFile (strSourceFile, ForReading, True) strFoundToday = "FALSE" 'proper values are FALSE or TRUE'Open the Cirrus Text File and read line by line the report results looking for FAILURES 'Create the HTML table in the results file FAILURES strStatusType = "DIFFERENCE" CreateTableHTML objResultsFile, strStatusType wscript.echo "Checking for DIFFERENCES" x1 = 1 intMaxLoop = 200000 While Not ((objSourceFile.AtEndOfStream) or (x1 > intMaxLoop)) 'exit the loop if it runs too many times strInputFileLine = trim(objSourceFile.ReadLine) 'Check for today's date. If the line contains the date, the value = 1. Then start parsing the If (InStr(LCase(strInputFileLine), LCase(strTodaysDate)) > 0) Then wscript.echo "line no: " & x1 wscript.echo "strInputFileLine: " & strInputFileLIne strFoundToday = "TRUE" End If 'wscript.echo "Loop # " & x1 & " strFoundToday: " & strFoundToday If (strFoundToday = "TRUE") Then AnalyzeData strInputFileLine, objResultsFile, strStatusType End If x1 = (x1+1) 'increment counter to make sure you are not stuck in a never ending loop Wend'Finish HTML table that has the results data inside CloseTableHTML objResultsFile 'Close Source File because we already looped through it objSourceFile.Close'----------------------------------------------------------------------------------------------------------------------------------------------------' LOOKING FOR SUCCESSES IN CONFIG REPORT'---------------------------------------------------------------------------------------------------------------------------------------------------- 'OpenDataFile to Read Servernames 'Opening the source file from begining (again) Set objSourceFile = objFSO.OpenTextFile (strSourceFile, ForReading, True) strFoundToday = "FALSE" 'proper values are FALSE or TRUE'Open the Cirrus Text File and read line by line the report results looking for FAILURES 'Create the HTML table in the results file FAILURES strStatusType = "SUCCESS" CreateTableHTML objResultsFile, strStatusType wscript.echo "Checking for SUCCESSES" x1 = 1 intMaxLoop = 200000 While Not ((objSourceFile.AtEndOfStream) or (x1 > intMaxLoop)) 'exit the loop if it runs too many times strInputFileLine = trim(objSourceFile.ReadLine) 'Check for today's date. If the line contains the date, the value = 1. Then start parsing the If (InStr(LCase(strInputFileLine), LCase(strTodaysDate)) > 0) Then wscript.echo "line no: " & x1 wscript.echo "strInputFileLine: " & strInputFileLIne strFoundToday = "TRUE" End If 'wscript.echo "Loop # " & x1 & " strFoundToday: " & strFoundToday If (strFoundToday = "TRUE") Then AnalyzeData strInputFileLine, objResultsFile, strStatusType End If x1 = (x1+1) 'increment counter to make sure you are not stuck in a never ending loop Wend'Finish HTML table that has the results data inside CloseTableHTML objResultsFile 'Close Source File because we already looped through it objSourceFile.Close'---------------------------------------------------------------------------------------------------------------------------------------------------- 'Finish HTML Formatting on bottom of the page ResultsFileFooter objResultsFile, intErrorCount'---------------------------------------------------------------------------------------------------------------------------------------------------- 'Copy the Results File to the WebServer 'To browse the page use the following link: www.webserver.com/.../cirrusreport.htm Dim objFile, strDest wscript.echo "Copying results to the Web Server" strDest="\\web-server\SolarWinds\CirrusReport.htm" Set objFile=objFSO.GetFile(strResultsFile) objFile.Copy(strDest)'---------------------------------------------------------------------------------------------------------------------------------------------------- 'Email Results of Scan 'MailResults wscript.echo "[EMAIL SECTION]" 'Location of Results File to be included with the email 'strFileName = "c:\bin\drivespace\Results.htm" 'Set the basic Message Properties With objMessage .Subject = "SolarWinds Configuration Report" .From = """SolarWinds Reporting"" <johnshepard@atlantis.com>" .To = "<johnshepard@atlantis.com>" .CreateMHTMLBody "">www.atlantis.com/.../cirrusreport.htm" .AddAttachement objResultsFile .AddAttachement objErrorFile .Configuration.Fields.Item ("">schemas.microsoft.com/.../sendusing") = 2 .Configuration.Fields.Item ("">schemas.microsoft.com/.../smtpserver") = "mail.atlantis.com" .Configuration.Fields.Item ("">schemas.microsoft.com/.../smtpserverport") = 25 .Configuration.Fields.Update End With objMessage.Send If err.number <> 0 Then Wscript.Echo "Error sending the email" wscript.echo "Err#: " & Err.Number & vbTab & Err.Description End If'---------------------------------------------------------------------------------------------------------------------------------------------------- 'Close DataFile objResultsFile.Close objErrorFile.Close'Release Object Variables objShell = "" objFSO = "" objMessage = "" objMessConfig = "" objFields = "" '###########################################################################################################' END MAIN'###########################################################################################################'###########################################################################################################Sub IdentifyDeviceName(strInputFileLine, objResultsFile)'The first section of each line of text is the sytem name followed by a colon 'This sub identifies the system name from the entire line of text'You must drop the colon from the name so subtract one intFirstColonPosition = ((InStr(LCase(strInputFileLine), LCase(":"))) - 1) wscript.echo infFirstColonPosition strDeviceName = Trim(Mid(strInputFileLine, 1, intFirstColonPosition)) wscript.echo "DEVICE NAME: " & strDeviceNameEnd Sub'###########################################################################################################Sub AnalyzeData(strInputFileLine, objResultsFile, strStatusType)' This sub will check the text from the text file to see if the line is reporting a succesfull download or failure download Dim strRType strRType = "EMPTY" If strStatusType = "FAILURE" then 'First section of IF/THEN is looking for FAILURES 'Checking the string for FAILURES, if found log them otherwise it assumes success and skips the entry If (InStr(LCase(strInputFileLine), LCase("error:")) > 0) Then wscript.echo "ERROR: " & strInputFileLine 'The first section of each line of text is the sytem name followed by a colon 'This section identifies the system name from the entire line of text 'You must drop the colon from the name so subtract one intFirstColonPosition = (InStr(LCase(strInputFileLine), LCase(":"))) intStringLength = Len(strInputFileLine) wscript.echo infFirstColonPosition strDeviceName = Trim(Mid(strInputFileLine, 1, (intFirstColonPosition-1))) wscript.echo "DEVICE NAME: " & strDeviceName 'Now you can drop the first portion of the string as it is the device name which was found above. 'This section drops the begining of the text up to the first semicolon. wscript.echo Right(strInputFileLIne, (intstringLength - intFirstColonPosition)) strConnectionInfo = Right(strInputFileLIne, (intstringLength - intFirstColonPosition)) strRType = "FAIL" WriteResultsData strConnectionInfo, objResultsFile, strRType, strDeviceName End If End If wscript.echo "strStatusType: " & strStatusType If strStatusType = "DIFFERENCE" then 'second section of IF/THEN is looking for DIFFERENCES 'Checking the string for SUCCESS, if found log them otherwise it assumes failure and skips the entry If (InStr(LCase(strInputFileLine), LCase("differs from last")) > 0) Then 'wscript.echo "Success: " & strInputFileLine 'The first section of each line of text is the sytem name followed by a colon 'This section identifies the system name from the entire line of text 'You must drop the colon from the name so subtract one wscript.echo "DIFF FOUND!!!!!!!!!!" wscript.echo strInputFileLine intFirstColonPosition = (InStr(LCase(strInputFileLine), "has changed")) intStringLength = Len(strInputFileLine) wscript.echo intFirstColonPosition strDeviceName = Trim(Mid(strInputFileLine, 11, (intFirstColonPosition-12))) wscript.echo "DEVICE NAME: " & strDeviceName 'Now you can drop the first portion of the string as it is the device name which was found above. 'This section drops the begining of the text up to the first semicolon. wscript.echo Right(strInputFileLIne, ((intstringLength - intFirstColonPosition)+1)) strConnectionInfo = Right(strInputFileLIne, ((intstringLength - intFirstColonPosition)+1)) strRType = "DIFF" WriteResultsData strConnectionInfo, objResultsFile, strRType, strDeviceName End If End If If strStatusType = "SUCCESS" then 'thrid section of IF/THEN is looking for SUCCESS 'Checking the string for SUCCESS, if found log them otherwise it assumes failure and skips the entry If (InStr(LCase(strInputFileLine), LCase("downloaded running config")) > 0) Then 'wscript.echo "Success: " & strInputFileLine 'The first section of each line of text is the sytem name followed by a colon 'This section identifies the system name from the entire line of text 'You must drop the colon from the name so subtract one intFirstColonPosition = (InStr(LCase(strInputFileLine), LCase(":"))) intStringLength = Len(strInputFileLine) wscript.echo intFirstColonPosition strDeviceName = Trim(Mid(strInputFileLine, 1, (intFirstColonPosition-1))) wscript.echo "DEVICE NAME: " & strDeviceName 'Now you can drop the first portion of the string as it is the device name which was found above. 'This section drops the begining of the text up to the first semicolon. wscript.echo Right(strInputFileLIne, (intstringLength - intFirstColonPosition)) strConnectionInfo = Right(strInputFileLIne, (intstringLength - intFirstColonPosition)) strRType = "SUCCESS" WriteResultsData strConnectionInfo, objResultsFile, strRType, strDeviceName End If End IfEnd Sub'###########################################################################################################Sub WriteResultsData(strConnectionInfo, objResultsFile, strRType, strDeviceName)' This sub writes data into an HTML table for each device. If the device was a failure, then it writes the data into table' field with yellow background. if (strRType = "SUCCESS") then objResultsFile.WriteLine "<tr bgcolor=""#EAEAEA"">" objResultsFile.WriteLine "<td>" & UCase(strDeviceName) & "</td>" objResultsFile.WriteLine "<td>" & strConnectionInfo & "</td>" objResultsFile.WriteLine "</tr>" end if if (strRType = "FAIL") then objResultsFile.WriteLine "<tr bgcolor=""#FFFFCC"">" objResultsFile.WriteLine "<td>" & UCase(strDeviceName) & "</td>" If (Instr(LCase(strConnectionInfo), "bad password") > 0) Then objResultsFile.WriteLine "<td><b>" & strConnectionInfo & "</b></td>" Else objResultsFile.WriteLine "<td>" & strConnectionInfo & "</td>" End If objResultsFile.WriteLine "</td>" objResultsFile.WriteLine "</tr>" end if if (strRType = "DIFF") then objResultsFile.WriteLine "<tr bgcolor=""#FE9A9C"">" objResultsFile.WriteLine "<td>" & UCase(strDeviceName) & "</td>" objResultsFile.WriteLine "<td>" & strConnectionInfo & "</td>" objResultsFile.WriteLine "</td>" objResultsFile.WriteLine "</tr>" end ifEnd Sub'###########################################################################################################Sub ResultsFileHeader(objResultsFile)'Add formatting to HTML Results file objResultsFile.WriteLine "<html>" objResultsFile.WriteLine "<body>" objResultsFile.WriteLine "<table border=""0"" cellpadding=""0"" cellspacing=""0"" style=""border-collapse: collapse"" bordercolor=""#111111"" width=""600""><tr><td width=""100%"">" objResultsFile.WriteLine "<font face=""verdana"" size=""4"">" objResultsFile.WriteLine "ATLANTIS OUTPOST CORP.<br>" objResultsFile.WriteLine "CIRRUS DEVICE CONFIG MGMT REPORT<br>" objResultsFile.WriteLine "</font>" objResultsFile.WriteLine "<font size=""3"">" objResultsFile.WriteLine Month(Now()) & "-" & Day(Now()) & "-" & Year(Now()) & "<br>" objResultsFile.WriteLine Time() & "<br>" objResultsFile.WriteLIne "running from server: SOLARWINDS SERVER" objResultsFile.WriteLIne "</font>" objResultsFile.WriteLine "<hr>"End SubSub ResultsFileFooter(objResultsFile, intErrorCount)'Finish HTML Formatting on bottom of the page objResultsFile.WriteLine "</td></tr></table>" objResultsFile.WriteLine "</body>" objResultsFile.WriteLine "</html>"End Sub'###########################################################################################################Sub CreateTableHTML(objResultsFile, strStatusType) objResultsFile.WriteLine "<br>" objResultsFile.WriteLine "<font face=""Verdana"" size=""2"">" objResultsFile.WriteLine "<table border=""1"" cellpadding=""0"" cellspacing=""0"" style=""border-collapse: collapse"" width=""600"">" objResultsFile.WriteLine "<tr bgcolor=""#7B7BA8""><td>" objResultsFile.WriteLine "<b>" & strStatusType & "</b>" objResultsFile.WriteLine "</td><td></td></tr>"End SubSub CloseTableHTML(objResultsFile) objResultsFile.WriteLine "</table>" objResultsFile.WriteLine "</font>" objResultsFile.WriteLine "<br>"End Sub'###########################################################################################################Sub IntroPause(intWaitTimeSec) wscript.echo "SOLARWINDS CIRRUS REPORTING SCRIPT" wscript.echo "This script will query the Cirrus report and output the data in a nicer format." wscript.echo "" wscript.echo "Pausing for "& intWaitTimeSec & " seconds. CTRL+C If you Do Not wish To run now." wscript.sleep((intWaitTimeSec*1000)) wscript.echo "" wscript.echo ""End Sub'###########################################################################################################