mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Support the new list configuration format.
Refs #38121 Conflicts: - salt/beacons/status.py
This commit is contained in:
parent
be06df9b64
commit
c7fc09f97d
1 changed files with 28 additions and 19 deletions
|
@ -117,34 +117,43 @@ def beacon(config):
|
|||
ctime = datetime.datetime.utcnow().isoformat()
|
||||
|
||||
if len(config) < 1:
|
||||
config = {
|
||||
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 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
|
||||
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:
|
||||
try:
|
||||
func_items = entry[func]
|
||||
for item in func_items:
|
||||
if item == 'all':
|
||||
ret[func] = data
|
||||
else:
|
||||
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)
|
||||
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,
|
||||
|
|
Loading…
Add table
Reference in a new issue