Displays - dhoelzer/DAD GitHub Wiki

Previously, DAD allowed you to define up to two key fields and positions that could be used to identify a specific type of event and to then select the fields (and the order) that you would want to display for those events along with explanatory text. This has been completely revised!

The previous arrangement, while powerful, was also extremely non-portable. Not only would it be difficult to share your event interpretations with another DAD installation, but if your events were parsed even slightly differently the displays would not work at all since everything was keyed based on field positions. The new approach solves this problem.

When defining a display now you simply define a regular expression that will be used to match events and pass them to a custom display parser. Within the "Script" window you must then define a function parse_event, that takes the complete event text as an argument. What you return will be used as the display in all event output for all matching events. An example script is below:

def parse_event(event_text)
  regex = /.* postfix.* \[ [0-9]+ \] : (?<message_id>[^ ]+) to = < (?<recipient>[^ ]+) >.* relay = (?<relay>[^ ]+) .*status = (?<status>.*)$/
  fields = event_text.match(regex)
  if !fields.nil?
    return "Email ID #{fields['message_id']} to #{fields['recipient']} was handled by #{fields['relay']} relay - Status: #{fields['status']}"
  end
  regex = /.* [0-9][0-9]:[0-9][0-9]:[0-9][0-9] (?<unprocessed>.* postfix.*)$/
  fields = event_text.match(regex)
  return "**NO MATCH!** #{event_text}" if fields.nil?
  return "**UNMATCHED DISPLAY** #{fields['unprocessed']}"
end

The real beauty of this arrangement is that it is very flexible. The display above handles a very specific type of Postfix message. As you are likely aware, however, Postfix generates many different types of messages. Note the "UNMATCHED DISPLAY" that is returned toward the end. While this is simply a reminder for me, I hope that you can see that you can easily define multiple regular expressions that could be used to parse the many different Postfix messages that occur and render each in a different way.

As was true previously, events that do not trigger a display filter will continue to render normally.

⚠️ **GitHub.com Fallback** ⚠️