Jump to content

How to create a specific report, using AutoIt


Recommended Posts

Hello to all of you !

I've just discover AutoIt (great product !) and I think it could respond to my need, but I'm not sure ...

Here is my goal :

. I have a log directory

. Inside this directory, there is many subdirectories

. Inside all these subdirectories, there is thousands of Synch*.log files

. Inside of some of these log files, there is some errors.

Then :

. I would like to scan all of these log files

. Search for those which contain error messages

. catch error code and error message

. produce at the end a report file, which will contain the following :

-----------------------------------------------------------------------------------------------

Error n° XXX : <description of the error> : <number ot times this error occurs"

<list of files which contain this error>

<list of files which contain this error>

<list of files which contain this error>

<list of files which contain this error>

-----------------------------------------------------------------------------------------------

Error n° YYY : <description of the error> : <number ot times this error occurs"

<list of files which contain this error>

<list of files which contain this error>

<list of files which contain this error>

<list of files which contain this error>

-----------------------------------------------------------------------------------------------

As I can see, there is many ways to do it

But can you tell me please what is the simplest way to implement this need ?

Many thanks in advance !

Link to comment
Share on other sites

Welcome to the forums :P

You should start by being able to find and display the files. Do a forum search for a recursive file search. Then _ArrayDisplay the results. See what you get? Do you think you can think of a way to use that data? I'll give a hint. A For...Next loop. Then what you want to do is look at the FileOpen, FileRead, FileWrite, and _FileReadToArray and _ArraySearch. That should give you a hefty list to get you started ;) Good luck with this :)

Brett

Link to comment
Share on other sites

Welcome to the forums :P

You should start by being able to find and display the files. Do a forum search for a recursive file search. Then _ArrayDisplay the results. See what you get? Do you think you can think of a way to use that data? I'll give a hint. A For...Next loop. Then what you want to do is look at the FileOpen, FileRead, FileWrite, and _FileReadToArray and _ArraySearch. That should give you a hefty list to get you started ;) Good luck with this :)

Brett

ok thanks for infos !!!

When I will finish, I will publish it, ok ?

Link to comment
Share on other sites

Link to comment
Share on other sites

Thanks for help, all of you !

So ... Here is my script :

CODE
;

; Script de suivi des synchros Tapas

#include <Date.au3>

#include <Array.au3>

#include <INet.au3>

Dim $FileCount = 0

Dim $Currentfile = 0

Dim $NbErrors = 0

Dim $NbSynchKO = 0

Dim $UserCode = ""

Dim $ErrorsCodeArray

Dim $ErrorsOccursArray

Dim $ErrorsLabelArray

Dim $ErrorCode = ""

Dim $SynchroUserCode

Dim $SynchroLogFile

Dim $SynchroStart

Dim $SynchroEnd

Dim $SynchroErrorCode

Dim $SynchroVolume

Dim $Start

Dim $End

Dim $Volume

Dim $Bu

If FileExists(@ScriptDir & "\SynchFollowUp.txt") Then

FileDelete(@ScriptDir & "\SynchFollowUp.txt")

Endif

;--------------------------------------------------------------------------------

; BU : CIGARET FRANCE

;--------------------------------------------------------------------------------

If FileExists("c:\windows\2PRD_Synch_followup.bat") Then

FileDelete("c:\windows\2PRD_Synch_followup.bat")

Endif

FileWriteLine ( "c:\windows\2PRD_Synch_followup.bat", "@echo off")

FileWriteLine ( "c:\windows\2PRD_Synch_followup.bat", "net use Q: /DELETE")

FileWriteLine ( "c:\windows\2PRD_Synch_followup.bat", "net use Q: \\sv841\S$ adminsv841 /USER:sv841\administrator")

$Retour = RunWait ( @Comspec & ' /C c:\windows\2PRD_Synch_followup.bat',"", @SW_MINIMIZE)

If FileExists("c:\windows\2PRD_Synch_followup.bat") Then

FileDelete("c:\windows\2PRD_Synch_followup.bat")

Endif

;ScanFolder("Q:\apps\siebel78\tapp\siebsrvr\log", "CIGARET FRANCE")

;ScanFolder("D:\Projects\Tapas\Synchro followup\log", "CIGARET FRANCE")

ScanFolder("Q:\apps\siebel78\tapp\siebsrvr\log", "CIGARET FRANCE")

;--------------------------------------------------------------------------------

;--------------------------------------------------------------------------------

; BU : CIGARET SPAIN

;--------------------------------------------------------------------------------

If FileExists("c:\windows\2PRD_Synch_followup.bat") Then

FileDelete("c:\windows\2PRD_Synch_followup.bat")

Endif

FileWriteLine ( "c:\windows\2PRD_Synch_followup.bat", "@echo off")

FileWriteLine ( "c:\windows\2PRD_Synch_followup.bat", "net use Q: /DELETE")

FileWriteLine ( "c:\windows\2PRD_Synch_followup.bat", "net use Q: \\sv840\R$ adminsv840 /USER:sv840\administrator")

$Retour = RunWait ( @Comspec & ' /C c:\windows\2PRD_Synch_followup.bat',"", @SW_MINIMIZE)

If FileExists("c:\windows\2PRD_Synch_followup.bat") Then

FileDelete("c:\windows\2PRD_Synch_followup.bat")

Endif

ScanFolder("Q:\apps\siebel78\tapp\siebsrvr\log", "CIGARET SPAIN")

;--------------------------------------------------------------------------------

;--------------------------------------------------------------------------------

; BU : CIGAR SPAIN

;--------------------------------------------------------------------------------

If FileExists("c:\windows\2PRD_Synch_followup.bat") Then

FileDelete("c:\windows\2PRD_Synch_followup.bat")

Endif

FileWriteLine ( "c:\windows\2PRD_Synch_followup.bat", "@echo off")

FileWriteLine ( "c:\windows\2PRD_Synch_followup.bat", "net use Q: /DELETE")

FileWriteLine ( "c:\windows\2PRD_Synch_followup.bat", "net use Q: \\sv841\T$ adminsv841 /USER:sv841\administrator")

$Retour = RunWait ( @Comspec & ' /C c:\windows\2PRD_Synch_followup.bat',"", @SW_MINIMIZE)

If FileExists("c:\windows\2PRD_Synch_followup.bat") Then

FileDelete("c:\windows\2PRD_Synch_followup.bat")

Endif

ScanFolder("Q:\apps\siebel78\tapp\siebsrvr\log", "CIGAR SPAIN")

;--------------------------------------------------------------------------------

;-------------------------------------------------------------------------------

; Functions

;-------------------------------------------------------------------------------

Func ScanFolder($SourceFolder, $Bu)

Local $Search

Local $File

Local $FileAttributes

Local $FullFilePath

$ErrorsCodeArray = _ArrayCreate("Error Code")

$ErrorsOccursArray = _ArrayCreate("Occurs")

$ErrorsLabelArray = _ArrayCreate("Error Label")

$SynchroUserCode = _ArrayCreate("User Code")

$SynchroLogFile = _ArrayCreate("Log File ")

$SynchroStart = _ArrayCreate("Start ")

$SynchroEnd = _ArrayCreate("End ")

$SynchroErrorCode = _ArrayCreate("Error Code")

$SynchroVolume = _ArrayCreate("Volume")

$NbErrors = 0

$NbSynchKO = 0

$Currentfile = 0

ProgressOn("Progress Meter", "BU : " & $Bu & " in progress ...", "Count how many log files to handle")

;count how many files to handle

CountFiles($SourceFolder)

$Search = FileFindFirstFile($SourceFolder & "\Sync*.log")

While 1

If $Search = -1 Then

ExitLoop

EndIf

$File = FileFindNextFile($Search)

If @error Then ExitLoop

$FullFilePath = $SourceFolder & "\" & $File

$FileAttributes = FileGetAttrib($FullFilePath)

If StringInStr($FileAttributes,"D") Then

ScanFolder($FullFilePath)

Else

$UserCode = ""

AnalyzeFile($FullFilePath, $Bu)

If $NbErrors > 0 then

$NbSynchKO += 1

Endif

EndIf

$Currentfile +=1

WEnd

;-------------------------------------------------------------------------------

; Generate Report

;-------------------------------------------------------------------------------

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt"," ")

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt","************************************")

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt","* Synchronization follow-up")

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt","* Date and time : " & _Now() )

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt","************************************")

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt"," ")

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt",";-------------------------------------------------------------------------------")

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt","; Global Statistics for BU : " & $Bu)

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt",";-------------------------------------------------------------------------------")

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt","Number of synchronizations : " & $FileCount)

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt","Number of synchronizations with errors : " & $NbSynchKO)

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt"," ")

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt",";-------------------------------------------------------------------------------")

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt","; Global Errors follow-up for BU : " & $Bu)

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt",";-------------------------------------------------------------------------------")

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt"," ")

For $element = 0 to (UBound($ErrorsCodeArray) - 1)

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt", StringLeft($ErrorsCodeArray[$element] & " ",10) & " - " & StringLeft($ErrorsOccursArray[$element] & " ",8) & " - " & $ErrorsLabelArray[$element])

Next

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt"," ")

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt",";-------------------------------------------------------------------------------")

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt","; Global Users errors follow-up for BU : " & $Bu)

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt",";-------------------------------------------------------------------------------")

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt"," ")

For $element = 0 to (UBound($SynchroUserCode) - 1)

FileWriteLine(@ScriptDir & "\SynchFollowUp.txt", StringLeft($SynchroUserCode[$element] & " ",10) & " | " & StringRight($SynchroLogFile[$element],18) & " | " & $SynchroStart[$element] & " | " & $SynchroEnd[$element] & " | " & StringLeft($SynchroErrorCode[$element] & " ",10) & " | " & $SynchroVolume[$element])

Next

ProgressOff()

EndFunc

Func AnalyzeFile($FileName, $Bu)

$File = FileOpen($FileName, 0)

$NbErrors = 0

$SynchInError = 0

$Volume = ""

ProgressSet( (($Currentfile *100) / $FileCount), StringRight($FileName, 18) & " analyze in progress ...")

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

; Read in lines of text until the EOF is reached

$Start = ""

$End = ""

While 1

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

If $Start = "" Then

$Start = StringMid ($line, 6, 19)

$End = StringMid ($line, 26, 19)

Endif

If $SynchInError = 1 Then

If StringInStr($line, "Node ", 0) <> 0 Then

$UserCode = StringMid ($line,StringInStr($line, "Node ", 0)+ 5, 8)

$Volume = StringMid ($line,StringInStr($line, "Node ", 0)+ 14, 70)

Endif

Endif

If StringInStr($line, "err=", 0) <> 0 Then

$NbErrors += 1

$SynchInError = 1

$ErrorCode = StringMid ($line,StringInStr($line, "err=", 0)+ 4, 7)

$ErrorLabel = StringMid ($line,StringInStr($line, "err=", 0)+ 12, 100)

$Pos = _ArraySearch ($ErrorsCodeArray, $ErrorCode, 0, 0, 0, True)

If $Pos = -1 Then

_ArrayAdd($ErrorsCodeArray,$ErrorCode)

_ArrayAdd($ErrorsOccursArray,1)

_ArrayAdd($ErrorsLabelArray,$ErrorLabel)

Else

$ErrorsOccursArray[$Pos] += 1

EndIf

_ArrayAdd($SynchroUserCode,"")

_ArrayAdd($SynchroLogFile,$FileName)

_ArrayAdd($SynchroStart,$Start)

_ArrayAdd($SynchroEnd,$End)

_ArrayAdd($SynchroErrorCode,$ErrorCode)

_ArrayAdd($SynchroVolume,$Volume)

EndIf

Wend

For $element = 0 to (UBound($SynchroUserCode) - 1)

If $SynchroUserCode[$element] = "" Then

$SynchroUserCode[$element] = $UserCode

$SynchroVolume[$element] = $Volume

Endif

Next

SplashOff()

FileClose($file)

EndFunc

Func CountFiles($SourceFolder)

$FileCount = 0

$Search = FileFindFirstFile($SourceFolder & "\Sync*.log")

While 1

If $Search = -1 Then

ExitLoop

EndIf

$File = FileFindNextFile($Search)

If @error Then ExitLoop

$FullFilePath = $SourceFolder & "\" & $File

$FileAttributes = FileGetAttrib($FullFilePath)

If StringInStr($FileAttributes,"D") Then

CountFiles($FullFilePath)

Else

$FileCount += 1

Endif

WEnd

EndFunc

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...