'Convert a set of fields to one or multiple Trait values.
This method is called each time a trait is attempted to be extracted
from a notification. It will be called *even if* no matching fields
are found in the notification (in that case, the match_list will be
empty). If this method returns None, the trait *will not* be added to
the event. Any other value returned by this method will be used as
the value for the trait. Values returned will be coerced to the
appropriate type for the trait.
:param match_list: A list (may be empty if no matches) of *tuples*.
Each tuple is (field_path, value) where field_path is the jsonpath
for that specific field.
Example::
trait\'s fields definition: [\'payload.foobar\',
\'payload.baz\',
\'payload.thing.*\']
notification body:
\'metadata\': {\'message_id\': \'12345\'},
\'publisher\': \'someservice.host\',
\'payload\': {
\'foobar\': \'test\',
\'thing\': {
\'bar\': 12,
\'boing\': 13,
match_list will be: [(\'payload.foobar\',\'test\'),
(\'payload.thing.bar\',12),
(\'payload.thing.boing\',13)]
Here is a plugin that emulates the default (no plugin) behavior:
.. code-block:: python
class DefaultPlugin(TraitPluginBase):
"Plugin that returns the first field value."
def __init__(self, **kw):
super(DefaultPlugin, self).__init__()
def trait_value(self, match_list):
if not match_list:
return None
return [ match[1] for match in match_list]'

def trait_values(self, match_list):

    return [self.trait_value(match_list)]
