# Buggy code
def beacon(config):
    """
    Return status for requested information
    """
    log.debug(config)
    ctime = datetime.datetime.utcnow().isoformat()

    if len(config) < 1:
        config = {
            "loadavg": ["all"],
            "cpustats": ["all"],
            "meminfo": ["all"],
            "vmstats": ["all"],
            "time": ["all"],
        }

    ret = {}
    for func in config:
        try:
            data = __salt__["status.{0}".format(func)]()
        except salt.exceptions.CommandExecutionError as exc:
            log.debug(
                "Status beacon attempted to process function {0} \
                    but encountered error: {1}".format(func, exc)
            )
            continue
        ret[func] = {}
        for item in config[func]:
            if item == "all":
                ret[func] = data
            else:
                try:
                    try:
                        ret[func][item] = data[item]
                    except TypeError:
                        ret[func][item] = data[int(item)]
                except KeyError as exc:
                    ret[func] = "Status beacon is incorrectly configured: {0}".format(
                        exc
                    )

    return [
        {
            "tag": ctime,
            "data": ret,
        }
    ]


# Traceback (KeyError)
2016-12-07 10:33:33,391 [salt.minion      ][CRITICAL][22470] The beacon errored:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/minion.py", line 2153, in handle_beacons
beacons = self.process_beacons(self.functions)
File "/usr/lib/python2.7/dist-packages/salt/minion.py", line 409, in process_beacons
return self.beacons.process(b_conf, self.opts['grains'])  # pylint: disable=no-member
File "/usr/lib/python2.7/dist-packages/salt/beacons/__init__.py", line 103, in process
raw = self.beacons[fun_str](b_config[mod])
File "/usr/lib/python2.7/dist-packages/salt/beacons/status.py", line 121, in beacon
data = __salt__['status.{0}'.format(func)]()
File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1086, in __getitem__
func = super(LazyLoader, self).__getitem__(item)
File "/usr/lib/python2.7/dist-packages/salt/utils/lazy.py", line 101, in __getitem__
raise KeyError(key)
KeyError: "status.{'time': ['all']}"

# Fixed code
def beacon(config):
    """
    Return status for requested information
    """
    log.debug(config)
    ctime = datetime.datetime.utcnow().isoformat()

    if len(config) < 1:
        config = [
            {
                "loadavg": ["all"],
                "cpustats": ["all"],
                "meminfo": ["all"],
                "vmstats": ["all"],
                "time": ["all"],
            }
        ]

    if not isinstance(config, list):
        # To support the old dictionary config format
        config = [config]

    ret = {}
    for entry in config:
        for func in entry:
            ret[func] = {}
            try:
                data = __salt__["status.{0}".format(func)]()
            except salt.exceptions.CommandExecutionError as exc:
                log.debug(
                    "Status beacon attempted to process function {0} "
                    "but encountered error: {1}".format(func, exc)
                )
                continue
            if not isinstance(entry[func], list):
                func_items = [entry[func]]
            else:
                func_items = entry[func]
            for item in func_items:
                if item == "all":
                    ret[func] = data
                else:
                    try:
                        try:
                            ret[func][item] = data[item]
                        except TypeError:
                            ret[func][item] = data[int(item)]
                    except KeyError as exc:
                        ret[func] = (
                            "Status beacon is incorrectly configured: {0}".format(exc)
                        )

    return [
        {
            "tag": ctime,
            "data": ret,
        }
    ]