From 52d170c16f6f0f72e314c2a30150e512bfadb5ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Urba=C5=84ski?= Date: Mon, 31 Oct 2016 16:12:41 +0100 Subject: [PATCH 01/15] Allow to specify sender address in e-mails --- monit/files/mail | 2 +- pillar.example | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/monit/files/mail b/monit/files/mail index b73d914..03ff1c1 100644 --- a/monit/files/mail +++ b/monit/files/mail @@ -3,7 +3,7 @@ set alert {{email}} ON { invalid, timeout, resource, size, timestamp } {% endfor %} {%- if mail_alert.account.email and mail_alert.account.password -%} -set mail-format { from: {{mail_alert.account.email}} } +set mail-format { from: {{mail_alert.get('send_as', mail_alert.account.email)}} } {%- endif -%} {%- if mail_alert.account.server and mail_alert.account.port %} diff --git a/pillar.example b/pillar.example index 33c51b4..e10b36b 100644 --- a/pillar.example +++ b/pillar.example @@ -5,6 +5,7 @@ monit: port: 587 email: some@example.com password: p@ssw0rd;) + send_as: Monit Daemon users: - first@example.com - second@example.com From 77ad3fe1c20cd4e3d2423074a8666b552ad83d74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Urba=C5=84ski?= Date: Mon, 31 Oct 2016 16:28:16 +0100 Subject: [PATCH 02/15] Change pillar.example --- pillar.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pillar.example b/pillar.example index e10b36b..9e4049f 100644 --- a/pillar.example +++ b/pillar.example @@ -5,7 +5,7 @@ monit: port: 587 email: some@example.com password: p@ssw0rd;) - send_as: Monit Daemon + send_as: monit@example.com users: - first@example.com - second@example.com From 08cba15d424ee0c85eda4a8c9821936907e4618e Mon Sep 17 00:00:00 2001 From: Arthur Lutz Date: Wed, 25 Jan 2017 16:35:18 +0100 Subject: [PATCH 03/15] mode for monitrc if default is left monit won't start (at least on debian) and so install of pkg fails. --- monit/config.sls | 1 + 1 file changed, 1 insertion(+) diff --git a/monit/config.sls b/monit/config.sls index 23d200d..0d6b6d0 100644 --- a/monit/config.sls +++ b/monit/config.sls @@ -6,6 +6,7 @@ - source: salt://monit/files/monitrc - template: jinja - makedirs: True + - mode: '0700' - context: config_includes: {{ monit.config_includes }} http_access: {{ monit.http_access }} From 694f3937a8d19edd6a0b3f2eca6c62958074fb0b Mon Sep 17 00:00:00 2001 From: Arthur Lutz Date: Wed, 25 Jan 2017 16:36:25 +0100 Subject: [PATCH 04/15] split loop into two loops to make sure check starts block --- monit/files/modules | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/monit/files/modules b/monit/files/modules index e39e86f..ea0c0cd 100644 --- a/monit/files/modules +++ b/monit/files/modules @@ -48,6 +48,10 @@ {%- if 'pidfile' in kind_v or 'path' in kind_v %} check {{ mod_name }} {{ name }} with {{ element }} {{ element_v }} {%- endif -%} + {% endfor %} + {% endfor %} + {%- for kind, kind_v in mod_name_v.iteritems() -%} + {%- for element, element_v in kind_v.iteritems() -%} {#- 'config' is the lines containing 'group', 'start program', etc #} {%- if 'config' in kind -%} From 13650100fb3edb39b183379fbea8297154ab4b77 Mon Sep 17 00:00:00 2001 From: Arthur Lutz Date: Wed, 25 Jan 2017 16:39:36 +0100 Subject: [PATCH 05/15] optionnal password in pillar --- monit/files/mail | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monit/files/mail b/monit/files/mail index b73d914..ae53046 100644 --- a/monit/files/mail +++ b/monit/files/mail @@ -2,13 +2,13 @@ set alert {{email}} ON { invalid, timeout, resource, size, timestamp } {% endfor %} -{%- if mail_alert.account.email and mail_alert.account.password -%} +{%- if mail_alert.account.email -%} set mail-format { from: {{mail_alert.account.email}} } {%- endif -%} {%- if mail_alert.account.server and mail_alert.account.port %} set mailserver {{mail_alert.account.server}} port {{mail_alert.account.port}} - {%- if mail_alert.account.email and mail_alert.account.password %} + {%- if mail_alert.account.email and 'password' in mail_alert.account and mail_alert.account.password %} username "{{mail_alert.account.email}}" password "{{mail_alert.account.password}}" using tlsv1 {%- endif %} From 20f5c663ef4b299a9b1e839adf4bf3fbe413b484 Mon Sep 17 00:00:00 2001 From: waynegemmell Date: Fri, 10 Aug 2018 16:32:21 +0200 Subject: [PATCH 06/15] Doesn't fail on mailserver without credentials I've updated the file to not fail when there are no credentials on the mail server. --- monit/files/mail | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monit/files/mail b/monit/files/mail index 2bb85a7..89a3848 100644 --- a/monit/files/mail +++ b/monit/files/mail @@ -2,13 +2,13 @@ set alert {{email}} ON { invalid, timeout, resource, size, timestamp } {% endfor %} -{%- if mail_alert.account.email and mail_alert.account.password -%} +{%- if mail_alert.account.email is defined and mail_alert.account.password is defined -%} set mail-format { from: {{mail_alert.get('send_as', mail_alert.account.email)}} } {%- endif -%} {%- if mail_alert.account.server and mail_alert.account.port %} set mailserver {{mail_alert.account.server}} port {{mail_alert.account.port}} - {%- if mail_alert.account.email and 'password' in mail_alert.account and mail_alert.account.password %} + {%- if mail_alert.account.email is defined and mail_alert.account.password is defined %} username "{{mail_alert.account.email}}" password "{{mail_alert.account.password}}" using tlsv1 {%- endif %} From 7cd6405fd5e8226eb3b304d20e84ffbfca8d3544 Mon Sep 17 00:00:00 2001 From: waynegemmell Date: Mon, 27 Aug 2018 11:04:47 +0200 Subject: [PATCH 07/15] Updated mail to work if there is no email address --- monit/files/mail | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monit/files/mail b/monit/files/mail index 2bb85a7..bf04482 100644 --- a/monit/files/mail +++ b/monit/files/mail @@ -8,7 +8,7 @@ set mail-format { from: {{mail_alert.get('send_as', mail_alert.account.email)}} {%- if mail_alert.account.server and mail_alert.account.port %} set mailserver {{mail_alert.account.server}} port {{mail_alert.account.port}} - {%- if mail_alert.account.email and 'password' in mail_alert.account and mail_alert.account.password %} + {%- if mail_alert.account.email is defined and mail_alert.account.password is defined %} username "{{mail_alert.account.email}}" password "{{mail_alert.account.password}}" using tlsv1 {%- endif %} From b85d44d17f4b4aeb0175bb59801489c0f1a3212a Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Wed, 6 Mar 2019 06:57:26 +0000 Subject: [PATCH 08/15] fix(monitrc): use `|json` to resolve `2019.2` breaking change * Close #9: - Fix already tested in that issue --- monit/config.sls | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monit/config.sls b/monit/config.sls index 0d6b6d0..7060472 100644 --- a/monit/config.sls +++ b/monit/config.sls @@ -8,8 +8,8 @@ - makedirs: True - mode: '0700' - context: - config_includes: {{ monit.config_includes }} - http_access: {{ monit.http_access }} + config_includes: {{ monit.config_includes | json }} + http_access: {{ monit.http_access | json }} {#- This is the mail alert configuration #} {% if monit.mail_alert is defined %} From 611147e373cdbd95ebf9d817d4e64b3a5351e95c Mon Sep 17 00:00:00 2001 From: Wayne Gemmell Date: Thu, 7 Mar 2019 14:23:09 +0200 Subject: [PATCH 09/15] I added | json to monit.modules and monit.mail_alert to catch breaking characters --- monit/config.sls | 7 ++++--- monit/defaults.yaml | 1 + monit/files/mail | 2 +- monit/files/modules | 35 ----------------------------------- monit/files/monitrc | 2 +- 5 files changed, 7 insertions(+), 40 deletions(-) diff --git a/monit/config.sls b/monit/config.sls index 0d6b6d0..88fe933 100644 --- a/monit/config.sls +++ b/monit/config.sls @@ -9,7 +9,8 @@ - mode: '0700' - context: config_includes: {{ monit.config_includes }} - http_access: {{ monit.http_access }} + http_access: {{ monit.http_access | tojson }} + daemon_check: {{ monit.daemon_check }} {#- This is the mail alert configuration #} {% if monit.mail_alert is defined %} @@ -19,7 +20,7 @@ - template: jinja - makedirs: True - context: - mail_alert: {{ monit.mail_alert }} + mail_alert: {{ monit.mail_alert | tojson }} {% endif %} {#- This is populated by modules configuration @@ -29,4 +30,4 @@ - source: salt://monit/files/modules - template: jinja - context: - modules: {{ monit.modules }} + modules: {{ monit.modules | tojson }} diff --git a/monit/defaults.yaml b/monit/defaults.yaml index 85172c5..e2ebde7 100644 --- a/monit/defaults.yaml +++ b/monit/defaults.yaml @@ -4,6 +4,7 @@ monit: pkg: monit config: '/etc/monit/monitrc' config_includes: '/etc/monit/conf.d' + daemon_check: 10 service: name: monit http_access: diff --git a/monit/files/mail b/monit/files/mail index bf04482..89a3848 100644 --- a/monit/files/mail +++ b/monit/files/mail @@ -2,7 +2,7 @@ set alert {{email}} ON { invalid, timeout, resource, size, timestamp } {% endfor %} -{%- if mail_alert.account.email and mail_alert.account.password -%} +{%- if mail_alert.account.email is defined and mail_alert.account.password is defined -%} set mail-format { from: {{mail_alert.get('send_as', mail_alert.account.email)}} } {%- endif -%} diff --git a/monit/files/modules b/monit/files/modules index ea0c0cd..aa9a895 100644 --- a/monit/files/modules +++ b/monit/files/modules @@ -1,50 +1,17 @@ -# -*- coding: utf-8 -*- -# vim: ft=jinja - -{#- This sequence of loops is a bit harder to mantain. So in order - to make it a bit easier, the comments are following the example - below line by line. - - modules: - nginx_init: - process: - custom: - name: nginx - with: - pidfile: /var/run/nginx.pid - config: - group: www - start: "/etc/init.d/nginx start" - stop: "/etc/init.d/nginx stop" - if: - failed: 127.0.0.1 port 80 protocol http - action: restart --#} -{#- module = nginx_init, - module_v = {'process': {'with': {'pidfile':... #} {%- for module, module_v in modules.iteritems() -%} - {#- mod_name = process - mod_name_v = {'custom': {'name': 'nginx'}, 'with': {'pidfile':... #} {%- for mod_name, mod_name_v in module_v.iteritems() -%} - {#- if {'custom': {'name':... exist, this is our 'name'. - otherwise 'name' is the value of 'module' #} {%- if mod_name_v.has_key('custom') %} {%- set name = mod_name_v.custom.name %} {% else %} {%- set name = module %} {%- endif -%} - {#- kind = with, config and if - kind_v = {'pidfile':'/var/run/pid'}, {'group': 'www', etc. #} {%- for kind, kind_v in mod_name_v.iteritems() -%} - {#- element = pidfile, group, start, stop, etc. - element_v = /var/run/nginx.pid, www, "/etc/init.d/nginx start", etc. #} {%- for element, element_v in kind_v.iteritems() -%} - {#- if it has 'pidfile' or 'path' then this is the 'check' line #} {%- if 'pidfile' in kind_v or 'path' in kind_v %} check {{ mod_name }} {{ name }} with {{ element }} {{ element_v }} {%- endif -%} @@ -56,7 +23,6 @@ check {{ mod_name }} {{ name }} with {{ element }} {{ element_v }} {#- 'config' is the lines containing 'group', 'start program', etc #} {%- if 'config' in kind -%} - {#- filter 'start' to add 'program =' into this line #} {%- if 'start' in element or 'stop' in element %} {{ element }} program = "{{ element_v }}" {%- else %} @@ -64,7 +30,6 @@ check {{ mod_name }} {{ name }} with {{ element }} {{ element_v }} {%- endif %} {%- endif -%} - {#- if filter 'if' line #} {%- if 'if' in kind -%} {#- 'action' is appended to the 'if failed' line #} diff --git a/monit/files/monitrc b/monit/files/monitrc index 0440002..ac16b7b 100644 --- a/monit/files/monitrc +++ b/monit/files/monitrc @@ -1,4 +1,4 @@ -set daemon 10 +set daemon {{ daemon_check }} set httpd port {{ http_access.port }} and use address {{ http_access.bind }} From 0a59e41eca6c43dfe7545d712c20f62035961368 Mon Sep 17 00:00:00 2001 From: Wayne Gemmell Date: Tue, 2 Apr 2019 10:09:59 +0200 Subject: [PATCH 10/15] tojson changed to json for backwards compatibility --- monit/config.sls | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/monit/config.sls b/monit/config.sls index 88fe933..dbfa518 100644 --- a/monit/config.sls +++ b/monit/config.sls @@ -9,7 +9,7 @@ - mode: '0700' - context: config_includes: {{ monit.config_includes }} - http_access: {{ monit.http_access | tojson }} + http_access: {{ monit.http_access | json }} daemon_check: {{ monit.daemon_check }} {#- This is the mail alert configuration #} @@ -20,7 +20,7 @@ - template: jinja - makedirs: True - context: - mail_alert: {{ monit.mail_alert | tojson }} + mail_alert: {{ monit.mail_alert | json }} {% endif %} {#- This is populated by modules configuration @@ -30,4 +30,4 @@ - source: salt://monit/files/modules - template: jinja - context: - modules: {{ monit.modules | tojson }} + modules: {{ monit.modules | json }} From 698b2b94e5a693e3191bd87cf8bada826a50c279 Mon Sep 17 00:00:00 2001 From: Wayne Gemmell Date: Tue, 2 Apr 2019 13:12:26 +0200 Subject: [PATCH 11/15] tojson changed to json for backwards compatibility --- monit/config.sls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monit/config.sls b/monit/config.sls index dbfa518..47575ad 100644 --- a/monit/config.sls +++ b/monit/config.sls @@ -8,7 +8,7 @@ - makedirs: True - mode: '0700' - context: - config_includes: {{ monit.config_includes }} + config_includes: {{ monit.config_includes | json }} http_access: {{ monit.http_access | json }} daemon_check: {{ monit.daemon_check }} From 349d6a28287e7801ce7cfeff9b61e596a6db7a1c Mon Sep 17 00:00:00 2001 From: Wayne Gemmell Date: Wed, 3 Apr 2019 15:38:56 +0200 Subject: [PATCH 12/15] VIM tag readded --- monit/files/modules | 2 ++ 1 file changed, 2 insertions(+) diff --git a/monit/files/modules b/monit/files/modules index aa9a895..7178133 100644 --- a/monit/files/modules +++ b/monit/files/modules @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# vim: ft=jinja {%- for module, module_v in modules.iteritems() -%} {%- for mod_name, mod_name_v in module_v.iteritems() -%} From d9d531759f60c64af681954964146e43be06f607 Mon Sep 17 00:00:00 2001 From: Wayne Gemmell Date: Wed, 3 Apr 2019 15:48:13 +0200 Subject: [PATCH 13/15] Re-added comments. I'm not sure where they went. --- monit/files/modules | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/monit/files/modules b/monit/files/modules index 7178133..a61d9da 100644 --- a/monit/files/modules +++ b/monit/files/modules @@ -1,19 +1,48 @@ # -*- coding: utf-8 -*- # vim: ft=jinja + +{#- This sequence of loops is a bit harder to mantain. So in order + to make it a bit easier, the comments are following the example + below line by line. + + modules: + nginx_init: + process: + custom: + name: nginx + with: + pidfile: /var/run/nginx.pid + config: + group: www + start: "/etc/init.d/nginx start" + stop: "/etc/init.d/nginx stop" + if: + failed: 127.0.0.1 port 80 protocol http + action: restart +-#} +{#- module = nginx_init, + module_v = {'process': {'with': {'pidfile':... #} {%- for module, module_v in modules.iteritems() -%} + {#- mod_name = process + mod_name_v = {'custom': {'name': 'nginx'}, 'with': {'pidfile':... #} {%- for mod_name, mod_name_v in module_v.iteritems() -%} + {#- if {'custom': {'name':... exist, this is our 'name'. + otherwise 'name' is the value of 'module' #} {%- if mod_name_v.has_key('custom') %} {%- set name = mod_name_v.custom.name %} {% else %} {%- set name = module %} {%- endif -%} + {#- kind = with, config and if + kind_v = {'pidfile':'/var/run/pid'}, {'group': 'www', etc. #} {%- for kind, kind_v in mod_name_v.iteritems() -%} {%- for element, element_v in kind_v.iteritems() -%} + {#- if it has 'pidfile' or 'path' then this is the 'check' line #} {%- if 'pidfile' in kind_v or 'path' in kind_v %} check {{ mod_name }} {{ name }} with {{ element }} {{ element_v }} {%- endif -%} @@ -25,6 +54,7 @@ check {{ mod_name }} {{ name }} with {{ element }} {{ element_v }} {#- 'config' is the lines containing 'group', 'start program', etc #} {%- if 'config' in kind -%} + {#- filter 'start' to add 'program =' into this line #} {%- if 'start' in element or 'stop' in element %} {{ element }} program = "{{ element_v }}" {%- else %} @@ -32,6 +62,7 @@ check {{ mod_name }} {{ name }} with {{ element }} {{ element_v }} {%- endif %} {%- endif -%} + {#- if filter 'if' line #} {%- if 'if' in kind -%} {#- 'action' is appended to the 'if failed' line #} From 3009e6295dfc07c165080fd7fe8e8f255db656fd Mon Sep 17 00:00:00 2001 From: Wayne Gemmell Date: Wed, 3 Apr 2019 15:49:42 +0200 Subject: [PATCH 14/15] More comments to readd --- monit/files/modules | 2 ++ 1 file changed, 2 insertions(+) diff --git a/monit/files/modules b/monit/files/modules index a61d9da..ea0c0cd 100644 --- a/monit/files/modules +++ b/monit/files/modules @@ -40,6 +40,8 @@ kind_v = {'pidfile':'/var/run/pid'}, {'group': 'www', etc. #} {%- for kind, kind_v in mod_name_v.iteritems() -%} + {#- element = pidfile, group, start, stop, etc. + element_v = /var/run/nginx.pid, www, "/etc/init.d/nginx start", etc. #} {%- for element, element_v in kind_v.iteritems() -%} {#- if it has 'pidfile' or 'path' then this is the 'check' line #} From 6a5804fef643091c3e8f0562d83ea9153fedecab Mon Sep 17 00:00:00 2001 From: Wayne Gemmell Date: Wed, 3 Apr 2019 16:06:18 +0200 Subject: [PATCH 15/15] iteritems changed to items --- monit/files/modules | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/monit/files/modules b/monit/files/modules index ea0c0cd..552eaf5 100644 --- a/monit/files/modules +++ b/monit/files/modules @@ -22,11 +22,11 @@ -#} {#- module = nginx_init, module_v = {'process': {'with': {'pidfile':... #} -{%- for module, module_v in modules.iteritems() -%} +{%- for module, module_v in modules.items() -%} {#- mod_name = process mod_name_v = {'custom': {'name': 'nginx'}, 'with': {'pidfile':... #} - {%- for mod_name, mod_name_v in module_v.iteritems() -%} + {%- for mod_name, mod_name_v in module_v.items() -%} {#- if {'custom': {'name':... exist, this is our 'name'. otherwise 'name' is the value of 'module' #} @@ -38,11 +38,11 @@ {#- kind = with, config and if kind_v = {'pidfile':'/var/run/pid'}, {'group': 'www', etc. #} - {%- for kind, kind_v in mod_name_v.iteritems() -%} + {%- for kind, kind_v in mod_name_v.items() -%} {#- element = pidfile, group, start, stop, etc. element_v = /var/run/nginx.pid, www, "/etc/init.d/nginx start", etc. #} - {%- for element, element_v in kind_v.iteritems() -%} + {%- for element, element_v in kind_v.items() -%} {#- if it has 'pidfile' or 'path' then this is the 'check' line #} {%- if 'pidfile' in kind_v or 'path' in kind_v %} @@ -50,8 +50,8 @@ check {{ mod_name }} {{ name }} with {{ element }} {{ element_v }} {%- endif -%} {% endfor %} {% endfor %} - {%- for kind, kind_v in mod_name_v.iteritems() -%} - {%- for element, element_v in kind_v.iteritems() -%} + {%- for kind, kind_v in mod_name_v.items() -%} + {%- for element, element_v in kind_v.items() -%} {#- 'config' is the lines containing 'group', 'start program', etc #} {%- if 'config' in kind -%}