mysql:quickloganalyzer
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
mysql:quickloganalyzer [2012/05/02 17:18] – rlunaro | mysql:quickloganalyzer [2022/12/02 21:02] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== A quick log analyzer ====== | ||
+ | |||
+ | |||
+ | Here comes a quick log analyzer for web logs. It is an [[http:// | ||
+ | |||
+ | A little of AWK is required, and knowledge of regular expressions. | ||
+ | |||
+ | < | ||
+ | 10.255.255.255 - - [17/ | ||
+ | 10.256.256.256 - - [17/ | ||
+ | </ | ||
+ | |||
+ | <code awk> | ||
+ | # | ||
+ | # logs2mysql.awk - inserta los logs en una base de datos para hacer análisis | ||
+ | # | ||
+ | # To execute: | ||
+ | # awk -f logs2mysql.awk logfile.log| mysql -h hostname -u username -p database | ||
+ | # | ||
+ | # | ||
+ | # create table analisis | ||
+ | # ( ip varchar( 1000 ), | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # url varchar( 1000 ), | ||
+ | # | ||
+ | # | ||
+ | # bytes varchar( 1000 ), | ||
+ | # | ||
+ | # ); | ||
+ | # | ||
+ | |||
+ | BEGIN { | ||
+ | print "-- awk -f logs2mysql.sql logfile.log| mysql -h hostname -u username -p database "; | ||
+ | print "-- awk -f logs2mysql.sql logfile.log| mysql -h hostname -u username -p database "; | ||
+ | print "-- awk -f logs2mysql.sql logfile.log| mysql -h hostname -u username -p database "; | ||
+ | |||
+ | |||
+ | |||
+ | command = " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | "'## | ||
+ | "'## | ||
+ | " | ||
+ | "'## | ||
+ | "'## | ||
+ | "'## | ||
+ | "'## | ||
+ | "'## | ||
+ | "'## | ||
+ | } | ||
+ | |||
+ | /.*/ { | ||
+ | # | ||
+ | match( $0, "^([^ ]*) ([^ ]*) ([^ ]*) \\[(.*)\\] ([[: | ||
+ | # print "ip: " values[1]; | ||
+ | # print " | ||
+ | # print " | ||
+ | # print " | ||
+ | # print " | ||
+ | # print "url: " values[6]; | ||
+ | # print " | ||
+ | # print " | ||
+ | # print " | ||
+ | # print "user agent: " values[10]; | ||
+ | # print " | ||
+ | |||
+ | url = values[6]; | ||
+ | ignore = 0; | ||
+ | ignore = ignore || match( url, " | ||
+ | ignore = ignore || match( url, " | ||
+ | ignore = ignore || match( url, " | ||
+ | |||
+ | if( !ignore ) | ||
+ | { | ||
+ | out = command; | ||
+ | out = gensub( "## | ||
+ | out = gensub( "## | ||
+ | out = gensub( "## | ||
+ | the_date = gensub( " | ||
+ | out = gensub( "## | ||
+ | out = gensub( "## | ||
+ | out = gensub( "## | ||
+ | out = gensub( "## | ||
+ | out = gensub( "## | ||
+ | out = gensub( "## | ||
+ | out = gensub( "## | ||
+ | print out; | ||
+ | } # if ignore | ||
+ | |||
+ | } | ||
+ | |||
+ | END { | ||
+ | } | ||
+ | |||
+ | function escape( input ) | ||
+ | { | ||
+ | out = input; | ||
+ | out = gensub( ";", | ||
+ | out = gensub( " | ||
+ | out = gensub( " | ||
+ | out = gensub( "'", | ||
+ | out = gensub( " | ||
+ | |||
+ | return out; | ||
+ | |||
+ | } # escape | ||
+ | |||
+ | |||
+ | |||
+ | </ | ||
+ | |||