# Buggy code
def beacon(config):
    """
    Emit the load averages of this host.

    Specify thresholds for each load average
    and only emit a beacon if any of them are
    exceeded.

    .. code-block:: yaml

        beacons:
          - load:
            - 1m:
              - 0.0
              - 2.0
            - 5m:
              - 0.0
              - 1.5
            - 15m:
              - 0.1
              - 1.0

    """
    log.trace("load beacon starting")
    ret = []
    if not os.path.isfile("/proc/loadavg"):
        return ret
    with salt.utils.fopen("/proc/loadavg", "rb") as fp_:
        avgs = fp_.read().split()[:3]
        avg_keys = ["1m", "5m", "15m"]
        avg_dict = dict(zip(avg_keys, avgs))
        # Check each entry for threshold
        if (
            float(avgs[0]) < float(config[0]["1m"][0])
            or float(avgs[0]) > float(config[0]["1m"][1])
            or float(avgs[1]) < float(config[1]["5m"][0])
            or float(avgs[1]) > float(config[1]["5m"][1])
            or float(avgs[2]) < float(config[2]["15m"][0])
            or float(avgs[2]) > float(config[2]["15m"][1])
        ):
            ret.append(avg_dict)
    return ret


# Traceback (TypeError)
[DEBUG   ] Sending event - data = {'_stamp': '2015-10-13T21:36:05.014116', 'name': 'load', 'func': 'disable_beacon'}
[DEBUG   ] Handling event 'manage_beacons\n\n\x83\xa6_stamp\xba2015-10-13T21:36:05.014116\xa4name\xa4load\xa4func\xaedisable_beacon'
[ERROR   ] Exception in callback <functools.partial object at 0x7fd72412c730>
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/tornado/ioloop.py", line 592, in _run_callback
ret = callback()
File "/usr/lib/python2.7/dist-packages/tornado/stack_context.py", line 275, in null_wrapper
return fn(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/tornado/ioloop.py", line 598, in <lambda>
self.add_future(ret, lambda f: f.result())
File "/usr/lib/python2.7/dist-packages/tornado/concurrent.py", line 215, in result
raise_exc_info(self._exc_info)
File "/usr/lib/python2.7/dist-packages/tornado/gen.py", line 230, in wrapper
yielded = next(result)
File "/usr/lib/python2.7/dist-packages/salt/minion.py", line 1468, in handle_event
self.manage_beacons(package)
File "/usr/lib/python2.7/dist-packages/salt/minion.py", line 1376, in manage_beacons
self.beacons.disable_beacon(name)
File "/usr/lib/python2.7/dist-packages/salt/beacons/__init__.py", line 214, in disable_beacon
self.opts['beacons'][name]['enabled'] = False
TypeError: list indices must be integers, not str

# Fixed code
def beacon(config):
    """
    Emit the load averages of this host.

    Specify thresholds for each load average
    and only emit a beacon if any of them are
    exceeded.

    .. code-block:: yaml

        beacons:
          load:
            1m:
              - 0.0
              - 2.0
            5m:
              - 0.0
              - 1.5
            15m:
              - 0.1
              - 1.0

    """
    log.trace("load beacon starting")
    ret = []
    if not os.path.isfile("/proc/loadavg"):
        return ret
    with salt.utils.fopen("/proc/loadavg", "rb") as fp_:
        avgs = fp_.read().split()[:3]
        avg_keys = ["1m", "5m", "15m"]
        avg_dict = dict(zip(avg_keys, avgs))
        # Check each entry for threshold
        if (
            float(avgs[0]) < float(config["1m"][0])
            or float(avgs[0]) > float(config["1m"][1])
            or float(avgs[1]) < float(config["5m"][0])
            or float(avgs[1]) > float(config["5m"][1])
            or float(avgs[2]) < float(config["15m"][0])
            or float(avgs[2]) > float(config["15m"][1])
        ):
            ret.append(avg_dict)
    return ret