From ec9954b900b9a1bcddb66561b3333c0ed9940897 Mon Sep 17 00:00:00 2001
From: Erick Hitter <git-contrib@ethitter.com>
Date: Sun, 19 Aug 2018 19:15:10 -0700
Subject: [PATCH 1/4] Bump

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 524dfa6..b04e1b5 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
 ----------------
-- 
GitLab


From 88689bf77be52080ba1f06d68f2494d5f054d8e5 Mon Sep 17 00:00:00 2001
From: Erick Hitter <git-contrib@ethitter.com>
Date: Sun, 19 Aug 2018 19:59:32 -0700
Subject: [PATCH 2/4] Basic, working role

---
 defaults/main.yml      | 16 +++++++++++++++-
 tasks/main.yml         | 32 +++++++++++++++++++++++++++++++-
 templates/config.j2    | 18 ++++++++++++++++++
 templates/logrotate.j2 |  7 +++++++
 4 files changed, 71 insertions(+), 2 deletions(-)
 create mode 100644 templates/logrotate.j2

diff --git a/defaults/main.yml b/defaults/main.yml
index 4f43c51..aac7d0e 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 ccad619..a3008f6 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 e69de29..0060bae 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 0000000..5ea27ab
--- /dev/null
+++ b/templates/logrotate.j2
@@ -0,0 +1,7 @@
+{{ eth_log_alerting_debug_dest }} {
+  daily
+  rotate 14
+  notifempty
+  missingok
+  compress
+}
-- 
GitLab


From 53a7f954a1a3244a33238027d95aafb2c99f568c Mon Sep 17 00:00:00 2001
From: Erick Hitter <git-contrib@ethitter.com>
Date: Sun, 19 Aug 2018 20:42:26 -0700
Subject: [PATCH 3/4] Install service using sysv script

---
 defaults/main.yml   |  4 ++++
 tasks/install.yml   | 16 ++++++++++++++++
 tasks/logrotate.yml | 16 ++++++++++++++++
 tasks/main.yml      | 34 +++-------------------------------
 tasks/service.yml   | 29 +++++++++++++++++++++++++++++
 5 files changed, 68 insertions(+), 31 deletions(-)
 create mode 100644 tasks/install.yml
 create mode 100644 tasks/logrotate.yml
 create mode 100644 tasks/service.yml

diff --git a/defaults/main.yml b/defaults/main.yml
index aac7d0e..ccb416e 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -1,6 +1,10 @@
 ---
 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"
diff --git a/tasks/install.yml b/tasks/install.yml
new file mode 100644
index 0000000..6b78c3d
--- /dev/null
+++ b/tasks/install.yml
@@ -0,0 +1,16 @@
+---
+- 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
diff --git a/tasks/logrotate.yml b/tasks/logrotate.yml
new file mode 100644
index 0000000..41098fd
--- /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 a3008f6..dda2817 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -1,32 +1,4 @@
 ---
-- 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"
+- include: install.yml
+- include: service.yml
+- include: logrotate.yml
diff --git a/tasks/service.yml b/tasks/service.yml
new file mode 100644
index 0000000..9342f1c
--- /dev/null
+++ b/tasks/service.yml
@@ -0,0 +1,29 @@
+---
+- 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"'
+
+- name: Ensure service is enabled and started
+  service:
+    name: eth-log-alerting
+    enabled: yes
+    state: started
-- 
GitLab


From 184b12adc339eaa79a6d6b8593f3019d5813bb9b Mon Sep 17 00:00:00 2001
From: Erick Hitter <git-contrib@ethitter.com>
Date: Sun, 19 Aug 2018 20:52:50 -0700
Subject: [PATCH 4/4] Handle restarts after config updates

---
 handlers/main.yml | 5 ++++-
 tasks/install.yml | 1 +
 tasks/service.yml | 1 +
 3 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/handlers/main.yml b/handlers/main.yml
index 82e9b60..c9950d8 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
index 6b78c3d..18ef6a3 100644
--- a/tasks/install.yml
+++ b/tasks/install.yml
@@ -14,3 +14,4 @@
     owner: root
     group: root
     mode: 0400
+  notify: restart daemon
diff --git a/tasks/service.yml b/tasks/service.yml
index 9342f1c..ee987b4 100644
--- a/tasks/service.yml
+++ b/tasks/service.yml
@@ -21,6 +21,7 @@
     - '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:
-- 
GitLab