def get_expiring_deployed_certificates(exclude=None):
    """
    Finds all certificates that are eligible for deployed expiring cert notifications. Returns the set of domain/port
    pairs at which each certificate was identified as in use (deployed).

    Sample response:
        defaultdict(<class 'list'>,
            {'testowner2@example.com': [(Certificate(name=certificate100),
                                        defaultdict(<class 'list'>, {'localhost': [65521, 65522, 65523]}))],
            'testowner3@example.com': [(Certificate(name=certificate101),
                                        defaultdict(<class 'list'>, {'localhost': [65521, 65522, 65523]}))]})

    :return: A dictionary with owner as key, and a list of certificates associated with domains/ports.
    """
    certs_domains_and_ports = defaultdict(dict)
    for certificate in get_certs_for_expiring_deployed_cert_check(exclude, None):
        matched_domains = defaultdict(list)
        for cert_association in [assoc for assoc in certificate.certificate_associations if assoc.ports]:
            matched_domains[cert_association.domain.name] = cert_association.ports
        if len(matched_domains) > 0:
            certs_domains_and_ports[certificate] = matched_domains

    certs_domains_and_ports_by_owner = defaultdict(list)
    # group by owner
    for owner, owner_certs in groupby(sorted(certs_domains_and_ports.items(),
                                             key=lambda x: x[0].owner), lambda x: x[0].owner):
        certs_domains_and_ports_by_owner[owner] = list(owner_certs)
    return certs_domains_and_ports_by_owner

    Finds all certificates that are eligible for deployed expiring cert notifications. Returns the set of domain/port
    pairs at which each certificate was identified as in use (deployed).

    Sample response:
        defaultdict(<class 'list'>,
            {'testowner2@example.com': [(Certificate(name=certificate100),
                                        defaultdict(<class 'list'>, {'localhost': [65521, 65522, 65523]}))],
            'testowner3@example.com': [(Certificate(name=certificate101),
                                        defaultdict(<class 'list'>, {'localhost': [65521, 65522, 65523]}))]})

    :return: A dictionary with owner as key, and a list of certificates associated with domains/ports.
    
lemur/certificates/service.py