diff --git a/README.md b/README.md index 6836aa3..7af9d6b 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ Configuration * configure selinux policies (optional) * configure forwarding http to https including accesing the /nagios url directly (optional) * manage TLS certificates through certbot (optional) +* manage `$user$` arguments in resource file via define Service * manage Nagios service on server diff --git a/manifests/nagios/resources/resource.pp b/manifests/nagios/resources/resource.pp new file mode 100644 index 0000000..d81f166 --- /dev/null +++ b/manifests/nagios/resources/resource.pp @@ -0,0 +1,67 @@ +## cd_nagios::nagios::resources::resource.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 the resource config file header. +# @example concat::fragment { "user_rule_plugins": +# ng_user_arg_name => "$user1$", +# ng_user_arg_value => '/usr/lib64/nagios/plugins', +# ng_user_arg_comment => "Sets $USER1$ to be the path to the plugins", +# } +############################################################################# +class cd_nagios::nagios::resources::resource ( + +) inherits cd_nagios::params { + + if $fqdn == $ng_nagios_server { + + concat { $ng_resource_file: + ensure => present, + owner => 'root', + group => $ng_user + mode => '0640', + selrange => s0, + selrole => object_r, + seltype => nagios_etc_t, + seluser => system_u, + notify => Service[$ng_service], + } + + concat::fragment { 'header': + target => $ng_resource_file, + content => template($ng_resource_erb), + order => '000', + } + + # plugins rule + + cd_nagios::nagios::resources::resource_df { 'user_rule_plugins': + ng_user_arg_name => "$user1$", + ng_user_arg_value => '/usr/lib64/nagios/plugins', + ng_user_arg_comment => "Sets $USER1$ to be the path to the plugins", + } + + # eventhandlers rule + cd_nagios::nagios::resources::resource_df { 'user_rule_eventhandlers': + ng_user_arg_name => "$user2$", + ng_user_arg_value => '/usr/lib64/nagios/plugins/eventhandlers', + ng_user_arg_comment => "Sets $USER1$ to be the path to the plugins", + } + } +} diff --git a/manifests/nagios/resources/resource_df.pp b/manifests/nagios/resources/resource_df.pp new file mode 100644 index 0000000..644be5a --- /dev/null +++ b/manifests/nagios/resources/resource_df.pp @@ -0,0 +1,45 @@ +## cd_nagios::nagios::resources::resource_df.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 manages the resources in/etc/nagios/private/resources.cfg +# @param [string] ng_user_arg_name the name of the user argument i.e. $user1$ +############################################################################# +define cd_nagios::nagios::resources::resource_df ( + +$ng_user_arg_name = undef, +$ng_user_arg_value = undef, +$ng_user_arg_comment = undef, +$ng_resource_rule_erb = '/cd_nagios/nagios/resource_cfg_rule.erb', + +) { + +$ng_nagios_server = $::cd_nagios::params::ng_nagios_server +$ng_resource_file = $::cd_nagios::params::ng_resource_file + + + if $fqdn == $ng_nagios_server { + + concat::fragment { "rule_${name}": + target => $ng_resource_file, + content => template($ng_resource_rule_erb), + order => '000', + } + } +} diff --git a/manifests/params.pp b/manifests/params.pp index 4958ca5..35845d7 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -649,6 +649,8 @@ # Puppet module and have enabled the check declaration from there, so the # Nagios check is properly aligned to the Puppet module controlling the # particular item. +# @param [string] ng_user_arg1 the user argument for $user1$ +# @param [string] ng_user_arg2 the user argument for $user2$ ############################################################################### class cd_nagios::params ( @@ -904,6 +906,9 @@ $ng_loadctl_options = 'jobs_max=100;backoff_limit=10;rampup_change=5', # single nagios checks $ng_enable_swap_check = true, +# resource.cfg +$ng_user_arg1 = '/usr/lib64/nagios/plugins', +$ng_user_arg2 = '/usr/lib64/nagios/plugins/eventhandlers', ) { @@ -964,6 +969,7 @@ $ng_ssl_vhost_file = '/etc/httpd/conf.d/nagios_ssl.conf' $ng_ssl_vhost_erb = 'cd_nagios/httpd/nagios_ssl_vhost.erb' $ng_nagios_cfg_file = "${ng_main_dir}/nagios.cfg" $ng_nagios_cfg_erb = 'cd_nagios/nagios/nagios_cfg.erb' +$ng_resource_erb = 'cd_nagios/nagios/resource_cfg.erb' # certbot $ng_certbot_main_dir = '/etc/letsencrypt' diff --git a/manifests/server/files.pp b/manifests/server/files.pp index aea971a..d6dcd5e 100644 --- a/manifests/server/files.pp +++ b/manifests/server/files.pp @@ -67,6 +67,25 @@ class cd_nagios::server::files ( notify => Service[$ng_service], } + # manage resources.cfg file + + file { $ng_resource_file: + ensure => file, + path => $ng_resource_file, + owner => 'root', + group => 'root', + mode => '0644', + selrange => s0, + selrole => object_r, + seltype => nagios_etc_t, + seluser => system_u, + content => template($ng_cgi_cfg_erb), + notify => Service[$ng_service], + } + + + + ## Apache files # since we use vhost files, we do not want the regular file to appear # after upgrades to avoid conflicts diff --git a/manifests/server/service.pp b/manifests/server/service.pp index 2ed1393..e898e8f 100644 --- a/manifests/server/service.pp +++ b/manifests/server/service.pp @@ -32,6 +32,7 @@ class cd_nagios::server::service ( require cd_nagios::server::files require cd_nagios::server::access_rules require cd_nagios::nagios::objects::config + require cd_nagios::nagios::resources::resource service { $ng_service: ensure => running, diff --git a/templates/nagios/resource_cfg.erb b/templates/nagios/resource_cfg.erb new file mode 100755 index 0000000..eca3279 --- /dev/null +++ b/templates/nagios/resource_cfg.erb @@ -0,0 +1,7 @@ +################################################################################ +##### resource.cfg created by Puppet | manual changes will be overwritten ##### +################################################################################ +##### full reference for the original available at ##### +##### https://confdroid.com/2018/04/nagios-resource-cfg/ ##### +################################################################################ +# $user$ arguments are created below through defines. diff --git a/templates/nagios/resource_cfg_rule.erb b/templates/nagios/resource_cfg_rule.erb new file mode 100644 index 0000000..65dab78 --- /dev/null +++ b/templates/nagios/resource_cfg_rule.erb @@ -0,0 +1,3 @@ + +# <%= @ng_user_arg_comment %> +<%= @ng_user_arg_name %>=<%= @ng_user_arg_value %>