import requests


def get_alert(service, resource):
    """
    Get an entry from alerta
    :param service: alerta service
    :param resource: unique resource id of required entry
    :return: dict
    """
    resp = requests.get(service.data['url'] + "/alerts",
                        params={'environment': service.data['envName'], 'resource': resource},
                        headers=service.headers)

    if resp.status_code != 200:
        service.logger.info("Couldn't get data from alerta server, error code was %s" % resp.status_code)
    elif resp.json()['alerts']:
        alert = resp.json()['alerts'][0]
        if alert['status'] in ['open', 'ack']:
            return alert