Check if current number of sessions of a server for a specific haproxy backend
    is over a defined threshold.

    .. code-block:: yaml

        beacons:
          haproxy:
            - backends:
                www-backend:
                    threshold: 45
                    servers:
                      - web1
                      - web2
            - interval: 120

def beacon(config):
    '''
    Check if current number of sessions of a server for a specific haproxy backend
    is over a defined threshold.

    .. code-block:: yaml

        beacons:
          haproxy:
            - backends:
                www-backend:
                    threshold: 45
                    servers:
                      - web1
                      - web2
            - interval: 120
    '''
    ret = []

    _config = {}
    list(map(_config.update, config))

    for backend in _config.get('backends', ()):
        backend_config = _config['backends'][backend]
        threshold = backend_config['threshold']
        for server in backend_config['servers']:
            scur = __salt__['haproxy.get_sessions'](server, backend)
            if scur:
                if int(scur) > int(threshold):
                    _server = {'server': server,
                               'scur': scur,
                               'threshold': threshold,
                               }
                    log.debug('Emit because %s > %s'
                              ' for %s in %s', scur,
                                               threshold,
                                               server,
                                               backend)
                    ret.append(_server)
    return ret