Created
May 26, 2020 06:17
-
-
Save SolveSoul/9cf6d757450caecefb4ff31fcc74d53f to your computer and use it in GitHub Desktop.
Extracts the pending (security) patches and sends them to AWS CloudWatch as a metric
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PATCHES=$(sed '2q;d' /var/lib/update-notifier/updates-available | grep -o '[0-9]*') | |
SECURITY_PATCHES=$(sed "3q;d" /var/lib/update-notifier/updates-available | grep -o '[0-9]*') | |
INSTANCE_ID=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id) | |
UNIT="Count" | |
NAMESPACE="System/Linux" | |
aws cloudwatch put-metric-data --namespace $NAMESPACE --dimensions InstanceId=$INSTANCE_ID --unit $UNIT --metric-name "OperatingSystemUpdates" --value $PATCHES | |
aws cloudwatch put-metric-data --namespace $NAMESPACE --dimensions InstanceId=$INSTANCE_ID --unit $UNIT --metric-name "OperatingSystemSecurityUpdates" --value $SECURITY_PATCHES |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment