Skip to content

Instantly share code, notes, and snippets.

@marceldegraaf
Created November 28, 2012 11:40
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 marceldegraaf/4160651 to your computer and use it in GitHub Desktop.
Save marceldegraaf/4160651 to your computer and use it in GitHub Desktop.
Chef monit cookbook
default[:monit][:alert_emails] = %w( root@localhost )
default[:monit][:logfile] = "/var/log/monit.log"
default[:monit][:alert_from] = "monit@localhost"
default[:monit][:remote_user] = 'admin'
default[:monit][:remote_password] = 'secret'
define :monitrc, rules: [], variables: {} do
Chef::Log.info("Generating monitrc for: #{params[:name]}")
template "/etc/monit/conf.d/#{params[:name]}.monitrc" do
mode "0744"
user "root"
source params[:source]
variables params[:variables]
notifies :restart, "service[monit]", :immediately
action :create
variables rules: params[:rules],
vars: params[:variables],
name: params[:name]
end
end
package "monit"
directory "/etc/monit/conf.d" do
action :create
recursive true
end
template "/etc/monit/monitrc" do
source "monitrc.erb"
mode "0600"
variables :alert_emails => node[:monit][:alert_emails],
:logfile => node[:monit][:logfile]
notifies :restart, "service[monit]"
end
service "monit" do
action :nothing
end
set daemon 30
set mailserver localhost
set mail-format { from: <%= node[:monit][:alert_from] %> }
<% @alert_emails.each do |email| -%>
set alert <%= email %> but not on { pid instance }
<% end %>
set eventqueue
basedir /var/monit
slots 100
set logfile <%= @logfile %>
Include /etc/monit/conf.d/*.monitrc
set httpd port 2812
allow <%= node[:monit][:remote_user] %>:<%= node[:monit][:remote_password] %>
# This is an example of using the "monitrc" definition
monitrc :nginx do
source "nginx.monitrc.erb" # <= this is the monitrc.erb template in your own cookbook
rules node[:nginx][:monit][:rules]
end
check process nginx
with pidfile <%= node[:nginx][:pid] %>
start program = "/etc/init.d/nginx start" as uid root and gid root
stop program = "/etc/init.d/nginx stop" as uid root and gid root
<% @rules.each do |rule| -%>
<%= rule %>
<% end -%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment