Cover V05, I12
Article
Listing 1
Listing 2
Listing 3
Listing 4
Listing 5

dec96.tar


Listing 3: Parsing the log file

#!/bin/tcl
#
# /usr/lib/doctor/db/internet.tcl
#
# Procs used to parse the log files, in particular the Netscape
# error log file /usr/internet

#
# Open log file and seek to last position, or start if it has shrunk
#
proc internet_openLog {table path} {
upvar #0 internet_oldsize_$table oldsize
upvar #0 internet_nrow_$table nrow

if { ! [info exists oldsize] } {
set oldsize 0
set nrow 0
}

if { [catch {file size $path} cursize] } {
set oldsize 0
set nrow 0
return {}
}

if { $oldsize == $cursize } {
return {}
}

if { $oldsize > $cursize } {
set nrow 0
dnrow_set $tabname 0
set oldsize 0
}

if { [catch {open $path r} inhandle] } {
error "could not open $path: $inhandle"
}

if { [catch {seek $inhandle $oldsize} result] } {
close $inhandle
error "could not seek $path to $oldsize: $result"
}
set oldsize $cursize

return $inhandle
}

proc internet_parseErrorLog {} {
set table internet_errors
set path /usr/internet/ns_httpd/httpd-80/logs/errors
upvar #0 internet_nrow_$table nrow

set inhandle [internet_openLog $table $path]
if { [lempty $inhandle] } {
return 0
}

set string {}
set pollcheck 0
while {[gets $inhandle input] != -1} {
set result [scan a<<$ ($input) {%s %s for host %s trying to \
%[^,], %[^^]} \
category host operation message]
if {$result != 5} {
dtrace -l 0 -m Internet "bad error log entry: $input"
continue
}
dput $table date [string trim $date {[]}] $nrow
dput $table category [string trimright $category {:}] $nrow
dput $table host $host $nrow
dput $table operation [string trimright $operation {,}] $nrow
dput $table message $message $nrow
incr nrow
}

close $inhandle
return 0
}

# End of File