Skip to content

Commit

Permalink
updated export alert tools to hide invisible rules
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyBarnes committed Sep 30, 2023
1 parent 9b29897 commit 281a609
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions tooling/export-alerts/export-alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def parseArguments():
parser.add_argument('-j', '--output-json', type=str, required=False, metavar='file', help='Output path to JSON file')
parser.add_argument('-y', '--output-yaml', type=str, required=False, metavar='file', help='Output path to YAML file')
parser.add_argument('-t', '--template', type=str, required=False, metavar='template', help='Path to Excel template', default='alerts-template.xlsx')
parser.add_argument('-o', '--output', type=str, required=False, metavar='output', help='Path to output file', default='amba-alerts.xlsx')
parser.add_argument('-s', '--export-hidden', action='store_true', help='Export alerts rules where visible is set to false')
args = parser.parse_args()

return args
Expand All @@ -33,7 +33,7 @@ def outputToYamlFile(data, filename):
with open(filename, "w") as f:
yaml.dump(data, f, indent=2)

def readYamlData(dir):
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
Expand All @@ -57,6 +57,8 @@ def readYamlData(dir):

alerts = yaml.safe_load(f)
for alert in alerts:
if (not export_hidden) and ('visible' in alert) and (alert['visible'] == False):
continue
data[resouceCategory][resourceType].append(alert)

return data
Expand Down Expand Up @@ -143,19 +145,15 @@ def main():

args = parseArguments()

data = readYamlData(args.path, args.export_hidden)

templateFile = '/tooling/export-alerts/alerts-template.xlsx'
outputFile= '/services/amba-alerts.xlsx'

data = readYamlData(args.path)

if len(args.output_xls) > 0:
if args.output_xls:
exportToXls(data, args.template, args.output_xls)

if len(args.output_json) > 0:
if args.output_json:
outputToJsonFile(data, args.output_json)

if len(args.output_yaml) > 0:
if args.output_yaml:
outputToYamlFile(data, args.output_yaml)

if __name__ == '__main__':
Expand Down

0 comments on commit 281a609

Please sign in to comment.