| 1 | See PiwikServer#ServerLogAnalytics |
| 2 | |
| 3 | {{{ |
| 4 | #!/bin/bash |
| 5 | |
| 6 | # date format used in log files names |
| 7 | DATE=$(date "+%Y-%m-%d") |
| 8 | |
| 9 | # location of the latest log file |
| 10 | NEW_LOG="/home/puffin/nginx/puffin-nginx-$DATE.log" |
| 11 | |
| 12 | LOGFILE="/home/puffin/nginx/puffin-nginx.log" |
| 13 | |
| 14 | # check the log file exists and then fix it |
| 15 | # and import it to piwik |
| 16 | if [[ -f $NEW_LOG ]]; then |
| 17 | |
| 18 | # fix the issue with the proxy ip address being added to the first field |
| 19 | cat $NEW_LOG | sed 's/, 127.0.0.1//' > $LOGFILE |
| 20 | |
| 21 | # import the fixed log file |
| 22 | python /web/stats.transitionnetwork.org/piwik/misc/log-analytics/import_logs.py \ |
| 23 | --url=https://stats.transitionnetwork.org/ \ |
| 24 | --idsite=12 --enable-static --enable-bots --enable-http-errors --enable-http-redirect \ |
| 25 | --log-format-regex='"(?P<ip>\S+)" (?P<host>\S+) \[(?P<date>.*?) (?P<timezone>.*?)\] (?P<status>\S+) (?P<length>\S+) \S+ \S+ "(?P<referrer>.*?)" "(?P<user_agent>.*?)" \S+ "\S+"' \ |
| 26 | --recorders=8 $LOGFILE |
| 27 | |
| 28 | fi |
| 29 | }}} |