Call once string.format to build host_dimension field
diff --git a/heka/files/lua/encoders/status_nagios.lua b/heka/files/lua/encoders/status_nagios.lua
index dd4d73e..bf3b9aa 100644
--- a/heka/files/lua/encoders/status_nagios.lua
+++ b/heka/files/lua/encoders/status_nagios.lua
@@ -26,7 +26,10 @@
-- 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.
@@ -70,8 +73,8 @@
end
local host
- if host_dimension_key then
- host = read_message(string.format('Fields[%s]', host_dimension_key)) or default_host
+ if host_dimension_field then
+ host = read_message(host_dimension_field) or default_host
else
host = read_message('Fields[hostname]') or read_message('Hostname')
end