diff --git a/manifests/nagios/objects/add_contactgroups.pp b/manifests/nagios/objects/add_contactgroups.pp index 3bc3c32..b5e6fb0 100644 --- a/manifests/nagios/objects/add_contactgroups.pp +++ b/manifests/nagios/objects/add_contactgroups.pp @@ -23,15 +23,21 @@ ################################################################################ define cd_nagios::nagios::objects::add_contactgroups ( +$ng_contactgroup_name = undef, +$ng_contactgroup_alias = undef, +$ng_contactgroup_register = '1', ) { -$ng_nagios_server == $::cd_nagios::params::ng_nagios_server +$ng_nagios_server = $::cd_nagios::params::ng_nagios_server +$ng_tgt_contactgroup_add = $::cd_nagios::params::ng_tgt_contactgroup_add + if $::fqdn == $ng_nagios_server { - - - + concat::fragment { $name: + target => $ng_tgt_contactgroup_add, + content => template($ng_contacts_rule_erb), + } } } diff --git a/manifests/nagios/objects/add_contactgroups_rules.pp b/manifests/nagios/objects/add_contactgroups_rules.pp new file mode 100644 index 0000000..a50e671 --- /dev/null +++ b/manifests/nagios/objects/add_contactgroups_rules.pp @@ -0,0 +1,66 @@ +## cd_nagios::nagios::objects::add_contactgroups_rules.pp +# Module name: cd_nagios +# Author: Arne Teuke (arne_teuke@ConfDroid.com) +# # License: +# This file is part of cd_nagios. +# +# cd_nagios is used for providing automatic configuration of Nagios +# Copyright (C) 2016 ConfDroid (copyright@ConfDroid.com) +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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/nagios_add_contactgroups.cfg file +# and populates through define and external puppet rules +# @example +# cd_nagios::nagios::objects::add_contactgroups { 'example_group': +# ng_contactgroup_name => 'example_group', +# ng_contactgroup_alias => 'Example Group', +# ng_contactgroup_register '1', +# } +################################################################################ +class cd_nagios::nagios::objects::add_contactgroups_rules ( + + +) inherits cd_nagios::params { + + if $::fqdn == $ng_nagios_server { + + # manage /etc/nagios/conf.d/nagios_add_contactgroups.cfg + + concat { $ng_tgt_contactgroup_add: + ensure => present, + path => $ng_tgt_contactgroup_add, + owner => $ng_user, + group => $ng_user, + mode => '0640', + selrange => s0, + selrole => object_r, + seltype => nagios_etc_t, + seluser => system_u, + notify => Service[$ng_service], + } + + # manage file header + + concat::fragment { 'contactgroups_header': + target => $ng_tgt_contactgroup_add, + content => template($ng_cntctgrps_head_erb), + order => '000', + } + + cd_nagios::nagios::objects::add_contactgroups { 'example_group': + ng_contactgroup_name => 'example_group', + ng_contactgroup_alias => 'Example Group', + ng_contactgroup_register '1', + } + } +} diff --git a/manifests/params.pp b/manifests/params.pp index 37d50c5..1589b8a 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -976,6 +976,9 @@ $ng_target_add_contact = "${ng_conf_d_dir}/nagios_add_contact.cfg" $ng_contacts_head_erb = 'cd_nagios/nagios/contacts_cfg_head.erb' $ng_contacts_rule_erb = 'cd_nagios/nagios/contacts_cfg_rule.erb' $ng_tgt_contactgroup_base = "${ng_conf_d_dir}/nagios_contactgroup_base.cfg" +$ng_tgt_contactgroup_add = "${ng_conf_d_dir}/nagios_contactgroup_add.cfg" +$ng_cntctgrps_head_erb = 'cd_nagios/nagios/contactgroups_cfg_head.erb' +$ng_cntctgrps_rule_erb = 'cd_nagios/nagios/contactgroups_cfg_rule.erb' $ng_target_command = "${ng_conf_d_dir}/nagios_command.cfg" diff --git a/templates/nagios/contactgroups_cfg_head.erb b/templates/nagios/contactgroups_cfg_head.erb new file mode 100644 index 0000000..31e8a7b --- /dev/null +++ b/templates/nagios/contactgroups_cfg_head.erb @@ -0,0 +1,8 @@ +############################################################################### +########## nagios_add_contactgroups.cfg created by Puppet ########## +########## manual changes are overwritten! ########## +############################################################################### +########## Full reference file available at ########## +########## https://confdroid.com/2017/07/nagios-contacts-cfg/ ########## +############################################################################### +# rules are created below by external puppet rules. diff --git a/templates/nagios/contactgroups_cfg_rule.erb b/templates/nagios/contactgroups_cfg_rule.erb new file mode 100644 index 0000000..f4bbd98 --- /dev/null +++ b/templates/nagios/contactgroups_cfg_rule.erb @@ -0,0 +1,5 @@ +define contactgroup { + contactgroup_name <%= @ng_contactgroup_name %> + alias <%= @ng_contactgroup_alias %> + register <%= @ng_contactgroup_register %> + } diff --git a/templates/nagios/contacts_cfg.erb b/templates/nagios/contacts.cfg similarity index 100% rename from templates/nagios/contacts_cfg.erb rename to templates/nagios/contacts.cfg