Skip to content

Instantly share code, notes, and snippets.

@fbettag
Created July 25, 2018 19:59
Show Gist options
  • Save fbettag/a465309c1a8d2fddd93e997d1f8dee44 to your computer and use it in GitHub Desktop.
Save fbettag/a465309c1a8d2fddd93e997d1f8dee44 to your computer and use it in GitHub Desktop.
rudder agent hook script to be placed into /var/rudder/hooks.d
#!/bin/sh
# All available metadata within the sdc: namespace gets converted into vars.
VARS="uuid server_uuid datacenter_name alias billing_id brand cpu_shares create_timestamp dns_domain hostname image_uuid last_modified limit_priv max_locked_memory max_lwps max_physical_memory max_swap owner_uuid quota state tmpfs zfs_io_priority zonename zonepath"
E="{"
# The sdc: namespace.
for key in $VARS
do
VALUE=$(mdata-get sdc:${key} 2>/dev/null|sed ':a;N;$!ba;s/\n/\\n/g')
[[ -n $VALUE ]] && E+="\"sdc:${key}\":\"${VALUE}\","
done
# User defined customer_metadata.
for key in $(mdata-list)
do
VALUE=$(mdata-get ${key} 2>/dev/null|sed ':a;N;$!ba;s/\n/\\n/g')
[[ -n $VALUE ]] && E+="\"${key}\":\"${VALUE}\","
done
E+="}"
echo -n $E|sed -e 's;,}$;};'
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment