in tooling/generate-templates/generate-templates.py [0:0]
def readYamlData(dir, export_hidden):
# Walk the directory tree and load all the alerts.yaml files
# into a list of dictionaries using the folder path as the structure
# for the dictionary.
data = {}
for root, dirs, files in os.walk(dir):
for file in files:
if file == 'alerts.yaml':
with open(os.path.join(root, file)) as f:
# Get current folder name and parent folder name
# to use as keys in the dictionary
resourceType = os.path.basename(root)
resouceCategory = os.path.basename(os.path.dirname(root))
if not resouceCategory in data:
data[resouceCategory] = {}
if not resourceType in data[resouceCategory]:
data[resouceCategory][resourceType] = []
alerts = yaml.safe_load(f)
if alerts:
for alert in alerts:
if (not export_hidden) and ('visible' in alert) and (alert['visible'] == False):
continue
data[resouceCategory][resourceType].append(alert)
return data