feat: added aws-cloudwatch.py
This commit is contained in:
+1
-1
@@ -30,7 +30,7 @@ def main() -> None:
|
|||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||||
results = executor.map(getResources, projectlib.aws.getRegions())
|
results = executor.map(getResources, projectlib.aws.getRegions())
|
||||||
for region_rows in results:
|
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:
|
if region_rows:
|
||||||
for row in region_rows:
|
for row in region_rows:
|
||||||
ws.append(row)
|
ws.append(row)
|
||||||
|
|||||||
Executable
+50
@@ -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()
|
||||||
+1
-1
@@ -34,7 +34,7 @@ def main() -> None:
|
|||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||||
results = executor.map(getResources, projectlib.aws.getRegions())
|
results = executor.map(getResources, projectlib.aws.getRegions())
|
||||||
for region_rows in results:
|
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:
|
if region_rows:
|
||||||
for row in region_rows:
|
for row in region_rows:
|
||||||
ws.append(row)
|
ws.append(row)
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ def main() -> None:
|
|||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||||
results = executor.map(getResources, projectlib.aws.getRegions())
|
results = executor.map(getResources, projectlib.aws.getRegions())
|
||||||
for region_rows in results:
|
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:
|
if region_rows:
|
||||||
for row in region_rows:
|
for row in region_rows:
|
||||||
ws.append(row)
|
ws.append(row)
|
||||||
|
|||||||
+1
-1
@@ -33,7 +33,7 @@ def main() -> None:
|
|||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||||
results = executor.map(getResources, projectlib.aws.getRegions())
|
results = executor.map(getResources, projectlib.aws.getRegions())
|
||||||
for region_rows in results:
|
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:
|
if region_rows:
|
||||||
for row in region_rows:
|
for row in region_rows:
|
||||||
ws.append(row)
|
ws.append(row)
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ def main() -> None:
|
|||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||||
results = executor.map(getResources, projectlib.aws.getRegions())
|
results = executor.map(getResources, projectlib.aws.getRegions())
|
||||||
for region_rows in results:
|
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:
|
if region_rows:
|
||||||
for row in region_rows:
|
for row in region_rows:
|
||||||
ws.append(row)
|
ws.append(row)
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ def main() -> None:
|
|||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||||
results = executor.map(getResources, projectlib.aws.getRegions())
|
results = executor.map(getResources, projectlib.aws.getRegions())
|
||||||
for region_rows in results:
|
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:
|
if region_rows:
|
||||||
for row in region_rows:
|
for row in region_rows:
|
||||||
ws.append(row)
|
ws.append(row)
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ def main() -> None:
|
|||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||||
results = executor.map(getResources, projectlib.aws.getRegions())
|
results = executor.map(getResources, projectlib.aws.getRegions())
|
||||||
for region_rows in results:
|
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:
|
if region_rows:
|
||||||
for row in region_rows:
|
for row in region_rows:
|
||||||
ws.append(row)
|
ws.append(row)
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ def main() -> None:
|
|||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||||
results = executor.map(getResources, projectlib.aws.getRegions())
|
results = executor.map(getResources, projectlib.aws.getRegions())
|
||||||
for region_rows in results:
|
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:
|
if region_rows:
|
||||||
for row in region_rows:
|
for row in region_rows:
|
||||||
ws.append(row)
|
ws.append(row)
|
||||||
|
|||||||
+1
-1
@@ -33,7 +33,7 @@ def main() -> None:
|
|||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||||
results = executor.map(getResources, projectlib.aws.getRegions())
|
results = executor.map(getResources, projectlib.aws.getRegions())
|
||||||
for region_rows in results:
|
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:
|
if region_rows:
|
||||||
for row in region_rows:
|
for row in region_rows:
|
||||||
ws.append(row)
|
ws.append(row)
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ def main() -> None:
|
|||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||||
results = executor.map(getResources, projectlib.aws.getRegions())
|
results = executor.map(getResources, projectlib.aws.getRegions())
|
||||||
for region_rows in results:
|
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:
|
if region_rows:
|
||||||
for row in region_rows:
|
for row in region_rows:
|
||||||
ws.append(row)
|
ws.append(row)
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ def main() -> None:
|
|||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||||
results = executor.map(getResources, projectlib.aws.getRegions())
|
results = executor.map(getResources, projectlib.aws.getRegions())
|
||||||
for region_rows in results:
|
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:
|
if region_rows:
|
||||||
for row in region_rows:
|
for row in region_rows:
|
||||||
ws.append(row)
|
ws.append(row)
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ def main() -> None:
|
|||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||||
results = executor.map(getResources, projectlib.aws.getRegions())
|
results = executor.map(getResources, projectlib.aws.getRegions())
|
||||||
for region_rows in results:
|
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:
|
if region_rows:
|
||||||
for row in region_rows:
|
for row in region_rows:
|
||||||
ws.append(row)
|
ws.append(row)
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ def main() -> None:
|
|||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||||
results = executor.map(getResources, projectlib.aws.getRegions())
|
results = executor.map(getResources, projectlib.aws.getRegions())
|
||||||
for region_rows in results:
|
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:
|
if region_rows:
|
||||||
for row in region_rows:
|
for row in region_rows:
|
||||||
ws.append(row)
|
ws.append(row)
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ def main() -> None:
|
|||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||||
results = executor.map(getResources, projectlib.aws.getRegions())
|
results = executor.map(getResources, projectlib.aws.getRegions())
|
||||||
for region_rows in results:
|
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:
|
if region_rows:
|
||||||
for row in region_rows:
|
for row in region_rows:
|
||||||
ws.append(row)
|
ws.append(row)
|
||||||
|
|||||||
+1
-1
@@ -33,7 +33,7 @@ def main() -> None:
|
|||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||||
results = executor.map(getResources, projectlib.aws.getRegions())
|
results = executor.map(getResources, projectlib.aws.getRegions())
|
||||||
for region_rows in results:
|
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:
|
if region_rows:
|
||||||
for row in region_rows:
|
for row in region_rows:
|
||||||
ws.append(row)
|
ws.append(row)
|
||||||
|
|||||||
Reference in New Issue
Block a user