Skip to content

Instantly share code, notes, and snippets.

@BlueDoge
Created July 14, 2022 22:26
Show Gist options
  • Save BlueDoge/2305e798a1f1cdd804ff8236b65c0284 to your computer and use it in GitHub Desktop.
Save BlueDoge/2305e798a1f1cdd804ff8236b65c0284 to your computer and use it in GitHub Desktop.
Display alarm data, let user select alarms, then data dump
#Originally created by Liz Clements in 2022
#License: MIT
$AWSRegion = 'us-west-2'
$AWSProfileLocation = ("$env:USERPROFILE\.aws\credentials")
$AWSProfileName = 'default'
#Grab Composites
$AlarmData_Composite = Get-CWAlarm `
-ProfileLocation $AWSProfileLocation -ProfileName $AWSProfileName -Region $AWSRegion `
-AlarmType Composite
#Grab Metrics
$AlarmData_Metric = Get-CWAlarm `
-ProfileLocation $AWSProfileLocation -ProfileName $AWSProfileName -Region $AWSRegion `
-AlarmType Metric
#Provide the data on composites to the user via grid view
$UserData_Composite = `
$AlarmData_Composite | Select-Object `
@{ `
Name="State"; `
Expression= `
{ `
if($_.StateValue -eq [Amazon.CloudWatch.StateValue]::ALARM) `
{ `
"IN ALARM" `
} `
else { `
"OK" `
} `
} `
}, `
AlarmName, `
AlarmDescription, `
AlarmArn, `
AlarmRule, `
StateReason, `
StateReasonData, `
StateUpdatedTimestamp, `
@{ `
Name="Dimensions"; `
Expression= `
{ `
$_.Dimensions | Where-Object Key -eq "InstanceId" | Select-Object Value -ExpandProperty Value `
} `
}, `
AlarmConfigurationUpdatedTimestamp `
| Out-GridView -PassThru
#Provide the data on metrics to the user via grid view
$UserData_Metric = `
$AlarmData_Metric | Select-Object `
@{ `
Name="State"; `
Expression= `
{ `
if($_.StateValue -eq [Amazon.CloudWatch.StateValue]::ALARM) `
{ `
"IN ALARM" `
} `
else { `
"OK" `
} `
} `
}, `
MetricName, `
AlarmName, `
AlarmDescription, `
AlarmArn, `
StateReason, `
StateReasonData, `
StateUpdatedTimestamp, `
@{ `
Name="Dimensions"; `
Expression= `
{ `
$_.Dimensions | Where-Object Key -eq "InstanceId" | Select-Object Value -ExpandProperty Value `
} `
}, `
AlarmConfigurationUpdatedTimestamp `
| Out-GridView -PassThru
"=================="
"Composites"
"=================="
$UserData_Composite | Format-Table
" "
" "
"=================="
"Metrics"
"=================="
$UserData_Metric | Format-Table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment