def filter_service_by_hostgroup_name(group):
    """Filter for service
    Filter on hostgroup

    :param group: hostgroup to filter
    :type group: str
    :return: Filter
    :rtype: bool
    """

    def inner_filter(items):
        """Inner filter for service. Accept if hostgroup in service.host.hostgroups"""
        service = items["service"]
        host = items["hosts"][service.host]
        if service is None or host is None:
            return False
        return group in [items["hostgroups"][g].hostgroup_name for g in host.hostgroups]

    return inner_filter