Merge pull request #106 from SwannCroiset/nagios-host-env
Nagios host env
diff --git a/heka/files/lua/encoders/status_nagios.lua b/heka/files/lua/encoders/status_nagios.lua
index 9957f70..bf3b9aa 100644
--- a/heka/files/lua/encoders/status_nagios.lua
+++ b/heka/files/lua/encoders/status_nagios.lua
@@ -19,9 +19,17 @@
local lma = require 'lma_utils'
local interp = require "msg_interpolate"
+local host_suffix_dimension_field
+if read_config('host_suffix_dimension_key') then
+ host_suffix_dimension_field = string.format('Fields[%s]', read_config('host_suffix_dimension_key'))
+end
+
-- These 2 configurations are used only to encode GSE messages
local default_host = read_config('default_nagios_host')
-local host_dimension_key = read_config('nagios_host_dimension_key')
+local host_dimension_field
+if read_config('nagios_host_dimension_key') then
+ host_dimension_field = string.format('Fields[%s]', read_config('nagios_host_dimension_key'))
+end
-- Nagios CGI cannot accept 'plugin_output' parameter greater than 1024 bytes
-- See bug #1517917 for details.
@@ -64,12 +72,21 @@
return -1
end
- if host_dimension_key then
- data['host'] = read_message(string.format('Fields[%s]', host_dimension_key)) or default_host
+ local host
+ if host_dimension_field then
+ host = read_message(host_dimension_field) or default_host
else
- data['host'] = read_message('Fields[hostname]') or read_message('Hostname')
+ host = read_message('Fields[hostname]') or read_message('Hostname')
end
+ if host_suffix_dimension_field then
+ local suffix = read_message(host_suffix_dimension_field)
+ if suffix then
+ host = host .. '.' .. suffix
+ end
+ end
+ data['host'] = host
+
data['service'] = service_name
data['plugin_state'] = nagios_state_map[status]
diff --git a/heka/meta/heka.yml b/heka/meta/heka.yml
index d9df152..c37929c 100644
--- a/heka/meta/heka.yml
+++ b/heka/meta/heka.yml
@@ -103,7 +103,8 @@
engine: sandbox
module_file: /usr/share/lma_collector/encoders/status_nagios.lua
module_dir: /usr/share/lma_collector/common;/usr/share/heka/lua_modules
- {%- endif %}
+ config:
+ host_suffix_dimension_key: environment_label
{%- endif %}
{%- if metric_collector.influxdb_host is defined or metric_collector.aggregator_host is defined or metric_collector.nagios_host is defined %}
output:
@@ -439,6 +440,7 @@
module_file: /usr/share/lma_collector/encoders/status_nagios.lua
module_dir: /usr/share/lma_collector/common;/usr/share/heka/lua_modules
config:
+ host_suffix_dimension_key: environment_label
default_nagios_host: "{{ aggregator.nagios_default_host_alarm_clusters }}"
{%- if aggregator.nagios_host_dimension_key is defined %}
nagios_host_dimension_key: "{{ aggregator.nagios_host_dimension_key }}"
diff --git a/heka/server.sls b/heka/server.sls
index c2de1a0..888f04c 100644
--- a/heka/server.sls
+++ b/heka/server.sls
@@ -1,5 +1,5 @@
{%- from "heka/map.jinja" import server with context %}
-{%- if server.enabled %}
+{%- if server.enabled is defined and server.enabled %}
heka_packages:
pkg.latest:
@@ -198,4 +198,4 @@
{%- endif %}
{%- endfor %}
-{%- endif %}
\ No newline at end of file
+{%- endif %}