Skip to content

Commit

Permalink
Allow to set other settings and import map inside templates
Browse files Browse the repository at this point in the history
  • Loading branch information
amontalban committed Jan 30, 2017
1 parent c61a754 commit 3cadbf1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
7 changes: 0 additions & 7 deletions monit/config.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand All @@ -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
Expand All @@ -35,5 +30,3 @@
- makedirs: True
- watch_in:
- service: {{ monit.service.name }}
- context:
modules: {{ monit.modules }}
2 changes: 2 additions & 0 deletions monit/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions monit/files/mail
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 5 additions & 2 deletions monit/files/modules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{%- from "monit/map.jinja" import monit with context -%}
# -*- coding: utf-8 -*-
# vim: ft=jinja

Expand All @@ -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':... #}
Expand All @@ -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 -%}
Expand All @@ -70,7 +71,9 @@ check {{ mod_name|replace('\\n', '\n') }} {{ name|replace('\\n', '\n') }} with {
{#- 'action' is appended to the 'if failed' line #}
{%- if 'action' not in element %}
if {{ element|replace('\\n', '\n') }}
{%- if element_v is not none %}
{{ element_v|replace('\\n', '\n')| indent(4) }}
{%- endif %}
then {{ kind_v.action|replace('\\n', '\n') }}
{%- endif %}
{%- endif %}
Expand Down
14 changes: 8 additions & 6 deletions monit/files/monitrc
Original file line number Diff line number Diff line change
@@ -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 }}/*

0 comments on commit 3cadbf1

Please sign in to comment.