Skip to content

Instantly share code, notes, and snippets.

@rossdakin
Created January 13, 2015 21:47
Show Gist options
  • Save rossdakin/22db64daa8e13c7237ba to your computer and use it in GitHub Desktop.
Save rossdakin/22db64daa8e13c7237ba to your computer and use it in GitHub Desktop.
Files to construct a Chef cookbook for creating a "canary" instance (a box that simply announces itself to CoudWatch, to ensure that egress traffic from private subnets is successfully making its way through your NAT boxes).
default[:deliv_canary][:cron_name] = 'canary'
default[:deliv_canary][:region] = 'us-east-1'
default[:deliv_canary][:namespace] = 'Canary'
default[:deliv_canary][:metric_name] = 'Chirps'
default[:deliv_canary][:unit] = 'Count'
default[:deliv_canary][:value] = 1
default[:deliv_canary][:dimensions] = {
AZ: node[:opsworks][:instance][:availability_zone],
Environment: node[:deliv_canary][:environment],
VPC: node[:opsworks][:stack][:vpc_id],
}.to_a.sort.map { |pair| pair.join('=') }.join(',')
cron node[:deliv_canary][:cron_name] do
command %Q(aws cloudwatch put-metric-data
--region #{node[:deliv_canary][:region]}
--namespace #{node[:deliv_canary][:namespace]}
--metric-name #{node[:deliv_canary][:metric_name]}
--unit #{node[:deliv_canary][:unit]}
--value #{node[:deliv_canary][:value]}
--dimensions #{node[:deliv_canary][:dimensions]}).gsub(/\s+/, ' ')
end
include_recipe 'deliv_canary::list_crontab'
cron node[:deliv_canary][:cron_name] do
action :delete
end
include_recipe 'deliv_canary::list_crontab'
ruby_block 'list_crontab' do
block do
Chef::Log.info("Crontab for #{`whoami`.chomp} is currently: \n#{`crontab -l`}")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment