From 1985761f00bd9a8bb2c975c003bba9f5bf40f601 Mon Sep 17 00:00:00 2001 From: KemoNine Date: Tue, 4 Aug 2020 23:57:58 +0000 Subject: [PATCH] Initial bring up of monit role --- playbook-frames.yml | 1 + roles/monit/defaults/main.yml | 18 ++++++++++++++++++ roles/monit/handlers/main.yml | 0 roles/monit/tasks/main.yml | 31 +++++++++++++++++++++++++++++++ roles/monit/templates/filesystem | 2 ++ roles/monit/templates/monitrc | 15 +++++++++++++++ 6 files changed, 67 insertions(+) create mode 100644 roles/monit/handlers/main.yml create mode 100644 roles/monit/templates/filesystem create mode 100644 roles/monit/templates/monitrc diff --git a/playbook-frames.yml b/playbook-frames.yml index 3debcc6..60fe139 100644 --- a/playbook-frames.yml +++ b/playbook-frames.yml @@ -4,3 +4,4 @@ roles: - msmtp - hdmi + - monit diff --git a/roles/monit/defaults/main.yml b/roles/monit/defaults/main.yml index e69de29..c997aa3 100644 --- a/roles/monit/defaults/main.yml +++ b/roles/monit/defaults/main.yml @@ -0,0 +1,18 @@ +--- + +# Notifiation email setup +monit_notification_email: "user@domain.tld" +monit_smtp_server: "mail.domain.tld" +monit_smtp_user: "user@domain.tld" +monit_smtp_password: "password" + +# Filesystems to monitor +monit_filesystems: + - { name: "rootfs", path: "/", alert: "80%" } + +# Monitor WireGuard? +monit_wireguard: true + +# Username / password for monit web service +monit_web_user: "admin" +monit_web_pasword: "password" diff --git a/roles/monit/handlers/main.yml b/roles/monit/handlers/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/roles/monit/tasks/main.yml b/roles/monit/tasks/main.yml index e69de29..26ce40e 100644 --- a/roles/monit/tasks/main.yml +++ b/roles/monit/tasks/main.yml @@ -0,0 +1,31 @@ +--- + - name: Gather instance facts + setup: + - name: Update APT package cache + apt: + update_cache: "true" + cache_valid_time: "3600" + tags: + - monit-install + - name: Install monit + package: + name: "{{ packages }}" + state: present + vars: + packages: + - monit + tags: + - monit-install + - block: + - name: Setup filesystem monitoring + template: + src: filesystem + dest: "/etc/monit/conf.d/{{item.name}}" + owner: root + group: root + mode: 0644 + loop: + {{ monit_filesystems }} + tags: + - monit-config + - monit-filesystems \ No newline at end of file diff --git a/roles/monit/templates/filesystem b/roles/monit/templates/filesystem new file mode 100644 index 0000000..5e7a678 --- /dev/null +++ b/roles/monit/templates/filesystem @@ -0,0 +1,2 @@ +check filesystem {{ item.name }} with path {{ item.path }} + if space usage > {{ item.alert }} then alert diff --git a/roles/monit/templates/monitrc b/roles/monit/templates/monitrc new file mode 100644 index 0000000..7efc272 --- /dev/null +++ b/roles/monit/templates/monitrc @@ -0,0 +1,15 @@ +set log /var/log/monit.log +set idfile /var/lib/monit/id +set statefile /var/lib/monit/state +set eventqueue + +set mailserver {{ monit_smtp_server }} port 587 + username "{{ monit_smtp_user }}" password "{{ monit_smtp_password }}" + using tls + +set httpd port 2812 and + use address 0.0.0.0 + allow {{ monit_web_user }}:{{ monit_web_pasword }} + +include /etc/monit/conf.d/* +include /etc/monit/conf-enabled/*