Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Support for Goaccess #1647

Closed
wants to merge 10 commits into from
10 changes: 10 additions & 0 deletions default.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ apache_vhosts:
documentroot: "{{ pimpmylog_install_dir }}"
extra_parameters: "{{ apache_vhost_php_fpm_parameters }}"

- servername: "goaccess.{{ vagrant_hostname }}"
documentroot: "{{ goaccess_install_dir }}"
extra_parameters: ""

- servername: "{{ vagrant_ip }}"
serveralias: "dashboard.{{ vagrant_hostname }}"
documentroot: "{{ dashboard_install_dir }}"
Expand Down Expand Up @@ -175,6 +179,10 @@ nginx_hosts:
root: "{{ pimpmylog_install_dir }}"
is_php: true

- server_name: "goaccess.{{ vagrant_hostname }}"
root: "{{ goaccess_install_dir }}"
is_php: false

- server_name: "{{ vagrant_ip }} dashboard.{{ vagrant_hostname }}"
root: "{{ dashboard_install_dir }}"
is_php: true
Expand Down Expand Up @@ -213,6 +221,7 @@ installed_extras:
# - drupalconsole
- drush
# - elasticsearch
# - goaccess
# - java
- mailhog
# - memcached
Expand Down Expand Up @@ -344,6 +353,7 @@ docker_image_path: ~/Downloads

# Other configuration.
dashboard_install_dir: /var/www/dashboard
goaccess_install_dir: /var/www/goaccess
known_hosts_path: ~/.ssh/known_hosts
hostname_configure: true
hostname_fqdn: "{{ vagrant_hostname }}"
Expand Down
4 changes: 4 additions & 0 deletions provisioning/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@
- include: tasks/cron.yml
tags: ['cron']

- include: tasks/goaccess.yml
when: '"goaccess" in installed_extras'
tags: ['goaccess']

- include: tasks/dashboard.yml
when: dashboard_install_dir is defined and dashboard_install_dir != ''
tags: ['webserver', 'database', 'php']
Expand Down
95 changes: 95 additions & 0 deletions provisioning/tasks/goaccess.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---

- name: Looking for GoAccess
stat:
path: /usr/local/bin/goaccess
register: goaccess_stat

- name: Ensure GoAccess dependencies are installed
package:
name: "{{ item }}"
state: installed
with_items:
- libgeoip-dev
- libncursesw5-dev
when: goaccess_stat.stat.exists|bool == false

- name: Create Directory for GoAccess
file:
path: /opt/goaccess-1.2
state: directory
mode: 0775
when: goaccess_stat.stat.exists|bool == false

- name: Download GoAccess
unarchive:
src: http://tar.goaccess.io/goaccess-1.2.tar.gz
dest: /opt/
remote_src: yes
when: goaccess_stat.stat.exists|bool == false

- name: Make GoAccess
command: "{{ item }}"
args:
chdir: '/opt/goaccess-1.2/'
with_items:
- ./configure --enable-utf8 --enable-geoip=legacy
- make
- make install
when: goaccess_stat.stat.exists|bool == false

- name: Configure GoAcccess for Apache
lineinfile:
path: /usr/local/etc/goaccess.conf
regexp: '{{ item.regex|regex_escape() }}'
line: '{{ item.replace }}'
backrefs: yes
state: present
with_items:
- regex: '#time-format %H:%M:%S'
replace: 'time-format %H:%M:%S'
- regex: '#date-format %d/%b/%Y'
replace: 'date-format %d/%b/%Y'
- regex: 'log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"'
replace: '#log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"'
- regex: '#log-format %v:%^ %h %^[%d:%t %^] "%r" %s %b "%R" "%u"'
replace: 'log-format %v:%^ %h %^[%d:%t %^] "%r" %s %b "%R" "%u"'
when: 'drupalvm_webserver == "apache"'

- name: Configure GoAcccess for NGINX
lineinfile:
path: /usr/local/etc/goaccess.conf
regexp: '{{ item.regex|regex_escape() }}'
line: '{{ item.replace }}'
backrefs: yes
state: present
with_items:
- regex: '#time-format %H:%M:%S'
replace: 'time-format %H:%M:%S'
- regex: '#date-format %d/%b/%Y'
replace: 'date-format %d/%b/%Y'
- regex: '#log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"'
replace: 'log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"'
- regex: 'log-format %v:%^ %h %^[%d:%t %^] "%r" %s %b "%R" "%u"'
replace: '#log-format %v:%^ %h %^[%d:%t %^] "%r" %s %b "%R" "%u"'
when: 'drupalvm_webserver == "nginx"'

- name: Create folder for GoAccess output
file:
path: "{{ goaccess_install_dir }}"
state: directory
mode: 0777

- name: Ensure GoAccess cron task is present for Apache
cron:
name: "Update GoAccess data"
state: present
job: "/usr/local/bin/goaccess /var/log/apache2/access.log -o {{ goaccess_install_dir }}/index.html"
when: 'drupalvm_webserver == "apache"'

- name: Ensure GoAccess cron task is present for NGINX
cron:
name: "Update GoAccess data"
state: present
job: "/usr/local/bin/goaccess /var/log/nginx/access.log -o {{ goaccess_install_dir }}/index.html"
when: 'drupalvm_webserver == "nginx"'