Created
November 25, 2016 18:20
-
-
Save skreuzer/20ae9a37ba0c124819eae7f0e0a3104b to your computer and use it in GitHub Desktop.
Cfengine bundle to extract EC2 metadata information from the host
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
bundle agent aws | |
{ | |
methods: | |
"any" usebundle => ec2_metadata("meta-data/instance-id", "^i-.*"), | |
useresult => "metadata"; | |
"any" usebundle => ec2_metadata("meta-data/instance-type", "^[tmcxrpgid]\d\.(nano|micro|small|medium|\d?x?large)$"), | |
useresult => "metadata"; | |
"any" usebundle => ec2_metadata("meta-data/placement/availability-zone", "^us-.*"), | |
useresult => "metadata"; | |
reports: | |
"availability-zone: $(metadata[availability_zone])"; | |
"instance-type: $(metadata[instance_type])"; | |
"instance-id: $(metadata[instance_id])"; | |
} | |
bundle agent ec2_metadata(metric, metric_regex) | |
{ | |
vars: | |
"query" string => readtcp("169.254.169.254", "80", | |
"GET /latest/$(metric) HTTP/1.1$(const.r)$(const.n)$(const.r)$(const.n)", 500); | |
"return_index" string => canonify(lastnode("$(metric)", "/")); | |
classes: | |
"query_ok" expression => regcmp("[^\n]*200 OK.*\n.*","$(query)"); | |
query_ok:: | |
"extract_ok" expression => regextract("$(metric_regex)", $(query), "query_result"); | |
reports: | |
extract_ok:: | |
"$(query_result[0])" bundle_return_value_index => "$(return_index)"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment