From 5ba3c7a539f1224f2e938a6f11cd7236dd87a4e8 Mon Sep 17 00:00:00 2001 From: Andres Montalban Date: Fri, 27 Jan 2017 15:12:48 -0300 Subject: [PATCH] Allow to set other settings and import map inside templates --- monit/config.sls | 7 ------- monit/defaults.yaml | 2 ++ monit/files/mail | 17 +++++++++-------- monit/files/modules | 5 +++-- monit/files/monitrc | 14 ++++++++------ 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/monit/config.sls b/monit/config.sls index 486e52c..4590b19 100644 --- a/monit/config.sls +++ b/monit/config.sls @@ -9,9 +9,6 @@ - mode: '0700' - watch_in: - service: {{ monit.service.name }} - - context: - config_includes: {{ monit.config_includes }} - http_access: {{ monit.http_access }} {#- This is the mail alert configuration #} {% if monit.mail_alert is defined %} @@ -22,8 +19,6 @@ - makedirs: True - watch_in: - service: {{ monit.service.name }} - - context: - mail_alert: {{ monit.mail_alert }} {% endif %} {#- This is populated by modules configuration @@ -35,5 +30,3 @@ - makedirs: True - watch_in: - service: {{ monit.service.name }} - - context: - modules: {{ monit.modules }} diff --git a/monit/defaults.yaml b/monit/defaults.yaml index 85172c5..a7b4f6d 100644 --- a/monit/defaults.yaml +++ b/monit/defaults.yaml @@ -6,6 +6,8 @@ monit: config_includes: '/etc/monit/conf.d' service: name: monit + daemon_interval: 10 + logfile: syslog http_access: port: 2812 bind: 127.0.0.1 diff --git a/monit/files/mail b/monit/files/mail index ae53046..77ecd02 100644 --- a/monit/files/mail +++ b/monit/files/mail @@ -1,15 +1,16 @@ -{%- for email in mail_alert.users -%} -set alert {{email}} ON { invalid, timeout, resource, size, timestamp } +{%- from "monit/map.jinja" import monit with context -%} +{%- for email in monit.mail_alert.users -%} +set alert {{ email }} ON { invalid, timeout, resource, size, timestamp } {% endfor %} -{%- if mail_alert.account.email -%} -set mail-format { from: {{mail_alert.account.email}} } +{%- if monit.mail_alert.account.email -%} +set mail-format { from: {{ monit.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 %} - username "{{mail_alert.account.email}}" password "{{mail_alert.account.password}}" +{%- if monit.mail_alert.account.server and monit.mail_alert.account.port %} +set mailserver {{ monit.mail_alert.account.server }} port {{ monit.mail_alert.account.port }} + {%- if monit.mail_alert.account.email and 'password' in monit.mail_alert.account and monit.mail_alert.account.password %} + username "{{ monit.mail_alert.account.email }}" password "{{ monit.mail_alert.account.password }}" using tlsv1 {%- endif %} with timeout 30 seconds diff --git a/monit/files/modules b/monit/files/modules index c87474f..a49deca 100644 --- a/monit/files/modules +++ b/monit/files/modules @@ -1,3 +1,4 @@ +{%- from "monit/map.jinja" import monit with context -%} # -*- coding: utf-8 -*- # vim: ft=jinja @@ -22,7 +23,7 @@ -#} {#- module = nginx_init, module_v = {'process': {'with': {'pidfile':... #} -{%- for module, module_v in modules.iteritems() -%} +{%- for module, module_v in monit.modules.iteritems() -%} {#- mod_name = process mod_name_v = {'custom': {'name': 'nginx'}, 'with': {'pidfile':... #} @@ -46,7 +47,7 @@ {#- 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|replace('\\n', '\n') }} {{ name|replace('\\n', '\n') }} with {{ element|replace('\\n', '\n') }} {{ element_v|replace('\\n', '\n') }} +check {{ mod_name|replace('\\n', '\n') }} {{ name|replace('\\n', '\n') }} with {{ element|replace('\\n', '\n') }} "{{ element_v|replace('\\n', '\n') }}" {%- endif -%} {%- endfor -%} {%- endfor -%} diff --git a/monit/files/monitrc b/monit/files/monitrc index 0440002..29b2b12 100644 --- a/monit/files/monitrc +++ b/monit/files/monitrc @@ -1,12 +1,14 @@ -set daemon 10 +{%- from "monit/map.jinja" import monit with context -%} +set daemon {{ monit.daemon_interval }} +set logfile {{ monit.logfile }} -set httpd port {{ http_access.port }} and - use address {{ http_access.bind }} -{%- for host in http_access.allowed.hosts %} +set httpd port {{ monit.http_access.port }} and + use address {{ monit.http_access.bind }} +{%- for host in monit.http_access.allowed.hosts %} allow {{ host }} {%- endfor %} -{%- for userdata in http_access.allowed.users %} +{%- for userdata in monit.http_access.allowed.users %} allow {{ userdata[0] }}:{{ userdata[1] }} {%- endfor %} -include {{ config_includes }}/* +include {{ monit.config_includes }}/*