Last active
July 4, 2017 15:58
-
-
Save majormoses/984e486a3b63e4dd5172a341fd3472f7 to your computer and use it in GitHub Desktop.
Recipe to create a bunch of sensu checks from attributes
This file contains 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
# non-converge checks | |
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['chef_client']['command'] = "check-chef-nodes.rb -U #{Chef::Config[:chef_server_url]} -C :::chef.client.node|#{node.name}::: -K /etc/sensu/conf.d/chef-client.pem -t 1800" | |
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['chef_client']['handlers'] = ['pagerduty'] | |
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['chef_client']['subscribers'] = ['chef_server'] | |
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['chef_client']['interval'] = 60 | |
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['chef_client']['additional'] = { | |
'pager_team' => 'non_urgent', | |
'notification' => 'A chef client is not converging', | |
'occurrences' => 2, | |
'subdue' => { | |
'days' => { | |
'all' => [ | |
{ | |
'begin' => '6PM PST', | |
'end' => '10AM PST' | |
} | |
] | |
} | |
} | |
} |
This file contains 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
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['ping_four8s']['command'] = 'check-ping.rb -h 8.8.8.8 -T 5' | |
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['ping_four8s']['handlers'] = ['pagerduty'] | |
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['ping_four8s']['subscribers'] = ['base'] | |
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['ping_four8s']['interval'] = 5 | |
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['ping_four8s']['additional'] = { | |
'pager_team' => 'urgent', | |
'notification' => 'cant reach 8.8.8.8', | |
'occurrences' => 13 | |
} |
This file contains 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
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['ping_google']['command'] = 'check-ping.rb -h google.com -T 5' | |
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['ping_google']['handlers'] = ['pagerduty'] | |
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['ping_google']['subscribers'] = ['base'] | |
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['ping_google']['interval'] = 5 | |
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['ping_google']['additional'] = { | |
'pager_team' => 'urgent', | |
'notification' => 'cant reach google.com', | |
'occurrences' => 13 | |
} |
This file contains 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
node['MY_CUSTOM_NAMESPACE']['sensu']['checks'].each do |name, check| | |
sensu_check name do | |
if check['command'] | |
if node['MY_CUSTOM_NAMESPACE']['sensu']['checks'][name]['custom'] | |
command "#{node['sensu']['directory']}/plugins/" + check['command'] | |
else | |
command check['command'] | |
end | |
else | |
Chef::Log.error "Unable to find a command for check: #{name}" | |
end | |
if check['handlers'] | |
handlers check['handlers'] | |
else | |
Chef::Log.info "Warning there are no handlers defined for check: #{name}" | |
end | |
if check['subscribers'] | |
subscribers check['subscribers'] | |
else | |
Chef::Log.error "Unable to find a subscriber for check: #{name}" | |
end | |
if check['interval'] | |
interval check['interval'] | |
else | |
Chef::Log.info "No defined interval for check: #{name}, using default of #{node['MY_CUSTOM_NAMESPACE']['sensu']['check_interval']}" | |
interval node['MY_CUSTOM_NAMESPACE']['sensu']['check_interval'] | |
end | |
publish check['publish'] unless check['publish'].nil? | |
if check['additional'] | |
additional check['additional'] | |
else | |
Chef::Log.error "No defined addtional for check: #{name}, this includes occurances, notification message, etc." | |
end | |
# use unless nil instead of if because its a bool value | |
standalone check['standalone'] unless check['standalone'].nil? | |
if check['low_flap_threshold'] && check['high_flap_threshold'] | |
if check['high_flap_threshold'] > check['low_flap_threshold'] | |
low_flap_threshold check['low_flap_threshold'] | |
high_flap_threshold check['high_flap_threshold'] | |
end | |
end | |
only_if do | |
# Generate all checks on sensu server, base checks, or checks that are in the intersection of roles and subscribers. | |
(node['roles'].include? 'sensu_server')\ | |
|| (check['subscribers'].include? 'base')\ | |
|| (!node['MY_CUSTOM_NAMESPACE']['sensu']['roles'].nil?\ | |
&& !(check['subscribers'] & node['MY_CUSTOM_NAMESPACE']['sensu']['roles']).empty?) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment