diff --git a/deployment/CONFIGURATION.md b/deployment/CONFIGURATION.md index 747cd068..0048db81 100644 --- a/deployment/CONFIGURATION.md +++ b/deployment/CONFIGURATION.md @@ -46,6 +46,7 @@ cp hosts.yml.example hosts.yml hosts: : ansible_user: + #syslog_server_port: "://:" ``` The config above would install the Oracle on ``, UI on ``, and both Oracle, UI and Monitor on ``. diff --git a/deployment/hosts.yml.example b/deployment/hosts.yml.example index 683c1b67..ac308d63 100644 --- a/deployment/hosts.yml.example +++ b/deployment/hosts.yml.example @@ -16,3 +16,4 @@ sokol-kovan: hosts: 127.0.0.1: ansible_user: ubuntu + #syslog_server_port: "://:" diff --git a/deployment/roles/common/files/daemon.json b/deployment/roles/common/files/daemon.json index 89a39e30..5317bea8 100644 --- a/deployment/roles/common/files/daemon.json +++ b/deployment/roles/common/files/daemon.json @@ -1,5 +1,4 @@ { - "disable-legacy-registry": true, "live-restore": true, "no-new-privileges": true } diff --git a/deployment/roles/monitor/tasks/logging.yml b/deployment/roles/monitor/tasks/logging.yml new file mode 100644 index 00000000..6e860450 --- /dev/null +++ b/deployment/roles/monitor/tasks/logging.yml @@ -0,0 +1,41 @@ +--- +- name: Slurp docker compose file + slurp: + src: "{{ bridge_path }}/monitor/docker-compose.yml" + register: docker_compose_slurp + +- name: Parse docker compose file + set_fact: + docker_compose_parsed: "{{ docker_compose_slurp['content'] | b64decode | from_yaml }}" + +- name: Set logger to remote server + set_fact: + docker_compose_parsed: "{{ docker_compose_parsed |combine({'services': {item: {'logging': {'driver': 'syslog','options': {'tag': '{{.Name}}/{{.ID}}'}}}}}, recursive=True) }}" + with_items: "{{ docker_compose_parsed.services }}" + +- name: Write new docker-compose file + copy: + content: "{{ docker_compose_parsed | to_yaml }}" + dest: "{{ bridge_path }}/monitor/docker-compose.yml" + +- name: Set the local container logs configuration file + template: + src: 33-monitor-docker.conf.j2 + dest: /etc/rsyslog.d/33-monitor-docker.conf + owner: root + group: root + mode: 0644 + +- name: Set the log configuration file to send container logs to remote server + template: + src: 38-monitor-remote-logging.conf.j2 + dest: /etc/rsyslog.d/38-monitor-remote-logging.conf + owner: root + group: root + mode: 0644 + when: syslog_server_port is defined + +- name: restart rsyslog + service: + name: rsyslog + state: restarted diff --git a/deployment/roles/monitor/tasks/main.yml b/deployment/roles/monitor/tasks/main.yml index 18d3cd42..06af77ad 100644 --- a/deployment/roles/monitor/tasks/main.yml +++ b/deployment/roles/monitor/tasks/main.yml @@ -1,4 +1,5 @@ --- - include_tasks: pre_config.yml +- include_tasks: logging.yml - include_tasks: jumpbox.yml - include_tasks: servinstall.yml diff --git a/deployment/roles/monitor/templates/33-monitor-docker.conf.j2 b/deployment/roles/monitor/templates/33-monitor-docker.conf.j2 new file mode 100644 index 00000000..35e9840e --- /dev/null +++ b/deployment/roles/monitor/templates/33-monitor-docker.conf.j2 @@ -0,0 +1,11 @@ +$FileCreateMode 0644 +template(name="DockerLogFileName_Monitor" type="list") { + constant(value="/var/log/docker/") + property(name="syslogtag" securepath="replace" regex.type="ERE" regex.submatch="1" regex.expression="monitor_(.*)\\/[a-zA-Z0-9]+\\[") + constant(value="/docker.log") +} + +if $programname startswith 'monitor_' then \ + ?DockerLogFileName_Monitor + +$FileCreateMode 0600 diff --git a/deployment/roles/monitor/templates/38-monitor-remote-logging.conf.j2 b/deployment/roles/monitor/templates/38-monitor-remote-logging.conf.j2 new file mode 100644 index 00000000..0746736b --- /dev/null +++ b/deployment/roles/monitor/templates/38-monitor-remote-logging.conf.j2 @@ -0,0 +1,15 @@ +if $programname startswith 'monitor_' then { +action( + type="omfwd" + protocol="{{ syslog_server_port.split(":")[0] }}" + target="{{ (syslog_server_port.split(":")[1])[2:] }}" + port="{{ syslog_server_port.split(":")[2] }}" + template="RemoteForwardFormat" + queue.SpoolDirectory="/var/spool/rsyslog" + queue.FileName="remote" + queue.MaxDiskSpace="1g" + queue.SaveOnShutdown="on" + queue.Type="LinkedList" + ResendLastMSGOnReconnect="on" + ) +}