Generate the gse_policies Lua module
diff --git a/heka/_service.sls b/heka/_service.sls
index 22ca02a..a571d16 100644
--- a/heka/_service.sls
+++ b/heka/_service.sls
@@ -277,6 +277,22 @@
 
 {%- endfor %}
 
+{%- set policy = service_metadata.get('policy') %}
+{%- if policy %}
+/usr/share/lma_collector/common/gse_policies.lua:
+  file.managed:
+  - source: salt://heka/files/gse_policies.lua
+  - template: jinja
+  - mode: 640
+  - group: heka
+  - require:
+    - file: /usr/share/lma_collector
+  - watch_in:
+    - service: heka_{{ service_name }}_service
+  - defaults:
+    policy: {{ policy|yaml }}
+{%- endif %}
+
 {%- for filter_name, filter in service_metadata.get('filter', {}).iteritems() %}
 
 /etc/{{ service_name }}/filter_{{ filter_name }}.toml:
diff --git a/heka/files/gse_policies.lua b/heka/files/gse_policies.lua
new file mode 100644
index 0000000..8ec9c06
--- /dev/null
+++ b/heka/files/gse_policies.lua
@@ -0,0 +1,55 @@
+-- Copyright 2015-2016 Mirantis, Inc.
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+--     http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+
+local gse_policy = require 'gse_policy'
+
+local M = {}
+setfenv(1, M) -- Remove external access to contain everything in the module
+
+local policies = {
+{%- for _policy_name, _policy in policy|dictsort %}
+    ['{{ _policy_name|replace("'", "\\'") }}'] = {
+    {%- for _policy_rule in _policy %}
+        gse_policy.new({
+            status = '{{ _policy_rule["status"] }}',
+        {%- set _trigger = _policy_rule.get("trigger") %}
+        {%- if _trigger %}
+            trigger = {
+                logical_operator = '{{ _trigger["logical_operator"] }}',
+                rules = {
+            {%- for _rule in _trigger["rules"] %}
+                    ['function'] = '{{ _rule["function"] }}',
+                {%- set comma = joiner(",") %}
+                    ['arguments'] = {
+                {%- for _argument in _rule["arguments"]|sort -%}
+                {{ comma() }}'{{ _argument }}'
+                {%- endfor -%}
+                    },
+                    ['relational_operator'] = '{{ _rule["relational_operator"] }}',
+                    ['threshold'] = {{ _rule["threshold"] }},
+            {%- endfor %}
+                },
+            },
+        {%- endif %}
+        }),
+    {%- endfor %}
+    },
+{%- endfor %}
+}
+
+function find(policy)
+    return policies[policy]
+end
+
+return M