To programmatically extract numerical data points (current values) and thresholds from standard alarm messages and populate them into the custom_1 and custom_2 fields of the alarm XML for enhanced reporting and integration.
Create a new script named enrich_custom_fields and paste the following code:
if event ~= nil and event.message ~= nil then
-- 1. Extract the current value (the number before the first %)
local val = string.match(event.message, "is now%s+([%d%.]+)%%")
-- 2. Extract the limit threshold (the number inside the parentheses before %)
local lim = string.match(event.message, "threshold%s+%(([%d%.]+)%%%)")
-- 3. If the pattern changes slightly, use a generic backup pattern to capture two numbers
if not val or not lim then
val, lim = string.match(event.message, "is now%s+([%d%.]+).-[%(%s]([%d%.]+)%%")
end
-- 4. If values were found, assign them to the custom fields
if val then
event.custom_1 = val
end
if lim then
event.custom_2 = lim
end
end
-- Return the updated event back to nas
return event
populate_custom_data).custom.enrich_custom_fields from the Script dropdown.cdm or use a Message Filter like /*is now*threshold*/).Example output: