From 67774d64dbcab9f91cb58c72714fc9df94658fe9 Mon Sep 17 00:00:00 2001 From: KenF Date: Thu, 29 Jan 2026 13:23:19 +0800 Subject: [PATCH] feat: added aws-cloudwatch.py --- aws-apigw.py | 2 +- aws-cloudwatch.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++ aws-ddb.py | 2 +- aws-ec2.py | 2 +- aws-ecs.py | 2 +- aws-efs.py | 2 +- aws-eks.py | 2 +- aws-elasticache.py | 2 +- aws-emr.py | 2 +- aws-lambda.py | 2 +- aws-lb.py | 2 +- aws-logs.py | 2 +- aws-opensearch.py | 2 +- aws-rds.py | 2 +- aws-step.py | 2 +- aws-subnets.py | 2 +- 16 files changed, 65 insertions(+), 15 deletions(-) create mode 100755 aws-cloudwatch.py diff --git a/aws-apigw.py b/aws-apigw.py index 94d0285..2f3dc17 100755 --- a/aws-apigw.py +++ b/aws-apigw.py @@ -30,7 +30,7 @@ def main() -> None: with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: results = executor.map(getResources, projectlib.aws.getRegions()) for region_rows in results: - # append to worksheet only if resoruces are found in the region + # append to worksheet only if resources are found in the region if region_rows: for row in region_rows: ws.append(row) diff --git a/aws-cloudwatch.py b/aws-cloudwatch.py new file mode 100755 index 0000000..fd746a5 --- /dev/null +++ b/aws-cloudwatch.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +r""" +Documentation + +License: This program is released under the MIT License +""" + +# Imports +import boto3 +import concurrent.futures +from openpyxl import load_workbook +from openpyxl.worksheet.worksheet import Worksheet +import projectlib.aws + + +def getResources(region_name: str) -> list[list[str | int]]: + return_data = [] + client = boto3.client('cloudwatch', region_name=region_name) + paginator = client.get_paginator('describe_alarms') + for page in paginator.paginate( + AlarmTypes=['CompositeAlarm','MetricAlarm'] + ): + composite = page.get('CompositeAlarms', []) + for i in composite: + return_data.append(["Composite", i['AlarmName'], i.get('AlarmDescription'), i['ActionsEnabled'], region_name]) + metric = page.get('MetricAlarms', []) + for i in metric: + return_data.append(["Metric", i['AlarmName'], i.get('AlarmDescription'), i['ActionsEnabled'], region_name]) + return return_data + +# Main function +def main() -> None: + # Open spreadsheet and add a sheet + wb = load_workbook('aws-inventory.xlsx') + ws = wb.create_sheet("Cloudwatch") + + ws.append(["Type", "AlarmName", "AlarmDescription", "ActionsEnabled", "region"]) + with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: + results = executor.map(getResources, projectlib.aws.getRegions()) + for region_rows in results: + # append to worksheet only if resources are found in the region + if region_rows: + for row in region_rows: + ws.append(row) + + wb.save('aws-inventory.xlsx') + +# Call main function +if __name__ == '__main__': + main() diff --git a/aws-ddb.py b/aws-ddb.py index e771eaa..16d1e8d 100755 --- a/aws-ddb.py +++ b/aws-ddb.py @@ -34,7 +34,7 @@ def main() -> None: with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: results = executor.map(getResources, projectlib.aws.getRegions()) for region_rows in results: - # append to worksheet only if resoruces are found in the region + # append to worksheet only if resources are found in the region if region_rows: for row in region_rows: ws.append(row) diff --git a/aws-ec2.py b/aws-ec2.py index c76a891..0f63eb7 100755 --- a/aws-ec2.py +++ b/aws-ec2.py @@ -40,7 +40,7 @@ def main() -> None: with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: results = executor.map(getResources, projectlib.aws.getRegions()) for region_rows in results: - # append to worksheet only if resoruces are found in the region + # append to worksheet only if resources are found in the region if region_rows: for row in region_rows: ws.append(row) diff --git a/aws-ecs.py b/aws-ecs.py index 4e6dfea..6794a5e 100755 --- a/aws-ecs.py +++ b/aws-ecs.py @@ -33,7 +33,7 @@ def main() -> None: with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: results = executor.map(getResources, projectlib.aws.getRegions()) for region_rows in results: - # append to worksheet only if resoruces are found in the region + # append to worksheet only if resources are found in the region if region_rows: for row in region_rows: ws.append(row) diff --git a/aws-efs.py b/aws-efs.py index 77f3ad5..92b436c 100755 --- a/aws-efs.py +++ b/aws-efs.py @@ -31,7 +31,7 @@ def main() -> None: with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: results = executor.map(getResources, projectlib.aws.getRegions()) for region_rows in results: - # append to worksheet only if resoruces are found in the region + # append to worksheet only if resources are found in the region if region_rows: for row in region_rows: ws.append(row) diff --git a/aws-eks.py b/aws-eks.py index a20889f..97f4eb4 100755 --- a/aws-eks.py +++ b/aws-eks.py @@ -37,7 +37,7 @@ def main() -> None: with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: results = executor.map(getResources, projectlib.aws.getRegions()) for region_rows in results: - # append to worksheet only if resoruces are found in the region + # append to worksheet only if resources are found in the region if region_rows: for row in region_rows: ws.append(row) diff --git a/aws-elasticache.py b/aws-elasticache.py index eb08bcd..2cdfb40 100755 --- a/aws-elasticache.py +++ b/aws-elasticache.py @@ -31,7 +31,7 @@ def main() -> None: with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: results = executor.map(getResources, projectlib.aws.getRegions()) for region_rows in results: - # append to worksheet only if resoruces are found in the region + # append to worksheet only if resources are found in the region if region_rows: for row in region_rows: ws.append(row) diff --git a/aws-emr.py b/aws-emr.py index a81c58c..9e0d54c 100755 --- a/aws-emr.py +++ b/aws-emr.py @@ -31,7 +31,7 @@ def main() -> None: with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: results = executor.map(getResources, projectlib.aws.getRegions()) for region_rows in results: - # append to worksheet only if resoruces are found in the region + # append to worksheet only if resources are found in the region if region_rows: for row in region_rows: ws.append(row) diff --git a/aws-lambda.py b/aws-lambda.py index 7ff9c17..37c5a8a 100755 --- a/aws-lambda.py +++ b/aws-lambda.py @@ -33,7 +33,7 @@ def main() -> None: with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: results = executor.map(getResources, projectlib.aws.getRegions()) for region_rows in results: - # append to worksheet only if resoruces are found in the region + # append to worksheet only if resources are found in the region if region_rows: for row in region_rows: ws.append(row) diff --git a/aws-lb.py b/aws-lb.py index dc7008e..870b5b4 100755 --- a/aws-lb.py +++ b/aws-lb.py @@ -31,7 +31,7 @@ def main() -> None: with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: results = executor.map(getResources, projectlib.aws.getRegions()) for region_rows in results: - # append to worksheet only if resoruces are found in the region + # append to worksheet only if resources are found in the region if region_rows: for row in region_rows: ws.append(row) diff --git a/aws-logs.py b/aws-logs.py index 20567e2..ee119b6 100755 --- a/aws-logs.py +++ b/aws-logs.py @@ -31,7 +31,7 @@ def main() -> None: with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: results = executor.map(getResources, projectlib.aws.getRegions()) for region_rows in results: - # append to worksheet only if resoruces are found in the region + # append to worksheet only if resources are found in the region if region_rows: for row in region_rows: ws.append(row) diff --git a/aws-opensearch.py b/aws-opensearch.py index 54b7164..fea0c10 100755 --- a/aws-opensearch.py +++ b/aws-opensearch.py @@ -31,7 +31,7 @@ def main() -> None: with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: results = executor.map(getResources, projectlib.aws.getRegions()) for region_rows in results: - # append to worksheet only if resoruces are found in the region + # append to worksheet only if resources are found in the region if region_rows: for row in region_rows: ws.append(row) diff --git a/aws-rds.py b/aws-rds.py index fa4a6d3..4ba45c3 100755 --- a/aws-rds.py +++ b/aws-rds.py @@ -31,7 +31,7 @@ def main() -> None: with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: results = executor.map(getResources, projectlib.aws.getRegions()) for region_rows in results: - # append to worksheet only if resoruces are found in the region + # append to worksheet only if resources are found in the region if region_rows: for row in region_rows: ws.append(row) diff --git a/aws-step.py b/aws-step.py index 96beb51..490d3a1 100755 --- a/aws-step.py +++ b/aws-step.py @@ -31,7 +31,7 @@ def main() -> None: with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: results = executor.map(getResources, projectlib.aws.getRegions()) for region_rows in results: - # append to worksheet only if resoruces are found in the region + # append to worksheet only if resources are found in the region if region_rows: for row in region_rows: ws.append(row) diff --git a/aws-subnets.py b/aws-subnets.py index 496731e..cba9811 100755 --- a/aws-subnets.py +++ b/aws-subnets.py @@ -33,7 +33,7 @@ def main() -> None: with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: results = executor.map(getResources, projectlib.aws.getRegions()) for region_rows in results: - # append to worksheet only if resoruces are found in the region + # append to worksheet only if resources are found in the region if region_rows: for row in region_rows: ws.append(row)