Skip to content

Instantly share code, notes, and snippets.

@richardc
Last active December 19, 2015 09:09
Show Gist options
  • Select an option

  • Save richardc/5930902 to your computer and use it in GitHub Desktop.

Select an option

Save richardc/5930902 to your computer and use it in GitHub Desktop.
# dev_env.pp
node ns38 {
nagios::service { "BPL_ping":
service_block => {
hostgroup_name => "bpl-servers",
check_command => "check_ping!100.0,20%!500.0,60%",
},
}
nagios::service { "BPL_load":
service_block => {
hostgroup_name => "bpl-servers",
check_command => "ss_load",
},
}
nagios::service { "BPL_swap":
service_block => {
hostgroup_name => "bpl-servers",
check_command => "ss_swap",
},
}
nagios::service { "BPL_mem":
service_block => {
check_command => "ss_mem-used",
'hostgroup_name' => 'mem',
},
}
}
node ns39 {
nagios::service { "BPL_ping":
service_block => {
hostgroup_name => "bpl-servers",
check_command => "check_ping!100.0,20%!500.0,60%",
},
}
nagios::service { "BPL_load":
service_block => {
hostgroup_name => "bpl-servers",
check_command => "ss_load",
},
}
nagios::service { "BPL_swap":
service_block => {
hostgroup_name => "bpl-servers",
check_command => "ss_swap",
},
}
}
node nagios {
$baseconfigdir="/etc/nagios3/conf.d"
$conf_file_srvs="services.cfg"
# Nagios service collection
datacat { "${baseconfigdir}/${conf_file_srvs}":
template => 'nagios/services.cfg.erb',
owner => "root",
group => "nagios",
mode => "0644",
}
Datacat_fragment <<| tag == "nagios_service" |>> { target => "${baseconfigdir}/${conf_file_srvs}" }
}
#modules/nagios/manifests/service.pp
define nagios::service ($service_block) {
# Service block
@@datacat_fragment { "${name}_${fqdn}":
tag => 'nagios_service',
data => { "$name" => $service_block, },
}
}
#nagios/services.cfg.erb
<% @data.keys.sort.each do |service| -%>
define service {
name <%= service -%>
<% @data[service].keys.sort.each do |field| %>
<%= field %> <%= @data[service][field] -%>
<% end %>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment