import re


def parse_fst_iface_event(ev):
    """Parses FST iface event that comes as a string, e.g.
    "<3>FST-EVENT-IFACE attached ifname=wlan9 group=fstg0"
    Returns a dictionary with parsed "event_type", "ifname", and "group"; or
    None if not an FST event or can't be parsed."""
    event = {}
    if ev.find("FST-EVENT-IFACE") == -1:
        return None
    if ev.find("attached") != -1:
        event['event_type'] = 'attached'
    elif ev.find("detached") != -1:
        event['event_type'] = 'detached'
    else:
        return None
    f = re.search("ifname=(\S+)", ev)
    if f is not None:
        event['ifname'] = f.group(1)
    f = re.search("group=(\S+)", ev)
    if f is not None:
        event['group'] = f.group(1)
    return event