Browse Source

Adjust syntax for boolean values on config. Remove slack from defaults

master
Ricardo Hernandez 8 years ago
parent
commit
43a815be08
2 changed files with 12 additions and 18 deletions
  1. +0
    -1
      icinga2/defaults.yaml
  2. +12
    -17
      icinga2/macros.jinja

+ 0
- 1
icinga2/defaults.yaml View File

os: Linux os: Linux
disk_wfree: 15% disk_wfree: 15%
ssh_port: 22 ssh_port: 22
notification.slack: "true"
http_vhosts: http_vhosts:
Icinga web 2: Icinga web 2:
http_uri: /icingaweb2 http_uri: /icingaweb2

+ 12
- 17
icinga2/macros.jinja View File

{% macro printassign(key, value) %}
{%- if value is number or "vars" in value %}
{%- macro printassign(key, value) %}
{#- Check values like: 3, 25, 3s, 45m, 8d #}
{%- if value is number or "vars" in value or value in ["false","true"] or key in ["check_interval", "retry_interval"] %}
{{ key }} = {{ value }} {{ key }} = {{ value }}
{#- Check string values, the more common #}
{%- elif value is string %} {%- elif value is string %}
{{ key }} = "{{ value }}" {{ key }} = "{{ value }}"
{%- endif %} {%- endif %}
{% endmacro %}
{%- endmacro %}


{%- macro printconfig(type, object, name, config, applyto="", applymethod="")%} {%- macro printconfig(type, object, name, config, applyto="", applymethod="")%}
{%- if applymethod == "to" %} {%- if applymethod == "to" %}
{{key}} "{{ value }}" {{key}} "{{ value }}"
{%- endif %} {%- endif %}
{%- endfor %} {%- endfor %}
{%- for key, value in config.items() if key != "import" %}
{#- Check values like: 3, 25, 3s, 45m, 8d #}
{%- if value is number or key in ["check_interval", "retry_interval"] %}
{{ key }} = {{ value }}
{#- Check string values, the more common #}
{%- elif value is string %}
{{ key }} = "{{ value }}"
{%- for key, value in config.items() if key != "import" -%}
{{ printassign(key, value) }}
{#- Handle vars values that can be a dict, list or value #} {#- Handle vars values that can be a dict, list or value #}
{%- elif key == "vars" %}
{%- if key == "vars" %}
{%- for varkey, varvalue in config.vars.items() %} {%- for varkey, varvalue in config.vars.items() %}
{%- if varvalue is mapping %} {%- if varvalue is mapping %}
{%- for k, v in varvalue.items() %} {%- for k, v in varvalue.items() %}
vars.{{ varkey }}["{{ k }}"] = { vars.{{ varkey }}["{{ k }}"] = {
{%- if v is not none %} {%- if v is not none %}
{%- for k1, v1 in v.items() -%} {%- for k1, v1 in v.items() -%}
{{ printassign(k1, v1)|indent(4)}}
{{ printassign(k1, v1)|indent(2)}}
{%- endfor %} {%- endfor %}
{%- endif %} {%- endif %}
} }
{%- endfor %} {%- endfor %}
{%- elif varvalue is number %}
vars.{{ varkey }} = {{ varvalue }}
{%- else %}
vars.{{ varkey }} = "{{ varvalue }}"
{%- else -%}
{{ printassign("vars." + varkey, varvalue) }}
{%- endif %} {%- endif %}
{%- endfor %} {%- endfor %}
{#- Handle dict values mapping dict type on yaml with icinga2 syntax #} {#- Handle dict values mapping dict type on yaml with icinga2 syntax #}
{{ key }} where {{ item }} {{ key }} where {{ item }}
{%- endfor %} {%- endfor %}
{#- Handle lists values mapping list type on yaml with icinga2 syntax #} {#- Handle lists values mapping list type on yaml with icinga2 syntax #}
{%- elif value is iterable %}
{%- elif value is iterable and not value is string %}
{{ key }} = [ {{ value|join(",") }} ] {{ key }} = [ {{ value|join(",") }} ]
{%- endif %} {%- endif %}
{%- endfor %} {%- endfor %}

Loading…
Cancel
Save