diff --git a/defaults/main.yml b/defaults/main.yml index 4f43c51621703158c28aa4dd774d27d19459580a..aac7d0e0c08bf42cd91cff2fbc117f7ee94a9d04 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,2 +1,16 @@ --- -# defaults file for eth-log-alerting \ No newline at end of file +eth_log_alerting_binary_url: "https://git.ethitter.com/debian/eth-log-alerting/uploads/73fb61dcec9e953d24f1180d03959e4c/eth-log-alerting_linux_amd64" +eth_log_alerting_binary_dest: /usr/local/bin/eth-log-alerting +eth_log_alerting_config_dest: /etc/eth-log-alerting.json + +eth_log_alerting_debug_dest: "os.Stdout" +eth_log_alerting_debug: false + +eth_log_alerting_logs: + - log_path: "" + webhook_url: "" + username: "" + channel: "" + color: "" + icon_url: "" + search: "" diff --git a/tasks/main.yml b/tasks/main.yml index ccad619cfb84b254f2f44e0be78533692eaa6f16..a3008f694b239d567fec6f1991e8ed7869b8b8bd 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,2 +1,32 @@ --- -# tasks file for eth-log-alerting \ No newline at end of file +- name: Download and install binary + get_url: + url: "{{ eth_log_alerting_binary_url }}" + dest: "{{ eth_log_alerting_binary_dest }}" + mode: 0755 + force: yes + +- name: Set configuration + template: + src: templates/config.j2 + dest: "{{ eth_log_alerting_config_dest }}" + force: yes + owner: root + group: root + mode: 0400 + +- name: Configure logrotate + template: + src: templates/logrotate.j2 + dest: /etc/logrotate.d/eth-log-alerting + force: yes + owner: root + group: root + mode: 0644 + when: eth_log_alerting_debug_dest != "os.Stdout" + +- name: Remove logrotate configuration + file: + dest: /etc/logrotate.d/eth-log-alerting + state: absent + when: eth_log_alerting_debug_dest == "os.Stdout" diff --git a/templates/config.j2 b/templates/config.j2 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0060bae8033626873d72713b066e8b473b6b6dc1 100644 --- a/templates/config.j2 +++ b/templates/config.j2 @@ -0,0 +1,18 @@ +{ + "debug-dest": "{{ eth_log_alerting_debug_dest }}", + "debug": {{ eth_log_alerting_debug|lower }}, + "logs": [ + {% for item in eth_log_alerting_logs %}{% if 0 != loop.index0 %},{% endif %} + + { + "log_path": "{{ item.log_path }}", + "webhook_url": "{{ item.webhook_url }}", + "username": "{{ item.username }}", + "channel": "{{ item.channel }}", + "color": "{{ item.color }}", + "icon_url": "{{ item.icon_url }}", + "search": "{{ item.search }}" + } + {% endfor %} + ] +} diff --git a/templates/logrotate.j2 b/templates/logrotate.j2 new file mode 100644 index 0000000000000000000000000000000000000000..5ea27abe94b8d7899463bdf8b85c8d771e588cef --- /dev/null +++ b/templates/logrotate.j2 @@ -0,0 +1,7 @@ +{{ eth_log_alerting_debug_dest }} { + daily + rotate 14 + notifempty + missingok + compress +}