Scalp ์ค์นผํ
Scalp ๋ชจ๋ ์ค์น
https://code.google.com/archive/p/apache-scalp/downloads
์ ๊ทํํ์์ ์ด์ฉํ ๊ณต๊ฒฉ์ฑ ๋ก๊ทธ ๊ตฌ๋ณ ๋ฃฐํ์ผ๋ ๋ฐ์์ค๋ค.
https://github.com/hyyan/apache-scalp/blob/master/default_filter.xml
Apache Tomcat Access Log
1 2 3 4 5 6 7 8 9 | 123.45.678.123 - - [12/Mar/2019:14:26:03 +0900] "GET /test/img/introduce.jpg HTTP/1.1" 200 22366 123.45.678.123 - - [12/Mar/2019:14:26:06 +0900] "POST /test/message HTTP/1.1" 200 207 123.45.678.123 - - [12/Mar/2019:14:26:07 +0900] "POST /test/message HTTP/1.1" 200 536 123.45.678.123 - - [12/Mar/2019:14:26:09 +0900] "POST /test/message HTTP/1.1" 200 259 123.45.678.123 - - [12/Mar/2019:14:26:17 +0900] "POST /test/message HTTP/1.1" 200 324 123.45.678.123 - - [12/Mar/2019:14:26:19 +0900] "POST /test/message HTTP/1.1" 200 336 123.45.678.123 - - [12/Mar/2019:14:26:22 +0900] "POST /test/message HTTP/1.1" 200 472 123.45.678.123 - - [12/Mar/2019:14:26:24 +0900] "POST /test/message HTTP/1.1" 200 341 123.45.678.123 - - [12/Mar/2019:14:26:28 +0900] "POST /test/message HTTP/1.1" 200 231 | cs |
ํด๋น ๋ก๊ทธ์ ํจํด์ ๊ธฐ๋ฐ์ผ๋ก ๋ก๊ทธ๋ถ์์ ํ๊ฒ๋๋ค.
Scalp ์คํ
1 | python scalp-0.4.py -l ${๋ก๊ทธ๊ฒฝ๋ก} -f ${ํํฐ๊ฒฝ๋ก} -o ${์ถ๋ ฅ๊ฒฝ๋ก} --html | cs |
๊ณต๊ฒฉ์ฑ ๋ก๊ทธ๊ฐ ์กด์ฌํ๋ฉด htmlํ์ผ ํํ๋ก ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํด์ค๋ค.
๊ฒฐ๊ณผ ์ถ๋ ฅ
Tmax ์นํฌ๋น ์ ์ฐ์ค ์คํ๋ก๊ทธ ๋ฐ์
Scalp๋ ์ํ์น ์น์๋ฒ๋ฅผ ๊ธฐ์ค์ผ๋ก ๋ก๊ทธ๋ถ์ํ๋๋ก ๊ฐ๋ฐ๋์๋ค. ํ์๋ Tmax ์นํฌ๋น ์ ์ฐ์ค๋ฅผ ์ฌ์ฉํ์ฌ ๊ณต๊ฒฉ์ฑ ๋ก๊ทธ๋ฅผ ๊ฐ์งํ ๋ ค๊ณ ํ๋๋ฐ, ์คํ๋ก๊ทธ ํ์์ด ๋ฌ๋ผ์ Scalp ์คํ์ ์ค๋ฅ๊ฐ ๋จ์ด์ก๋ค.
1 2 3 4 | 123.45.678.123 [01/Jan/2019:10:37:10 +0900] "GET /shell.php HTTP/1.1" 307 166 0 123.45.678.123 [01/Jan/2019:10:37:11 +0900] "GET /appserv.php HTTP/1.1" 307 166 0 123.45.678.123 [01/Jan/2019:10:37:13 +0900] "GET /scripts/setup.php HTTP/1.1" 307 166 0 123.45.678.123 [01/Jan/2019:10:37:14 +0900] "GET /phpmyadmin/scripts/setup.php HTTP/1.1" 307 166 0 | cs |
์ํ์น ํฐ์บฃ ์คํ๋ก๊ทธ์์ ์ฐจ์ด๋ฅผ ํ์ธํ๋ฉด "- -" ๋๋ฌธ์ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ค.
Scalp์ ์ฝ๋๋ฅผ ํ์ธํ์ฌ ์ ๊ทํํ์์ผ๋ก "- -"๋ฅผ ๊ตฌ๋ถํ๋ ๋ถ๋ง ๋ณ๊ฒฝํด์ฃผ๋ฉด ๋๋ค.
๊ธฐ์กด ์ํ์น ์น์๋ฒ ์ ๊ทํํ์
1 | c_reg = re.compile(r'^(.+)-(.*)\[(.+)[-|+](\d+)\] "([A-Z]+)?(.+) HTTP/\d.\d" (\d+)(\s[\d]+)?(\s"(.+)" )?(.*)$') | cs |
ํฐ๋งฅ์ค ์นํฌ๋น ์์ ์ ๊ทํํ์
1 | c_reg = re.compile(r'^(.+)() \[(.+)[-|+](\d+)\] "([A-Z]+)?(.+) HTTP/\d.\d" (\d+)(\s[\d]+)?(\s"(.+)" )?(.*)$') | cs |
batchํ์ผ ์ค์
properties setenv file
1 2 3 4 5 6 | PYTHON=/home/test/python/python2.7.13/bin/python #ํ์ด์ฌ ๊ฒฝ๋ก ACCESS=/home/test/access_log_check/bin #SCALP ๋ชจ๋ ๊ฒฝ๋ก FILTER_PATH=/home/test/access_log_check/config # ํํฐ ๊ฒฝ๋ก LOG_PATH=/home/tmax/webtob/log/test # ์นํฌ๋น ๋ก๊ทธํ์ผ ๊ฒฝ๋ก OUTPUT_PATH=/home/test/access_log_check/logs # ๋ถ์๊ฒฐ๊ณผ ์ถ๋ ฅ ๊ฒฝ๋ก DAY=30 # ํ์ฌ ๋ ์ง๋ก๋ถํฐ ์ง์ ์ผ์๊น์ง ๋ถ์ | cs |
์คํ batch ํ์ผ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | source /home/test/access_log_check/batch/setenv if test $# -eq 0 ; then echo "no params" exit 0 fi OPTION=$1 if test "$OPTION" = "start" then for((i=0;i<$DAY;i++));do sudo ${PYTHON} ${ACCESS}/scalp-0.4_fix.py -l ${LOG_PATH}/"$(date -d $i'day ago' +'access.log_%m%d%Y')" -f ${FILTER_PATH}/filter.xml -o ${OUTPUT_PATH} --html done elif test "$OPTION" != "" then echo "wrong" fi | cs |
๋๊ธ