adds resources

This commit is contained in:
Arne Teuke
2018-04-29 11:52:22 +02:00
parent 0c39f03373
commit 6b8ba84bc7
8 changed files with 149 additions and 0 deletions

View File

@@ -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

View File

@@ -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 <http://www.gnu.org/licenses/>.
# @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",
}
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
# @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',
}
}
}

View File

@@ -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'

View File

@@ -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

View File

@@ -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,

View File

@@ -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.

View File

@@ -0,0 +1,3 @@
# <%= @ng_user_arg_comment %>
<%= @ng_user_arg_name %>=<%= @ng_user_arg_value %>