diff --git a/manifests/nagios/objects/template_rules.pp b/manifests/nagios/objects/template_rules.pp index 947dc5b..4cbb711 100644 --- a/manifests/nagios/objects/template_rules.pp +++ b/manifests/nagios/objects/template_rules.pp @@ -19,8 +19,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # @summary Class manages /etc/nagios/conf.d/templates.cfg through concat. -# @example cd_nagios::objects::templates { $name: -# ng_template_object => 'service', +# @example cd_nagios::nagios::objects::templates { 'generic contact': +# ng_template_object => 'contact', +# ng_template_object_name => 'generic-contact', # } ################################################################################ class cd_nagios::nagios::objects::template_rules ( @@ -45,10 +46,37 @@ class cd_nagios::nagios::objects::template_rules ( notify => Service[$ng_service], } - # example rule - cd_nagios::objects::templates { 'generic contact': + # basic templates + cd_nagios::nagios::objects::templates { 'generic contact': ng_template_object => 'contact', ng_template_object_name => 'generic-contact', } + cd_nagios::nagios::objects::templates { 'generic-host': + ng_template_object => 'host', + ng_template_object_name => 'generic-host', + } + cd_nagios::nagios::objects::templates { 'linux-server': + ng_template_object => 'host', + ng_template_object_name => 'linux-server', + ng_template_object_use => 'generic-host', + ng_notification_options => 'd,u,r', + } + cd_nagios::nagios::objects::templates { 'windows-server': + ng_template_object => 'host', + ng_template_object_name => 'windows-server', + ng_template_object_use => 'generic-host', + ng_notification_options => 'd,u,r', + } + cd_nagios::nagios::objects::templates { 'generic-service': + ng_template_object => 'service', + ng_template_object_name => 'generic-service', + ng_max_check_attempts => '3', + ng_notification_options => 'w,u,c,r', + } + cd_nagios::nagios::objects::templates { 'local-service': + ng_template_object => 'service', + ng_template_object_name => 'generic-service', + ng_max_check_attempts => '4', + } } } diff --git a/manifests/nagios/objects/templates.pp b/manifests/nagios/objects/templates.pp index c9df353..ab7da62 100644 --- a/manifests/nagios/objects/templates.pp +++ b/manifests/nagios/objects/templates.pp @@ -20,7 +20,7 @@ # along with this program. If not, see . # @summary Define manages populates /etc/nagios/conf.d/templates.cfg. # @param [string] ng_template_object the object type for the templates. -# valid options are `contact`, `host` and `service`. +# Valid options are `contact`, `host` and `service`. # @param [string] ng_template_object_name populates the name field, # i.e. `generic-contact`, `generic-host`, `generic-service`. # @param [string] ng_svc_notification_period Period in which to send out @@ -41,7 +41,7 @@ # u = notify on UNREACHABLE host states, # r = notify on host recoveries (UP states), # f = notify when the host starts and stops flapping, -# s = snotify when host or service scheduled downtime starts and ends. +# s = notify when host or service scheduled downtime starts and ends. # n = none (the contact will not receive any type of host notifications). # @param [string] ng_service_notification_commands Command to use for # service event notification. Command must be defined in commands.cfg @@ -49,6 +49,54 @@ # host event notification. Command must be defined in commands.cfg. # @param [string] ng_object_register Whether to register the object to Nagios. # Since this is a template definition, we do not want to register those. +# @param [string] ng_template_object_use Which template to use for a given +# host or service definition, i.e. `generic-host`, `generic-service` etc. +# @param [string] ng_notifications_enabled Whether notifications are enabled. +# Valid options are `0` and `1`. +# @param [string] ng_event_handler_enabled Whether event handlers are enabled. +# Valid options are `0` and `1`. +# @param [string] ng_flap_detection_enabled Whether flap detection is enabled. +# Valid options are `0` and `1`. +# @param [string] ng_failure_prediction_enabled Whether failure prediction is +# enabled. Valid options are `0` and `1`. +# @param [string] ng_process_perf_data Whether to process performance data. +# Valid options are `0` and `1`. +# @param [string] ng_retain_status_information Whether to retain status +# information. Valid options are `0` and `1`. +# @param [string] ng_retain_nonstatus_information Whether to retain non-status +# information. Valid options are `0` and `1`. +# @param [string] ng_notification_period Which period in to send out +# notifications. for the defined service or host. +# @param [string] ng_notification_interval Whoe often (in minutes) we should +# resend notifications for the current status. +# @param [string] ng_check_period Which period in to run checks for the defined +# object. +# @param [string] ng_check_interval How often in minutes to check the defined +# object. +# @param [string] ng_retry_interval at what interval in minutes to schedule +# retries for the defined object. +# @param [string] ng_max_check_attempts how often to check the defined object +# maximal. +# @param [string] ng_notification_options see `ng_service_notification_options` +# and `ng_host_notification_options`. +# @param [string] ng_contact_groups contact groups for the defined oject. +# Specified contact group must exit in contact_groups +# @param [string] ng_active_checks_enabled Whether to enable active checks. +# Valid options are `0` and `1`. +# @param [string] ng_passive_checks_enabled Whether to enable passive checks. +# Valid options are `0` and `1`. +# @param [string] ng_parallelize_check Whether to parallelize checks +# Valid options are `0` and `1`. +# @param [string] ng_obsess_over_service Whether to obsess over the service. +# Valid options are `0` and `1`. +# @param [string] ng_check_freshness Whether to check freshness. +# Valid options are `0` and `1`. +# @param [string] ng_is_volatile Whether the service is volatile. +# Valid options are `0` and `1`. +# @param [string] ng_normal_check_interval How often to check the service +# under normal conditions. +# @param [string] ng_retry_check_interval Re-check the service every x minutes +# until a hard state can be determined. ################################################################################ define cd_nagios::nagios::objects::templates ( $ng_template_object = undef, @@ -60,6 +108,32 @@ $ng_host_notification_options = 'd,u,r,f,s', $ng_service_notification_commands = 'notify-service-by-email', $ng_host_notification_commands = 'notify-host-by-email', $ng_object_register = '0', +$ng_template_object_use = undef, +$ng_notifications_enabled = '1', +$ng_event_handler_enabled = '1', +$ng_flap_detection_enabled = '1', +$ng_failure_prediction_enabled = '1', +$ng_process_perf_data = '1', +$ng_retain_status_information = '1', +$ng_retain_nonstatus_information = '1', +$ng_notification_period = '24x7', +$ng_notification_interval = '30', +$ng_check_period = '24x7', +$ng_check_interval = '5', +$ng_retry_interval = '1', +$ng_max_check_attempts = '10', +$ng_check_command = 'check-host-alive', +$ng_notification_options = undef, +$ng_contact_groups = 'admins', +$ng_active_checks_enabled = '1', +$ng_passive_checks_enabled = '1', +$ng_parallelize_check = '1', +$ng_obsess_over_service = '1', +$ng_check_freshness = '0', +$ng_is_volatile = '0', +$ng_normal_check_interval = '10', +$ng_retry_check_interval = '2', + ) { $ng_nagios_server = $::cd_nagios::params::ng_nagios_server diff --git a/templates/nagios/templates_cfg_rule.erb b/templates/nagios/templates_cfg_rule.erb index b5a213d..2c00f14 100644 --- a/templates/nagios/templates_cfg_rule.erb +++ b/templates/nagios/templates_cfg_rule.erb @@ -1,18 +1,133 @@ <% if @ng_template_object == 'contact' -%> define <%= @ng_template_object %>{ - name <%= @ng_template_object_name %> ; - service_notification_period <%= @ng_svc_notification_period %> ; - host_notification_period <%= @ng_host_notification_period %> ; - service_notification_options <%= @ng_service_notification_options %> ; - host_notification_options <%= @ng_host_notification_options %> ; - service_notification_commands <%= @ng_service_notification_commands %> ; - host_notification_commands <%= @ng_host_notification_commands %> ; - register <%= @ng_object_register %> ; + name <%= @ng_template_object_name %> + service_notification_period <%= @ng_svc_notification_period %> + host_notification_period <%= @ng_host_notification_period %> + service_notification_options <%= @ng_service_notification_options %> + host_notification_options <%= @ng_host_notification_options %> + service_notification_commands <%= @ng_service_notification_commands %> + host_notification_commands <%= @ng_host_notification_commands %> + register <%= @ng_object_register %> } <% elsif @ng_template_object == 'host' -%> - -<% elsif @ng_template_object == 'service' -%> - - +<% if @ng_template_object_name == 'generic-host' -%> +define <%= @ng_template_object %>{ + name <%= @ng_template_object_name %> + notifications_enabled <%= @ng_notifications_enabled %> + event_handler_enabled <%= @ng_event_handler_enabled %> + flap_detection_enabled <%= @ng_flap_detection_enabled %> + failure_prediction_enabled <%= @ng_failure_prediction_enabled %> + process_perf_data <%= @ng_process_perf_data %> + retain_status_information <%= @ng_retain_status_information %> + retain_nonstatus_information <%= @ng_retain_nonstatus_information %> + notification_period <%= @ng_notification_period %> + register <%= @ng_object_register %> + } +<% end -%> +<% if @ng_template_object_name == 'linux-server' -%> +define <%= @ng_template_object %>{ + name <%= @ng_template_object_name %> + use <%= @ng_template_object_use %> + check_period <%= @ng_check_period %> + check_interval <%= @ng_check_interval %> + retry_interval <%= @ng_retry_interval %> + max_check_attempts <%= @ng_ng_max_check_attempts %> + check_command <%= @ng_check_command %> + notification_period <%= @ng_notification_period %> + notification_interval <%= @ng_notification_interval %> + notification_options <%= @ng_notification_options %> + contact_groups <%= @ng_contact_groups %> + hostgroups linux-servers + register <%= @ng_object_register %> + } +<% end %> +<% if @ng_template_object_name == 'windows-server' -%> +define <%= @ng_template_object %>{ + name <%= @ng_template_object_name %> + use <%= @ng_template_object_use %> + check_period <%= @ng_check_period %> + check_interval <%= @ng_check_interval %> + retry_interval <%= @ng_retry_interval %> + max_check_attempts <%= @ng_max_check_attempts %> + check_command <%= @ng_check_command %> + notification_period <%= @ng_notification_period %> + notification_interval <%= @ng_notification_interval %> + notification_options <%= @ng_notification_options %> + contact_groups <%= @ng_contact_groups %> + hostgroups windows-servers + register <%= @ng_object_register %> + } +<% end %> +<% if @ng_template_object_name == 'generic_printer' -%> +define <%= @ng_template_object %>{ + name <%= @ng_template_object_name %> + use <%= @ng_template_object_use %> + check_period <%= @ng_check_period %> + check_interval <%= @ng_check_interval %> + retry_interval <%= @ng_retry_interval %> + max_check_attempts <%= @ng_max_check_attempts %> + check_command <%= @ng_check_command %> + notification_period <%= @ng_notification_period %> + notification_interval <%= @ng_notification_interval %> + notification_options <%= @ng_notification_options %> + contact_groups <%= @ng_contact_groups %> + statusmap_image printer.png + register <%= @ng_object_register %> + } +<% end %> +<% if @ng_template_object_name == 'generic_switch' -%> +define <%= @ng_template_object %>{ + name <%= @ng_template_object_name %> + use <%= @ng_template_object_use %> + check_period <%= @ng_check_period %> + check_interval <%= @ng_check_interval %> + retry_interval <%= @ng_retry_interval %> + max_check_attempts <%= @ng_max_check_attempts %> + check_command <%= @ng_check_command %> + notification_period <%= @ng_notification_period %> + notification_interval <%= @ng_notification_interval %> + notification_options <%= @ng_notification_options %> + contact_groups <%= @ng_contact_groups %> + statusmap_image switch.png + register <%= @ng_object_register %> + } +<% end %> +<% elsif @ng_template_object == 'service' -%> +<% if @ng_template_object_name == 'generic-service' -%> +define <%= @ng_template_object %>{ + name <%= @ng_template_object_name %> + active_checks_enabled <%= @ng_active_checks_enabled %> + passive_checks_enabled <%= @ng_passive_checks_enabled %> + parallelize_check <%= @ng_parallelize_check %> + obsess_over_service <%= @ng_obsess_over_service %> + check_freshness <%= @ng_check_freshness %> + notifications_enabled <%= @ng_notifications_enabled %> + event_handler_enabled <%= @ng_event_handler_enabled %> + flap_detection_enabled <%= @ng_flap_detection_enabled %> + failure_prediction_enabled <%= @ng_failure_prediction_enabled %> + process_perf_data <%= @ng_process_perf_data %> + retain_status_information <%= @ng_retain_status_information %> + retain_nonstatus_information <%= @ng_retain_nonstatus_information %> + is_volatile <%= @ng_is_volatile %> + check_period <%= @ng_check_period %> + max_check_attempts <%= @ng_max_check_attempts %> + normal_check_interval <%= @ng_normal_check_interval %> + retry_check_interval <%= @ng_retry_check_interval %> + contact_groups <%= @ng_contact_groups %> + notification_interval <%= @ng_notification_interval %> + notification_period <%= @ng_notification_period %> + register <%= @ng_object_register %> + } +<% end -%> +<% if @ng_template_object_name == 'local-service' -%> +define <%= @ng_template_object %>{ + name <%= @ng_template_object_name %> + use <%= @ng_template_object_use %> + max_check_attempts <%= @ng_max_check_attempts %> + normal_check_interval <%= @ng_normal_check_interval %> + retry_check_interval <%= @ng_retry_check_interval %> + register <%= @ng_object_register %> + } +<% end -%> <% end -%>