From e76e4f857c4baf8af69b941b71460bad1c99401c Mon Sep 17 00:00:00 2001 From: Arne Teuke Date: Thu, 27 Jul 2017 15:28:21 +0100 Subject: [PATCH] added and linked add_timeperiods --- README.md | 1 + .../nagios/objects/add_timeperiod_rules.pp | 77 +++++++++++++++++++ manifests/nagios/objects/add_timeperiods.pp | 69 +++++++++++++++++ manifests/nagios/objects/config.pp | 2 +- manifests/nagios/objects/timeperiods.pp | 17 +++- manifests/params.pp | 5 +- templates/nagios/timeperiods_cfg_head.erb | 5 ++ templates/nagios/timeperiods_cfg_rule.erb | 18 +++++ 8 files changed, 190 insertions(+), 4 deletions(-) create mode 100644 manifests/nagios/objects/add_timeperiod_rules.pp create mode 100644 manifests/nagios/objects/add_timeperiods.pp create mode 100644 templates/nagios/timeperiods_cfg_head.erb create mode 100644 templates/nagios/timeperiods_cfg_rule.erb diff --git a/README.md b/README.md index 525768a..c3c1571 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ Configuration * manage Nagios main contactgroups through Puppet exports. Additional contact groups can be created through external Puppet rules via define, to avoid having to alter the module code. * manage Nagios main hostgroups through Puppet exports. Additional host groups can be created through external Puppet rules via define, to avoid having to alter the module code. * manage Nagios main servicegroups through Puppet exports. Additional service groups can be created through external Puppet rules via define, to avoid having to alter the module code. +* manage Nagios main timeperiods through Puppet exports. Additional timeperiods can be created through external Puppet rules via define, to avoid having to alter the module code. * configure NRPE on clients (optional) * configure firewall (optional) * configure selinux policies (optional) diff --git a/manifests/nagios/objects/add_timeperiod_rules.pp b/manifests/nagios/objects/add_timeperiod_rules.pp new file mode 100644 index 0000000..a590774 --- /dev/null +++ b/manifests/nagios/objects/add_timeperiod_rules.pp @@ -0,0 +1,77 @@ +# cd_nagios::nagios::objects::add_timeperiod_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_timeperiods_add.cfg. incl. +# additional timeperiods via define. +# cd_nagios::nagios::objects::add_timeperiods { 'example_timeperiod': +# ng_timeperiod_name => 'example_timeperiod', +# ng_timeperiod_alias => 'Example timeperiod', +# ng_timep_monday => '00:00-00:00', +# ng_timep_tuesday => '00:00-00:00', +# ng_timep_wednesday => '00:00-00:00', +# ng_timep_thursday => '00:00-00:00', +# ng_timep_friday => '00:00-00:00', +# ng_timep_saturday => '00:00-00:00', +# ng_timep_sunday => '00:00-00:00', +# } +################################################################################ +class cd_nagios::nagios::objects::add_timeperiod_rules ( + +) inherits cd_nagios::params { + + if $::fqdn == $ng_nagios_server { + + # manage /etc/nagios/conf.d/nagios_timeperiods_add.cfg + + concat { $ng_tgt_timeperiods_add: + ensure => present, + path => $ng_tgt_timeperiods_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 { 'timeperiods_header': + target => $ng_tgt_timeperiods_add, + content => template($ng_tgt_timep_head_erb), + order => '000', + } + + # example rule + cd_nagios::nagios::objects::add_timeperiods { 'example_timeperiod': + ng_timeperiod_name => 'example_timeperiod', + ng_timeperiod_alias => 'Example timeperiod', + ng_timep_monday => '00:00-00:00', + ng_timep_tuesday => '00:00-00:00', + ng_timep_wednesday => '00:00-00:00', + ng_timep_thursday => '00:00-00:00', + ng_timep_friday => '00:00-00:00', + ng_timep_saturday => '00:00-00:00', + ng_timep_sunday => '00:00-00:00', + } + } +} diff --git a/manifests/nagios/objects/add_timeperiods.pp b/manifests/nagios/objects/add_timeperiods.pp new file mode 100644 index 0000000..f33a823 --- /dev/null +++ b/manifests/nagios/objects/add_timeperiods.pp @@ -0,0 +1,69 @@ +## cd_nagios::nagios::objects::add_timeperiods.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 define populates /etc/nagios/conf.d/nagios_timeperiods_add through +# extermal Puppet rules. +# @example +# cd_nagios::nagios::objects::add_timeperiods { 'example_timeperiod': +# ng_timeperiod_name => 'example_timeperiod', +# ng_timeperiod_alias => 'Example timeperiod', +# } +# @param [string] ng_timep_name Specify the timeperiod short name. +# @param [string] ng_timep_alias Specify the timeperiod alias (long name) +# @param [string] ng_timep_monday Specify the desired hours for Monday +# @param [string] ng_timep_tuesday Specify the desired hours for Tuesday +# @param [string] ng_timep_wednesday Specify the desired hours for Wednesday. +# @param [string] ng_timep_thursday Specify the desired hours for Thursday +# @param [string] ng_timep_friday Specify the desired hours for Friday +# @param [string] ng_timep_saturday Specify the desired hours for Saturday +# @param [string] ng_timep_sunday Specify the desired hours for Sunday. +# @param [string] ng_timep_special_01 Specify a special date as key parameter +# for `ng_timep_special_02`. See Nagios documentation for format details. +# @param [string] ng_timep_special_02 Specify desired hours as value parameter +# for `g_timep_special_01`. +############################################################################### +define cd_nagios::nagios::objects::add_timeperiods ( + +$ng_timep_name = undef, +$ng_timep_alias = undef, +$ng_timep_monday = '00:00-00:00', +$ng_timep_tuesday = '00:00-00:00', +$ng_timep_wednesday = '00:00-00:00', +$ng_timep_thursday = '00:00-00:00', +$ng_timep_friday = '00:00-00:00', +$ng_timep_saturday = '00:00-00:00', +$ng_timep_sunday = '00:00-00:00', +$ng_timep_special_01 = undef, +$ng_timep_special_02 = '00:00-00:00', + +) { + +$ng_nagios_server = $::cd_nagios::params::ng_nagios_server +$ng_tgt_timep_add = $::cd_nagios::params::ng_tgt_timeperiod_add +$ng_tgt_timep_rule_erb = $::cd_nagios::params::ng_tgt_timep_rule_erb + + if $::fqdn == $ng_nagios_server { + + concat::fragment { $name: + target => $ng_tgt_timep_add, + content => template($ng_tgt_timep_rule_erb), + } + } +} diff --git a/manifests/nagios/objects/config.pp b/manifests/nagios/objects/config.pp index df37af5..822f5b0 100644 --- a/manifests/nagios/objects/config.pp +++ b/manifests/nagios/objects/config.pp @@ -37,6 +37,6 @@ class cd_nagios::nagios::objects::config ( require cd_nagios::nagios::objects::servicegroups require cd_nagios::nagios::objects::add_servicegroup_rules require cd_nagios::nagios::objects::timeperiods - + require cd_nagios::nagios::objects::add_timeperiod_rules } } diff --git a/manifests/nagios/objects/timeperiods.pp b/manifests/nagios/objects/timeperiods.pp index a292972..ac4f7c3 100644 --- a/manifests/nagios/objects/timeperiods.pp +++ b/manifests/nagios/objects/timeperiods.pp @@ -18,8 +18,8 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# @summary Class manages all timeperiods for NAGIOS through Puppet exports, -# and populates /etc/nagios/conf.d/nagios_timeperiods.cfg. +# @summary Class manages main timeperiods for NAGIOS through Puppet exports, +# and populates /etc/nagios/conf.d/nagios_timeperiods_base.cfg. ################################################################################ class cd_nagios::nagios::objects::timeperiods ( @@ -54,6 +54,8 @@ class cd_nagios::nagios::objects::timeperiods ( wednesday => '09:00-17:00', thursday => '09:00-17:00', friday => '09:00-17:00', + saturday => '00:00-00:00', + sunday => '00:00-00:00', owner => $ng_user, group => $ng_user, mode => '0640', @@ -78,5 +80,16 @@ class cd_nagios::nagios::objects::timeperiods ( register => '1', target => $ng_tgt_timeperiods_base, } + + @@nagios_timeperiod { 'none': + ensure => present, + timeperiod_name => 'none', + alias => 'No Time Is A Good Time', + owner => $ng_user, + group => $ng_user, + mode => '0640', + register => '1', + target => $ng_tgt_timeperiods_base, + } } } diff --git a/manifests/params.pp b/manifests/params.pp index 55fa492..0649557 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -964,7 +964,10 @@ $ng_certbot_live = "${ng_certbot_main_dir}/live" $ng_target_templates = "${ng_conf_d_dir}/nagios_templates.cfg" $ng_templates_head_erb = 'cd_nagios/nagios/templates_cfg_head.erb' $ng_templates_rule_erb = 'cd_nagios/nagios/templates_cfg_rule.erb' -$ng_tgt_timeperiods_base = "${ng_conf_d_dir}/timeperiods.cfg" +$ng_tgt_timeperiods_base = "${ng_conf_d_dir}/nagios_timeperiods.cfg" +$ng_tgt_timeperiods_add = "${ng_conf_d_dir}/nagios_timeperiods_add.cfg" +$ng_tgt_timep_head_erb = 'cd_nagios/nagios/timeperiods_cfg_head.erb' +$ng_tgt_timep_rule_erb = 'cd_nagios/nagios/timeperiods_cfg_rule.erb' $ng_target_localhost = "${ng_conf_d_dir}/nagios_localhost.cfg" $ng_target_host = "${ng_conf_d_dir}/nagios_host.cfg" $ng_target_hostgroup_base = "${ng_conf_d_dir}/nagios_hostgroups_base.cfg" diff --git a/templates/nagios/timeperiods_cfg_head.erb b/templates/nagios/timeperiods_cfg_head.erb new file mode 100644 index 0000000..133d7f3 --- /dev/null +++ b/templates/nagios/timeperiods_cfg_head.erb @@ -0,0 +1,5 @@ +############################################################################### +########## nagios_timeperiods_add.cfg created by Puppet ########## +########## manual changes are overwritten! ########## +############################################################################### +# rules are created below by external puppet rules. diff --git a/templates/nagios/timeperiods_cfg_rule.erb b/templates/nagios/timeperiods_cfg_rule.erb new file mode 100644 index 0000000..d68ae52 --- /dev/null +++ b/templates/nagios/timeperiods_cfg_rule.erb @@ -0,0 +1,18 @@ + +define timeperiod { + timeperiod_name <%= @ng_timeperiod_name %> + alias <%= @ng_timeperiod_alias %> + monday <%= @ng_timep_monday %> + tuesday <%= @ng_timep_tuesday %> + wednesday <%= @ng_timep_wednesday %> + thursday <%= @ng_timep_thursday %> + friday <%= @ng_timep_friday %> + saturday <%= @ng_timep_saturday %> + sunday <%= @ng_timep_sunday %> + } +<% unless @ng_timep_special_01.empty? -%> +define timeperiod { + timeperiod_name <%= @ng_timeperiod_name %> + @ng_timep_special_01 + } +<% end -%>