1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#
# TDC: Test-driven configuration
#
# define for testing permissions of a list of files
#
# Copyright (C) 2020 Thorsten Alteholz
#
# 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 in version 2 of the License.
#
# 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 <https://www.gnu.org/licenses/>.
#
#
# @summary create tests for a list of files
#
# @example Basic usage
# define { 'tdc::test_file_permission':
# file => [
# {
# file => '/usr/sbin/ntpd',
# permission => '755',
# },
# }
#
# @param file
# Array of files to be tested
#
define tdc::test_file_permission (
Array $file = [],
String $nagiosout = "${::tdc::nagiosdir}/tdc-${::fqdn}-${title}-file-permission",
String $nagioscheck = "${::tdc::checkrootdir}/${::tdc::checkscriptdir}/check_tdc_file_permission",
String $tdctitle = $title,
) {
#) inherits tdc {
Exec {
path => ['/usr/bin', '/usr/sbin', '/bin'],
}
concat{ "${::tdc::checkrootdir}/${::tdc::checkconfigdir}/tdc_${title}-file-permission.cfg":
owner => 'root',
group => 'root',
mode => '0644',
}
concat::fragment{ "${::tdc::checkrootdir}/${::tdc::checkconfigdir}/tdc_${title}-file-permission.cfg header":
target => "${::tdc::checkrootdir}/${::tdc::checkconfigdir}/tdc_${title}-file-permission.cfg",
content => epp('tdc/tdc_config_header.epp', {'type' => 'test for files', 'cmn' => $title}),
order => '00',
}
generate ('/bin/bash', '-c',
"${::tdc::generator} ${nagiosout} service no dummy")
generate ('/bin/bash', '-c',
"${::tdc::generator} ${nagiosout} hostgroup no dummy ${::fqdn}")
# create the tests from the file array
$file.each | $f, $fff | {
concat::fragment { "${fff} ${f}":
target => "${::tdc::checkrootdir}/${::tdc::checkconfigdir}/tdc_${title}-file-permission.cfg",
content => "command[check_tdc_${title}-${f}-${::fqdn}-file-permission]=${nagioscheck} ${fff['file']} ${fff['permission']}\n",
notify => Service[$::tdc::nrpeservice],
}
generate ('/bin/bash', '-c',
"${::tdc::generator} ${nagiosout} service yes check_tdc_${title}-${f}-${::fqdn}-file-permission")
generate ('/bin/bash', '-c',
"${::tdc::generator} ${nagiosout} hostgroup yes check_tdc_${title}-${f}-${::fqdn}-file-permission ${::fqdn}")
}
if !defined(File["${tdc::checkrootdir}/${tdc::checkscriptdir}/check_tdc_file_permission"]) {
file{ "${::tdc::checkrootdir}/${::tdc::checkscriptdir}/check_tdc_file_permission":
ensure => file,
owner => 'root',
group => 'root',
mode => '0755',
path => "${::tdc::checkrootdir}/${::tdc::checkscriptdir}/check_tdc_file_permission",
content => epp('tdc/check_tdc_file_permission.epp'),
}
}
#III we don't need hosts yet:
# generate ("/bin/bash", "-c", "${::tdc::generator} ${::tdc::nagiosdir}/tdc-$fqdn-${title}-file-permission host no $fqdn")
}
|