diff --git a/README.md b/README.md index 524dfa685eb7505ff93ef691da9dcde4605fc0cc..b04e1b5e187d66adf57917f90e033220bdebed88 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ TBD Dependencies ------------ -None +[eth-log-alerting](https://git.ethitter.com/debian/eth-log-alerting) Example Playbook ---------------- diff --git a/defaults/main.yml b/defaults/main.yml index 4f43c51621703158c28aa4dd774d27d19459580a..ccb416efa4d8a0e1c7394c34428648df4026031a 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,2 +1,20 @@ --- -# 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_init_url: "https://git.ethitter.com/debian/eth-log-alerting/raw/v0.0.1/init.sh" +eth_log_alerting_init_dest: /etc/init.d/eth-log-alerting +eth_log_alerting_init_defaults: /etc/default/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/handlers/main.yml b/handlers/main.yml index 82e9b60def7bf3e80b100b7e7e8311946d60a4bb..c9950d8b1bfbab2eb9c55884938fffcb5141f891 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,2 +1,5 @@ --- -# handlers file for eth-log-alerting \ No newline at end of file +- name: restart daemon + service: + name: eth-log-alerting + state: restarted diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000000000000000000000000000000000000..18ef6a3931e7e1770f7708b85ba3684cdf34b476 --- /dev/null +++ b/tasks/install.yml @@ -0,0 +1,17 @@ +--- +- 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 + notify: restart daemon diff --git a/tasks/logrotate.yml b/tasks/logrotate.yml new file mode 100644 index 0000000000000000000000000000000000000000..41098fdae850ef974069d91cf4ccd7ca9f1f9f2b --- /dev/null +++ b/tasks/logrotate.yml @@ -0,0 +1,16 @@ +--- +- 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/tasks/main.yml b/tasks/main.yml index ccad619cfb84b254f2f44e0be78533692eaa6f16..dda2817cede1b9cede3f526f96c8ab61ee07e96b 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,2 +1,4 @@ --- -# tasks file for eth-log-alerting \ No newline at end of file +- include: install.yml +- include: service.yml +- include: logrotate.yml diff --git a/tasks/service.yml b/tasks/service.yml new file mode 100644 index 0000000000000000000000000000000000000000..ee987b4cea286ba5b525a447b5e764af2cb95358 --- /dev/null +++ b/tasks/service.yml @@ -0,0 +1,30 @@ +--- +- name: Install service + get_url: + url: "{{ eth_log_alerting_init_url }}" + dest: "{{ eth_log_alerting_init_dest }}" + mode: 0755 + owner: root + group: root + force: yes + +- name: Configure service + lineinfile: + dest: "{{ eth_log_alerting_init_defaults }}" + line: "{{ item }}" + mode: 0644 + owner: root + group: root + state: present + create: yes + with_items: + - 'DAEMON="{{ eth_log_alerting_binary_dest }}"' + - 'DAEMON_ARGS="-config {{ eth_log_alerting_config_dest }}"' + - 'USER="root"' + notify: restart daemon + +- name: Ensure service is enabled and started + service: + name: eth-log-alerting + enabled: yes + state: started 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 +}