Skip to content

Commit 81fb919

Browse files
kcantrelgithub-actions[bot]
authored andcommitted
Apply automatic changes
1 parent c001d81 commit 81fb919

File tree

1 file changed

+99
-87
lines changed

1 file changed

+99
-87
lines changed

Monitoring/auto-add-cw-alarms/cloudformation.yaml

Lines changed: 99 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ Resources:
191191
# with the name "SSD_Alarm_Threshold" on the file system resource.
192192
#
193193
# Version: v2.1
194-
# Date: 2025-01-31-20:33:33
194+
# Date: 2025-03-06-19:51:27
195195
#
196196
################################################################################
197197
#
@@ -615,92 +615,104 @@ Resources:
615615
for region in regions:
616616
if region in fsxRegions:
617617
print(f'Scanning {region}')
618-
fsx = boto3.client('fsx', region_name=region, config=boto3Config)
619-
cw = boto3.client('cloudwatch', region_name=region, config=boto3Config)
620-
#
621-
# Get all the file systems, volumes and alarm in the region.
622-
fss = getFss(fsx)
623-
volumes = getVolumes(fsx)
624-
alarms = getAlarms(cw)
625-
#
626-
# Scan for filesystems without CPU Utilization Alarm.
627-
for fs in fss:
628-
if(fs['FileSystemType'] == "ONTAP"):
629-
threshold = int(getCPUAlarmThresholdTagValue(fs['Tags']))
630-
if(threshold != 100):
631-
fsId = fs['FileSystemId']
632-
fsName = fsId.replace('fs-', 'FsxId')
633-
alarmName = alarmPrefixCPU + fsId
634-
alarmDescription = f"CPU utilization alarm for file system {fsName}{customerId} in region {region}."
635-
636-
if(not contains_alarm(alarmName, alarms) and onlyFilesystemId == None or
637-
not contains_alarm(alarmName, alarms) and onlyFilesystemId != None and onlyFilesystemId == fsId):
638-
print(f'Adding CPU Alarm for {fs["FileSystemId"]}')
639-
add_cpu_alarm(cw, fsId, alarmName, alarmDescription, threshold, region)
640-
#
641-
# Scan for CPU alarms without a FSxN filesystem.
642-
for alarm in alarms:
643-
alarmName = alarm['AlarmName']
644-
if(alarmName[:len(alarmPrefixCPU)] == alarmPrefixCPU):
645-
fsId = alarmName[len(alarmPrefixCPU):]
646-
if(not contains_fs(fsId, fss) and onlyFilesystemId == None or
647-
not contains_fs(fsId, fss) and onlyFilesystemId != None and onlyFilesystemId == fsId):
648-
print("Deleting alarm: " + alarmName + " in region " + region)
649-
delete_alarm(cw, alarmName)
650-
#
651-
# Scan for filesystems without SSD Utilization Alarm.
652-
for fs in fss:
653-
if(fs['FileSystemType'] == "ONTAP"):
654-
threshold = int(getSSDAlarmThresholdTagValue(fs['Tags']))
655-
if(threshold != 100):
656-
fsId = fs['FileSystemId']
657-
fsName = fsId.replace('fs-', 'FsxId')
658-
alarmName = alarmPrefixSSD + fsId
659-
alarmDescription = f"SSD utilization alarm for file system {fsName}{customerId} in region {region}."
660-
661-
if(not contains_alarm(alarmName, alarms) and onlyFilesystemId == None or
662-
not contains_alarm(alarmName, alarms) and onlyFilesystemId != None and onlyFilesystemId == fsId):
663-
print(f'Adding SSD Alarm for {fsId}')
664-
add_ssd_alarm(cw, fs['FileSystemId'], alarmName, alarmDescription, threshold, region)
665-
#
666-
# Scan for SSD alarms without a FSxN filesystem.
667-
for alarm in alarms:
668-
alarmName = alarm['AlarmName']
669-
if(alarmName[:len(alarmPrefixSSD)] == alarmPrefixSSD):
670-
fsId = alarmName[len(alarmPrefixSSD):]
671-
if(not contains_fs(fsId, fss) and onlyFilesystemId == None or
672-
not contains_fs(fsId, fss) and onlyFilesystemId != None and onlyFilesystemId == fsId):
673-
print("Deleteing alarm: " + alarmName + " in region " + region)
674-
delete_alarm(cw, alarmName)
675-
#
676-
# Scan for volumes without alarms.
677-
for volume in volumes:
678-
if(volume['VolumeType'] == "ONTAP"):
679-
volumeId = volume['VolumeId']
680-
volumeName = volume['Name']
681-
volumeARN = volume['ResourceARN']
682-
fsId = volume['FileSystemId']
683-
684-
threshold = int(getAlarmThresholdTagValue(fsx, volumeARN))
685-
686-
if(threshold != 100): # No alarm if the value is set to 100.
687-
alarmName = alarmPrefixVolume + volumeId
688-
fsName = fsId.replace('fs-', 'FsxId')
689-
alarmDescription = f"Volume utilization alarm for volumeId {volumeId}{customerId}, File System Name: {fsName}, Volume Name: {volumeName} in region {region}."
690-
if(not contains_alarm(alarmName, alarms) and onlyFilesystemId == None or
691-
not contains_alarm(alarmName, alarms) and onlyFilesystemId != None and onlyFilesystemId == fsId):
692-
print(f'Adding volume utilization alarm for {volumeName} in region {region}.')
693-
add_volume_alarm(cw, volumeId, alarmName, alarmDescription, fsId, threshold, region)
694-
#
695-
# Scan for volume alarms without volumes.
696-
for alarm in alarms:
697-
alarmName = alarm['AlarmName']
698-
if(alarmName[:len(alarmPrefixVolume)] == alarmPrefixVolume):
699-
volumeId = alarmName[len(alarmPrefixVolume):]
700-
if(not contains_volume(volumeId, volumes) and onlyFilesystemId == None or
701-
not contains_volume(volumeId, volumes) and onlyFilesystemId != None and onlyFilesystemId == getFileSystemId(alarm)):
702-
print("Deleteing alarm: " + alarmName + " in region " + region)
703-
delete_alarm(cw, alarmName)
618+
try:
619+
fsx = boto3.client('fsx', region_name=region, config=boto3Config)
620+
cw = boto3.client('cloudwatch', region_name=region, config=boto3Config)
621+
#
622+
# Get all the file systems, volumes and alarm in the region.
623+
fss = getFss(fsx)
624+
volumes = getVolumes(fsx)
625+
alarms = getAlarms(cw)
626+
#
627+
# Scan for filesystems without CPU Utilization Alarm.
628+
for fs in fss:
629+
if(fs['FileSystemType'] == "ONTAP"):
630+
threshold = int(getCPUAlarmThresholdTagValue(fs['Tags']))
631+
if(threshold != 100):
632+
fsId = fs['FileSystemId']
633+
fsName = fsId.replace('fs-', 'FsxId')
634+
alarmName = alarmPrefixCPU + fsId
635+
alarmDescription = f"CPU utilization alarm for file system {fsName}{customerId} in region {region}."
636+
637+
if(not contains_alarm(alarmName, alarms) and onlyFilesystemId == None or
638+
not contains_alarm(alarmName, alarms) and onlyFilesystemId != None and onlyFilesystemId == fsId):
639+
print(f'Adding CPU Alarm for {fs["FileSystemId"]}')
640+
add_cpu_alarm(cw, fsId, alarmName, alarmDescription, threshold, region)
641+
#
642+
# Scan for CPU alarms without a FSxN filesystem.
643+
for alarm in alarms:
644+
alarmName = alarm['AlarmName']
645+
if(alarmName[:len(alarmPrefixCPU)] == alarmPrefixCPU):
646+
fsId = alarmName[len(alarmPrefixCPU):]
647+
if(not contains_fs(fsId, fss) and onlyFilesystemId == None or
648+
not contains_fs(fsId, fss) and onlyFilesystemId != None and onlyFilesystemId == fsId):
649+
print("Deleting alarm: " + alarmName + " in region " + region)
650+
delete_alarm(cw, alarmName)
651+
#
652+
# Scan for filesystems without SSD Utilization Alarm.
653+
for fs in fss:
654+
if(fs['FileSystemType'] == "ONTAP"):
655+
threshold = int(getSSDAlarmThresholdTagValue(fs['Tags']))
656+
if(threshold != 100):
657+
fsId = fs['FileSystemId']
658+
fsName = fsId.replace('fs-', 'FsxId')
659+
alarmName = alarmPrefixSSD + fsId
660+
alarmDescription = f"SSD utilization alarm for file system {fsName}{customerId} in region {region}."
661+
662+
if(not contains_alarm(alarmName, alarms) and onlyFilesystemId == None or
663+
not contains_alarm(alarmName, alarms) and onlyFilesystemId != None and onlyFilesystemId == fsId):
664+
print(f'Adding SSD Alarm for {fsId}')
665+
add_ssd_alarm(cw, fs['FileSystemId'], alarmName, alarmDescription, threshold, region)
666+
#
667+
# Scan for SSD alarms without a FSxN filesystem.
668+
for alarm in alarms:
669+
alarmName = alarm['AlarmName']
670+
if(alarmName[:len(alarmPrefixSSD)] == alarmPrefixSSD):
671+
fsId = alarmName[len(alarmPrefixSSD):]
672+
if(not contains_fs(fsId, fss) and onlyFilesystemId == None or
673+
not contains_fs(fsId, fss) and onlyFilesystemId != None and onlyFilesystemId == fsId):
674+
print("Deleteing alarm: " + alarmName + " in region " + region)
675+
delete_alarm(cw, alarmName)
676+
#
677+
# Scan for volumes without alarms.
678+
for volume in volumes:
679+
if(volume['VolumeType'] == "ONTAP"):
680+
volumeId = volume['VolumeId']
681+
volumeName = volume['Name']
682+
volumeARN = volume['ResourceARN']
683+
fsId = volume['FileSystemId']
684+
685+
threshold = int(getAlarmThresholdTagValue(fsx, volumeARN))
686+
687+
if(threshold != 100): # No alarm if the value is set to 100.
688+
alarmName = alarmPrefixVolume + volumeId
689+
fsName = fsId.replace('fs-', 'FsxId')
690+
alarmDescription = f"Volume utilization alarm for volumeId {volumeId}{customerId}, File System Name: {fsName}, Volume Name: {volumeName} in region {region}."
691+
if(not contains_alarm(alarmName, alarms) and onlyFilesystemId == None or
692+
not contains_alarm(alarmName, alarms) and onlyFilesystemId != None and onlyFilesystemId == fsId):
693+
print(f'Adding volume utilization alarm for {volumeName} in region {region}.')
694+
add_volume_alarm(cw, volumeId, alarmName, alarmDescription, fsId, threshold, region)
695+
#
696+
# Scan for volume alarms without volumes.
697+
for alarm in alarms:
698+
alarmName = alarm['AlarmName']
699+
if(alarmName[:len(alarmPrefixVolume)] == alarmPrefixVolume):
700+
volumeId = alarmName[len(alarmPrefixVolume):]
701+
if(not contains_volume(volumeId, volumes) and onlyFilesystemId == None or
702+
not contains_volume(volumeId, volumes) and onlyFilesystemId != None and onlyFilesystemId == getFileSystemId(alarm)):
703+
print("Deleteing alarm: " + alarmName + " in region " + region)
704+
delete_alarm(cw, alarmName)
705+
706+
except botocore.exceptions.ClientError as e:
707+
if e.response['Error']['Code'] == 'ServiceUnavailableException':
708+
print(f"Warning: Service Unavailable fault while scanning {region}. Skipping")
709+
continue
710+
else:
711+
print(f"boto3 client error: {json.dumps(e.response)}")
712+
raise e
713+
except botocore.exceptions.EndpointConnectionError as e:
714+
print(f"Warning: Endpoint Connection fault while scanning {region}. Skipping")
715+
continue
704716
705717
return
706718

0 commit comments

Comments
 (0)