diff --git a/manifests/nagios/config.pp b/manifests/nagios/config.pp index 6ccffe9..12babde 100644 --- a/manifests/nagios/config.pp +++ b/manifests/nagios/config.pp @@ -8,7 +8,7 @@ class confdroid_nagios::nagios::config ( ) inherits confdroid_nagios::params { if $ng_nagios_server == $fqdn { require confdroid_nagios::nagios::objects::commands - #require confdroid_nagios::nagios::objects::template_rules + require confdroid_nagios::nagios::objects::template_rules require confdroid_nagios::nagios::objects::add_contact_rules require confdroid_nagios::nagios::objects::add_contactgroups_rules require confdroid_nagios::nagios::objects::add_hostgroup_rules diff --git a/manifests/nagios/objects/template_rules.pp b/manifests/nagios/objects/template_rules.pp new file mode 100644 index 0000000..fec088d --- /dev/null +++ b/manifests/nagios/objects/template_rules.pp @@ -0,0 +1,82 @@ +## confdroid_nagios::nagios::objects::template_rules.pp +# Module name: confdroid_nagios +# Author: 12ww1160 (12ww1160@confdroid.com) +# @summary Class manages /etc/nagios/conf.d/nagios_templates.cfg through +# concat. +# @example confdroid_nagios::nagios::objects::templates { 'generic contact': +# ng_template_object => 'contact', +# ng_template_object_name => 'generic-contact', +# } +################################################################################ +class confdroid_nagios::nagios::objects::template_rules ( + +) inherits confdroid_nagios::params { + if $ng_nagios_server == $fqdn { + # create the templates.cfg file + + concat { $ng_target_templates: + ensure => present, + path => $ng_target_templates, + owner => $ng_user, + group => $ng_user, + mode => '0640', + selrange => s0, + selrole => object_r, + seltype => nagios_etc_t, + seluser => system_u, + notify => Service[$ng_service], + } + + concat::fragment { 'template_header': + target => $ng_target_templates, + content => template($ng_templates_head_erb), + order => '000', + } + + # basic templates + confdroid_nagios::nagios::objects::templates { 'generic contact': + ng_template_object => 'contact', + ng_template_object_name => 'generic-contact', + } + confdroid_nagios::nagios::objects::templates { 'generic-host': + ng_template_object => 'host', + ng_template_object_name => 'generic-host', + } + confdroid_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', + } + confdroid_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', + } + confdroid_nagios::nagios::objects::templates { 'generic-switch': + ng_template_object => 'host', + ng_template_object_name => 'generic-switch', + ng_template_object_use => 'generic-host', + ng_notification_options => 'd,u,r', + } + confdroid_nagios::nagios::objects::templates { 'generic-printer': + ng_template_object => 'host', + ng_template_object_name => 'generic-printer', + ng_template_object_use => 'generic-host', + ng_notification_options => 'd,u,r', + } + confdroid_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', + } + confdroid_nagios::nagios::objects::templates { 'local-service': + ng_template_object => 'service', + ng_template_object_name => 'local-service', + ng_max_check_attempts => '4', + ng_template_object_use => 'generic-service', + } + } +} diff --git a/manifests/nagios/objects/templates.pp b/manifests/nagios/objects/templates.pp new file mode 100644 index 0000000..0a09850 --- /dev/null +++ b/manifests/nagios/objects/templates.pp @@ -0,0 +1,123 @@ +## confdroid_nagios::nagios::objects::templates.pp +# Module name: confdroid_nagios +# Author: 12ww1160 (12ww1160@confdroid.com) +# @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`. +# @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 +# notifications for service events, i.e. `24x7`. +# @param [String] ng_host_notification_period Period in which to send out +# notifications for host events , i.e. `24x7`. +# @param [String] ng_service_notification_options What service events to send +# out notifications for: +# w = notify on WARNING service states, +# u = notify on UNKNOWN service states, +# c = notify on CRITICAL service states, +# r = notify on service recoveries (OK states), +# f = notify when the service starts and stops flapping. +# n = none (the contact will not receive any type of service notifications). +# @param [String] ng_host_notification_options What host events to send +# out notifications for: +# d = notify on DOWN host states, +# u = notify on UNREACHABLE host states, +# r = notify on host recoveries (UP states), +# f = notify when the host starts and stops flapping, +# 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 +# @param [String] ng_host_notification_commands Command to use for +# 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_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 how 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_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 object. +# 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_check_interval How often to check the service +# under normal conditions. +# @param [String] ng_retry_interval Re-check the service every x minutes +# until a hard state can be determined. +# @param [String] ng_host_check_command the check command for host checks +################################################################################ +define confdroid_nagios::nagios::objects::templates ( + Optional[String] $ng_template_object = undef, + Optional[String] $ng_template_object_name = undef, + String $ng_svc_notification_period = '24x7', + String $ng_host_notification_period = '24x7', + String $ng_service_notification_options = 'w,u,c,r,f,s', + String $ng_host_notification_options = 'd,u,r,f,s', + String $ng_service_notification_commands = 'notify-service-by-email', + String $ng_host_notification_commands = 'notify-host-by-email', + String $ng_object_register = '0', + Optional[String] $ng_template_object_use = undef, + String $ng_notifications_enabled = '1', + String $ng_event_handler_enabled = '1', + String $ng_flap_detection_enabled = '1', + String $ng_process_perf_data = '1', + String $ng_retain_status_information = '1', + String $ng_retain_nonstatus_information = '1', + String $ng_notification_period = '24x7', + String $ng_notification_interval = '30', + String $ng_check_period = '24x7', + String $ng_check_interval = '5', + String $ng_retry_interval = '1', + String $ng_max_check_attempts = '10', + String $ng_host_check_command = 'check-host-alive', + Optional[String] $ng_notification_options = undef, + String $ng_contact_groups = 'admins', + String $ng_active_checks_enabled = '1', + String $ng_passive_checks_enabled = '1', + String $ng_parallelize_check = '1', + String $ng_obsess_over_service = '1', + String $ng_check_freshness = '0', + String $ng_is_volatile = '0', + +) { + $ng_nagios_server = $confdroid_nagios::params::ng_nagios_server + $ng_target_templates = $confdroid_nagios::params::ng_target_templates + $ng_templates_rule_erb = $confdroid_nagios::params::ng_templates_rule_erb + + if $ng_nagios_server == $fqdn { + concat::fragment { $name: + target => $ng_target_templates, + content => template($ng_templates_rule_erb), + } + } +} diff --git a/manifests/params.pp b/manifests/params.pp index a1a1bd5..b6257af 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -246,7 +246,7 @@ class confdroid_nagios::params ( $ng_cntctgrps_head_erb = 'confdroid_nagios/nagios/contactgroups_cfg_head.erb' $ng_cntctgrps_rule_erb = 'confdroid_nagios/nagios/contactgroups_cfg_rule.erb' $ng_target_command = "${ng_conf_d_dir}/nagios_commands_base.cfg" - $ng_service_cmd = 'check_nagios!/var/log/nagios/status.dat!5!/usr/sbin/nagios' + $ng_service_cmd = 'check_nagios!/var/log/nagios/status.dat!5!/usr/sbin/nagios' $ng_htpasswd_file = "${ng_main_dir}/passwd" $ng_htpasswd_head = 'confdroid_nagios/nagios/htpasswd_head.erb' $ng_htpasswd_rule = 'confdroid_nagios/nagios/htpasswd_rule.erb'