WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Dr Watson Parser


We had a need to retrieve information from Dr. Watson logs on machines across our network.

We wanted the machine that the error occurred on, the date of the error and the exe that caused the error.

We couldn't find any pre-built tools to do this, so i wrote my own parser. It's a command line tool. Run the executable by itself or with the /? parameter to get the command syntax.

It's kinda tricky to parse the logs out, but it works pretty well.

;PARSEWAT.WBT
; ----------------------------------------------------------------------------------------
; Module Name: BLineSearch
; Description: 
;inputfile      - Full path + filename + extension of file to search
;offset         - Binary offset location to start search
;clue           - String to search for
;CS             - Case-sensitivity (0=No, 1=Yes)
;moreinfo       - BLineSearch Return (value) depends on the switch "moreinfo"
;                   - moreinfo = 0  then  Return line or "failure_notice" 
;                   - moreinfo = 1  then  Return line or "failure_notice" + | buffer size | offset of clue | line begin | line end | line length
;                   - moreinfo = 2  then  Return line or "failure_notice" + @CRLF buffer size @CRLF offset of clue @CRLF line begin @CRLF line end @CRLF line length
;failure_notice - String to return if nothing was found
; ----------------------------------------------------------------------------------------;

#DefineFunction BLineSearch(fInputFile, offset, szClue, bCS, iMoreInfo, szFailureNotice)
  ; ------------------------------------------------------------------
  ; Search for the clue
  ; ------------------------------------------------------------------
  iFileSize=FileSize(fInputFile)
  binbuf = BinaryAlloc(iFileSize)
  BinaryRead(binbuf, fInputFile)
  index = BinaryIndexEx(binbuf, offset, szClue, @FWDSCAN, bCS)
  
  ; ------------------------------------------------------------------
  ; If szClue was found, return line
  ; ------------------------------------------------------------------
  If (index>=0)
    ; ------------------------------------------------------------------
    ; +2 for CRLF
    ; ------------------------------------------------------------------
    linebegin = BinaryIndex(binbuf, index, @CRLF, @BACKSCAN) + 2
    ; ------------------------------------------------------------------
    ; Compensate for 1st line having no previous CRLF
    ; ------------------------------------------------------------------
    If (linebegin==2) then linebegin=0                              
    lineend = BinaryIndex(binbuf, linebegin, @CRLF, @FWDSCAN)  
    linelen = lineend-linebegin
    szLineData = BinaryPeekStr(binbuf, linebegin, linelen)
    
    ; ------------------------------------------------------------------
    ; Included Extra info about the location, filesize, linelenght, etc..
    ; ------------------------------------------------------------------
    Switch iMoreInfo
      Case 1
        szLineData=StrCat(szLineData,"|",iFileSize,"|", index,"|",linebegin,"|",lineend,"|",linelen)
        Break
      Case 2
        szLineData=StrCat(szLineData,@CRLF,@CRLF,"File Size= ", iFileSize, @CRLF, "Offset= ",index,@CRLF,"Line BEGIN= ",linebegin,@CRLF,"Line END= ",lineend,@CRLF,"Line LENGTH= ",linelen)
        Break
      Case iMoreInfo
        szLineData=szLineData
        Break
    Endswitch
  
  Else
    szLineData=szFailureNotice
  Endif
  
  binbuf=BinaryFree(binbuf)
  Return(szLineData)
#Endfunction

; ----------------------------------------------------------------------------------------
; Module Name: CheckParam
; Description: Parses out the parameters
; ----------------------------------------------------------------------------------------
#DefineSubroutine CheckParam(CurrentParam)
  ParamFound = @FALSE
  
  If StrIndex(CurrentParam,"/M:",1,@FWDSCAN) <> 0
    ParamFound=@TRUE
    szMachine = StrSub(CurrentParam,4,StrLen(CurrentParam))
  EndIf
  
  If StrIndex(CurrentParam,"/O:",1,@FWDSCAN) <> 0
    ParamFound=@TRUE
    szOutputFile = StrSub(CurrentParam,4,StrLen(CurrentParam))
  EndIf
  
  If StrIndex(CurrentParam,"/A:",1,@FWDSCAN) <> 0
    ParamFound=@TRUE
    szAppName = StrUpper(StrSub(CurrentParam,4,StrLen(CurrentParam)))
  EndIf
  
  If CurrentParam == "/?" Then ShowSyntax()
  
  If ParamFound == @FALSE Then
    Message("Error","The following parameter is invalid or not recognized:%@CRLF%%@CRLF%%CurrentParam%")
    Exit
  EndIf
#EndSubRoutine

; ----------------------------------------------------------------------------------------
; Module Name: ShowSyntax
; Description: Shows this executables syntax
; ----------------------------------------------------------------------------------------
#DefineFunction ShowSyntax()
  Line01='Dr. Watson Log Parser%@CRLF%%@CRLF%'
  Line02='Syntax: ParseWat.exe [/M:x] [/O:x] [/A:x]%@CRLF%%@CRLF%'
  Line03='Command Line Options:%@CRLF%'
  Line04='  /M:      - Workstation To Run Against%@CRLF%'
  Line05='  /O:      - File For Results Output%@CRLF%'
  Line06='  /A:      - Only Detect Logs For This Specified Executable (Optional)%@CRLF%%@CRLF%'
  Line07='Examples:%@CRLF%'
  Line08='  ParseWat.exe /M:spscnt018573 /O:c:\results.csv%@CRLF%'
  Line09='  ParseWat.exe /M:gbscnt016349 /O:h:\QueryList.txt%@CRLF%'
  Line10='  ParseWat.exe /M:gbscnt016349 /O:h:\QueryList.txt /A:Extra.exe%@CRLF%'
  msg = StrCat(Line01,Line02,Line03,Line04,Line05,Line06,Line07,Line08,Line09,Line10)
  Message("Dr. Watson Log Parser",msg)
  Exit
#EndFunction

; ----------------------------------------------------------------------------------------
; Module Name: ParseLog
; Description: Rips through a dr. watson log and retrieves the time of the error and what
;              exe/app caused the crash
; ----------------------------------------------------------------------------------------
#DefineFunction ParseLog(szMachine,szOutputFile,szAppName)
  ; ---------------------
  ; Variables
  ; ---------------------
  szFile = FileGet("\\%szMachine%\c$\winnt\drwtsn32.log","")
  szTemp = Environment("TEMP")
  szFile = StrReplace(szFile,"Application exception occurred:","®")
  iIndex = ItemCount(szFile,"®")-1
  
  for x=1 to iIndex
    szException = ItemExtract(x+1,szFile,"®")
    szException = StrCat("Application exception occurred:",szException)
    
    iPID = StrSub(szException,StrIndex(szException,"(",1,@FWDSCAN)+5,StrIndex(szException,")",1,@FWDSCAN)-(StrIndex(szException,"(",1,@FWDSCAN)+5))
  
    File = FileOpen("%szTemp%\DrWtsnWrk%szMachine%.txt","WRITE")
    FileWrite(File,szException)
    FileClose(File)
  
    szApp = StrTrim(BLineSearch("%szTemp%\DrWtsnWrk%szMachine%.txt", 2, "%iPID% ", @FALSE, 0, "Not Found"))
    
    szApp = StrUpper(StrTrim(StrSub(szApp, StrIndex(szApp," ",2,@FWDSCAN),-1)))
    
    iTimeStart = StrIndex(szException,"When:",1,@FWDSCAN)+6
    szTime = StrSub(szException,iTimeStart,StrIndex(szException,"%@CRLF%",iTimeStart,@FWDSCAN)-iTimeStart)
    
    if szAppName <> ""
      if szApp == szAppName
        File = FileOpen(szOutputFile,"APPEND")
        FileWrite(File,StrCat(szMachine,",",szApp,",",szTime))
        FileClose(File)
      endif
    else
      
      File = FileOpen(szOutputFile,"APPEND")
      FileWrite(File,StrCat(szMachine,",",szApp,",",szTime))
      FileClose(File)
    endif
  next
  
  FileDelete("%szTemp%\DrWtsnWrk%szMachine%.txt")
#EndFunction

; ---------------------------------
; Variables
; ---------------------------------
szMachine = ""
szOutputFile = ""
szAppName = ""

if param0 == 0 then ShowSyntax()

For x = 1 to %param0%
  CheckParam(StrUpper(Param%x%))
Next

If szMachine == ""
  Message("Error","Dr. Watson Log Parser needs the /M: parameter to run")
  Exit
EndIf

If szOutputFile == ""
  Message("Error","Dr. Watson Log Parser needs the /O: parameter to run")
  Exit
EndIf

if FileExist("\\%szMachine%\c$\winnt\drwtsn32.log")
  ParseLog(szMachine,szOutputFile,szAppName)
endif

Article ID:   W16187
File Created: 2004:06:29:09:57:30
Last Updated: 2004:06:29:09:57:30