Skip to content

Instantly share code, notes, and snippets.

@octplane
Created August 11, 2011 13:19
Show Gist options
  • Select an option

  • Save octplane/1139625 to your computer and use it in GitHub Desktop.

Select an option

Save octplane/1139625 to your computer and use it in GitHub Desktop.
Service template for Nagios in chef.
define host {
use generic-host <%# Inherit default values from a template %>
<%# Use FQDN because munin will send alerts using the FQDN %>
host_name <%= @host['fqdn'] %><%# The name we’re giving to this host %>
alias <%= @host['hostname'] %><%# A longer name associated with the host %>
address <%= @host['ipaddress'] %><%# IP address of the host %>
}
<% @services.each do |service, info|
info = info.to_hash
if DefaultMonitoredValues::check_on(info).include?(@host['swissr']['grid'])
%>
define service {
host <%= @host['fqdn'] %>
<% if DefaultMonitoredValues.passive(info) %>
use passive-service
<% else %>
use generic-service
retry_interval <%= DefaultMonitoredValues::retry_interval(info) %>
max_check_attempts <%= DefaultMonitoredValues::max_check_attempts(info) %>
check_command <%= DefaultMonitoredValues::check_command(info) %>
notification_period <%= DefaultMonitoredValues::notification_period(info)[@host['swissr']['grid']] %>
normal_check_interval <%= DefaultMonitoredValues::normal_check_interval(info) %>
<% end %>
service_description <%= service %>
}
<% info['depends'].each do |parent|
sd, hn = parent.split(/@/)
%>
define servicedependency {
dependent_host_name <%= @host['fqdn'] %>
dependent_service_description <%= service %>
host_name <%= hn %>.<%= @host['domain'] %>
service_description <%= sd %>
inherits_parent 1
notification_failure_criteria w,u,c
}
<% end
end
end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment