diff --git a/states/haproxy/config.sls b/states/haproxy/config.sls index 5e0b7d2..94e4a8b 100644 --- a/states/haproxy/config.sls +++ b/states/haproxy/config.sls @@ -1,5 +1,29 @@ --- {%- from "haproxy/map.jinja" import haproxy with context %} +{% for filename in haproxy.maps %} +haproxy-maps-{{ filename }}: + file.managed: + - name: {{ haproxy.config.dir }}/maps/{{ filename }} + - source: salt://haproxy/maps/{{ filename }}.j2 + - user: {{ haproxy.config.user }} + - group: {{ haproxy.config.group }} + - mode: "0600" + - template: jinja + - watch_in: + - service: haproxy-service +{% endfor %} + +haproxy-spoe-config: + file.managed: + - name: {{ haproxy.config.dir }}/spoe.cfg + - source: salt://haproxy/spoe/spoe.cfg.j2 + - user: {{ haproxy.config.user }} + - group: {{ haproxy.config.group }} + - mode: "0600" + - template: jinja + - watch_in: + - service: haproxy-service + haproxy-config: file.managed: - name: {{ haproxy.config.dir }}/{{ haproxy.config.configfile }} diff --git a/states/haproxy/defaults.yaml b/states/haproxy/defaults.yaml index 0d35cab..5513a71 100644 --- a/states/haproxy/defaults.yaml +++ b/states/haproxy/defaults.yaml @@ -84,3 +84,4 @@ haproxy: domains: {} vhosts: {} services: {} + spoe: {} diff --git a/states/haproxy/install.sls b/states/haproxy/install.sls index 39dfe48..ea3298a 100644 --- a/states/haproxy/install.sls +++ b/states/haproxy/install.sls @@ -36,16 +36,3 @@ haproxy-script-{{ file.name }}: - watch_in: - service: haproxy-service {% endfor %} - -{% for filename in haproxy.maps %} -haproxy-maps-{{ filename }}: - file.managed: - - name: {{ haproxy.config.dir }}/maps/{{ filename }} - - source: salt://haproxy/maps/{{ filename }}.j2 - - user: {{ haproxy.config.user }} - - group: {{ haproxy.config.group }} - - mode: "0600" - - template: jinja - - watch_in: - - service: haproxy-service -{% endfor %} \ No newline at end of file diff --git a/states/haproxy/templates/haproxy.cfg.j2 b/states/haproxy/templates/haproxy.cfg.j2 index f76d6ae..6b2265e 100644 --- a/states/haproxy/templates/haproxy.cfg.j2 +++ b/states/haproxy/templates/haproxy.cfg.j2 @@ -36,7 +36,7 @@ {%- macro cache() -%} http-request cache-use static if { path_end {{ haproxy.config.cache_file_types|join(" ") }} } - http-response cache-store static + http-response cache-store static {%- endmacro -%} {%- macro compression() -%} @@ -205,6 +205,12 @@ listen {{ name }} {{- tcpendpoints(servers=values.servers, check=values.check|default(haproxy.config.check)) }} {% endfor -%} +# SPOE Agents +{%- for name, values in haproxy.config.spoe.items() %} +listen {{ name }} + bind *:{{ values.port }},:::{{ values.port }} v4v6 +{% endfor -%} + {% if haproxy.config.admin.enable %} {{ admin() }} {%- endif %} diff --git a/states/haproxy/templates/spoe.cfg.j2 b/states/haproxy/templates/spoe.cfg.j2 new file mode 100644 index 0000000..293da0f --- /dev/null +++ b/states/haproxy/templates/spoe.cfg.j2 @@ -0,0 +1,30 @@ +## {{ salt['pillar.get']('salt_managed', default='Salt Managed') }} +{%- from "haproxy/map.jinja" import haproxy with context %} + +{%- for name, values in haproxy.config.spoe.items() %} +[{{ name }}] +spoe-agent {{ name }} + messages {{ " ".join(values.messages.keys()) }} option var-prefix {{ name }} + timeout hello 2s + timeout idle 2m + timeout processing 50ms + use-backend {{ name }} + log global + +{%- for m, m_values in values.messages.items() %} +spoe-message {{ m }} + {%- if m_values.args.keys() > 0 %} + args {{ " ".join([i+"="+v for i, v in m_values.args.items()]) }} + {%- endif %} + {%- if m_values.event %} + event {{ m_values.event }} + {%- endif %} +{% endfor %} + +spoe-message request + args unique_id=unique-id clientip=src host=req.hdr(Host) method=method path=pathq headers=req.hdrs body_size=req.body_size body=req.body + event on-frontend-http-request +spoe-message response + args unique_id=unique-id status=status + event on-http-response +{% endfor -%}