Skip to content

Instantly share code, notes, and snippets.

@SolveSoul
Created May 26, 2020 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SolveSoul/9cf6d757450caecefb4ff31fcc74d53f to your computer and use it in GitHub Desktop.
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
#!/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