From 1253b8c1db0fc01d25e13ccdfaac079b4fd7b833 Mon Sep 17 00:00:00 2001 From: Mark Stemm Date: Mon, 28 Nov 2016 16:20:59 -0800 Subject: [PATCH] Handle lua patterns. % requires escaping. --- userspace/engine/lua/rule_loader.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/userspace/engine/lua/rule_loader.lua b/userspace/engine/lua/rule_loader.lua index 284332c381c..174bfd18e9e 100644 --- a/userspace/engine/lua/rule_loader.lua +++ b/userspace/engine/lua/rule_loader.lua @@ -261,14 +261,19 @@ function load_rules(rules_content, rules_mgr, verbose, all_events, extra, replac -- If the format string contains %container.info, replace it -- with extra. Otherwise, add extra onto the end of the format -- string. - if string.find(v['output'], "%container.info") ~= nil then + if string.find(v['output'], "%container.info", nil, true) ~= nil then + -- There may not be any extra, or we're not supposed -- to replace it, in which case we use the generic -- "%container.name (id=%container.id)" - if extra == "" or replace_container_info == false then - v['output'] = string.gsub(v['output'], "%container.info", "%container.name (id=%container.id)") + if replace_container_info == false then + v['output'] = string.gsub(v['output'], "%%container.info", "%%container.name (id=%%container.id)") + if extra ~= "" then + v['output'] = v['output'].." "..extra + end else - v['output'] = string.gsub(v['output'], "%container.info", extra) + safe_extra = string.gsub(extra, "%%", "%%%%") + v['output'] = string.gsub(v['output'], "%%container.info", safe_extra) end else -- Just add the extra to the end