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
|
# File 'manifests/query_objects.pp', line 10
class icinga2::query_objects (
String[1] $destination = $facts['networking']['fqdn'],
Array[String[1]] $environments = [$environment],
) {
$_environments = if empty($environments) {
''
} else {
sprintf("environment in ['%s'] and", join($environments, "','"))
}
case $facts['os']['family'] {
'windows': {
} # windows
default: {
Concat {
owner => $icinga2::globals::user,
group => $icinga2::globals::group,
seltype => 'icinga2_etc_t',
mode => '0640',
}
} # default
}
$pql_query = puppetdb_query("resources[parameters] { ${_environments} type = 'Icinga2::Config::Fragment' and exported = true and tag = 'icinga2::instance::${destination}' and nodes { deactivated is null and expired is null } order by certname, title }")
$file_list = $pql_query.map |$object| {
$object['parameters']['target']
}
unique($file_list).each |$target| {
$objects = $pql_query.filter |$object| { $target == $object['parameters']['target'] }
$_content = $objects.reduce('') |String $memo, $object| {
"${memo}${object['parameters']['content']}"
}
if !defined(Concat[$target]) {
concat { $target:
ensure => present,
tag => 'icinga2::config::file',
warn => true,
}
}
concat::fragment { "custom-${target}":
target => $target,
content => $_content,
order => 99,
}
}
}
|