diff --git a/bundles/monit/files/monitrc b/bundles/monit/files/monitrc new file mode 100644 index 0000000..b94e503 --- /dev/null +++ b/bundles/monit/files/monitrc @@ -0,0 +1,45 @@ +set daemon 30 + with start delay 30 +set log syslog + +set mailserver localhost + +set mail-format { from: ${monit['from_address']} } +% for alert_address in monit['alert_addresses']: +set alert ${alert_address} +% endfor + +set httpd unixsocket /var/run/monit.sock + use address 127.0.0.1 + allow 127.0.0.1 + +check system $HOST + if cpu usage > 95% for 10 cycles then alert + if memory usage > 80% then alert + if swap usage > 25% then alert + +check filesystem rootfs with path / + if space usage > 80% for 5 times within 15 cycles then alert + if space usage > 90% then alert + if inode usage > 90% then alert + +check process cron matching "/usr/sbin/cron" + start program = "/usr/bin/systemctl start cron.service" + stop program = "/usr/bin/systemctl stop cron.service" + +% for systemd_service in ('systemd-timesyncd', 'systemd-networkd', 'systemd-journald'): +check process ${systemd_service} matching "/lib/systemd/${systemd_service}" + start program = "/usr/bin/systemctl start ${systemd_service}.service" + stop program = "/usr/bin/systemctl stop ${systemd_service}.service" +% endfor + +check process sshd matching "/usr/sbin/sshd" + start program = "/bin/systemctl start sshd.service" + stop program = "/bin/systemctl stop sshd.service" + if failed port 22 for 2 cycles then restart + if 3 restarts within 5 cycles then alert + +check process postfix matching "/usr/lib/postfix/sbin/master" + start program = "/bin/systemctl start postfix.service" + stop program = "/bin/systemctl stop postfix.service" + if failed port 25 protocol smtp for 5 cycles then restart diff --git a/bundles/monit/items.py b/bundles/monit/items.py new file mode 100644 index 0000000..e5f8a2b --- /dev/null +++ b/bundles/monit/items.py @@ -0,0 +1,38 @@ +svc_systemd = { + 'monit': { + 'needs': [ + 'pkg_apt:monit', + ], + }, +} + +files = { + '/etc/monit/monitrc': { + 'mode': '0400', + 'content_type': 'mako', + 'needs': [ + 'pkg_apt:monit', + ], + 'triggers': [ + 'svc_systemd:monit:restart', + ], + 'context': { + 'monit': node.metadata['monit'], + }, + }, +} + +directories = { + '/etc/monit/conf-enabled': { + 'purge': True, + }, + '/etc/monit/conf-available': { + 'purge': True, + }, + '/etc/monit/conf.d': { + 'purge': True, + }, + '/etc/monit/templates': { + 'purge': True, + }, +} diff --git a/bundles/monit/metadata.py b/bundles/monit/metadata.py new file mode 100644 index 0000000..499f943 --- /dev/null +++ b/bundles/monit/metadata.py @@ -0,0 +1,7 @@ +defaults = { + 'apt': { + 'packages': { + 'monit': {}, + }, + }, +}