|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- {%- 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 }}
- {#- Check string values, the more common #}
- {%- elif value is string %}
- {{ key }} = "{{ value }}"
- {%- endif %}
- {%- endmacro %}
-
- {%- macro printconfig(type, object, name, config, applyto="", applymethod="")%}
- {%- if applymethod == "to" %}
- {{ type }} {{ object }} "{{ name }}" to {{ applyto }} {
- {%- elif applymethod == "for" %}
- {{ type }} {{ object }} for {{ applyto }} {
- {%- elif object == "Host" and type != "template" %}
- {{ type }} {{ object }} {{ name }} {
- {%- else %}
- {{ type }} {{ object }} "{{ name }}" {
- {%- endif %}
- {%- if config is defined %}
- {#- Check import first to be the first line on config blocks #}
- {%- for key, value in config.items() %}
- {%- if key == "import" %}
- {{key}} "{{ value }}"
- {%- endif %}
- {%- endfor %}
- {%- for key, value in config.items() if key != "import" -%}
- {{ printassign(key, value) }}
- {#- Handle vars values that can be a dict, list or value #}
- {%- if key == "vars" %}
- {%- for varkey, varvalue in config.vars.items() %}
- {%- if varvalue is mapping %}
- {%- for k, v in varvalue.items() %}
- vars.{{ varkey }}["{{ k }}"] = {
- {%- if v is not none %}
- {%- for k1, v1 in v.items() -%}
- {{ printassign(k1, v1)|indent(2)}}
- {%- endfor %}
- {%- endif %}
- }
- {%- endfor %}
- {%- else -%}
- {{ printassign("vars." + varkey, varvalue) }}
- {%- endif %}
- {%- endfor %}
- {#- Handle dict values mapping dict type on yaml with icinga2 syntax #}
- {%- elif value is mapping %}
- {{ key }} = {
- {%- for k, v in value.items() -%}
- {{ printassign(k, v)|indent(2) }}
- {%- endfor %}
- }
- {#- Special case for assign and ignore #}
- {%- elif key in ["assign", "ignore"] %}
- {%- for item in value %}
- {{ key }} where {{ item }}
- {%- endfor %}
- {#- Handle lists values mapping list type on yaml with icinga2 syntax #}
- {%- elif value is iterable and not value is string %}
- {{ key }} = [ {{ value|join(",") }} ]
- {%- endif %}
- {%- endfor %}
- {#- Add a line to aggregate variables read from dictionary #}
- {%- if applymethod == "for" %}
- vars += config
- {%- endif %}
- {%- endif %}
- }
- {%- endmacro %}
|