Skip to content

Commit b6a4870

Browse files
author
Lennart Betz
committed
rewrite of features idomysql, idopgswl, influxdb2, influxdb, elasticsearch, gelf and icingadb
1 parent aae419e commit b6a4870

25 files changed

+656
-882
lines changed

examples/init_elasticsearch.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
include icinga2
22

33
class { 'icinga2::feature::elasticsearch':
4-
password => Sensitive('super(secret'),
4+
# password => Sensitive('super(secret'),
5+
password => 'super(secret',
56
}

examples/init_influxdb.pp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
}
44

55
class { 'icinga2::feature::influxdb':
6-
password => Sensitive('super(secret'),
6+
# password => Sensitive('super(secret'),
7+
password => 'super(secret',
78
basic_auth => {
89
username => 'icinga2',
9-
password => Sensitive('super(secret'),
10+
# password => Sensitive('super(secret'),
11+
password => 'super(secret',
1012
},
1113
}

examples/init_influxdb2.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
ensure => present,
77
organization => 'ICINGA',
88
bucket => 'icinga2',
9-
# auth_token => 'super(secret',
10-
auth_token => Sensitive('super(secret'),
9+
auth_token => 'super(secret',
10+
# auth_token => Sensitive('super(secret'),
1111
}

functions/cert.pp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
# Returned hash includes all paths and the key, cert and cacert.
66
#
77
function icinga2::cert(
8-
String $name,
9-
Optional[Stdlib::Absolutepath] $key_file = undef,
10-
Optional[Stdlib::Absolutepath] $cert_file = undef,
11-
Optional[Stdlib::Absolutepath] $cacert_file = undef,
12-
Optional[Variant[String, Sensitive]] $key = undef,
13-
Optional[String] $cert = undef,
14-
Optional[String] $cacert = undef,
8+
String $name,
9+
Optional[Stdlib::Absolutepath] $key_file = undef,
10+
Optional[Stdlib::Absolutepath] $cert_file = undef,
11+
Optional[Stdlib::Absolutepath] $cacert_file = undef,
12+
Optional[Variant[String, Sensitive[String]]] $key = undef,
13+
Optional[String] $cert = undef,
14+
Optional[String] $cacert = undef,
1515
) >> Hash {
1616
# @param name
1717
# The base name of certicate, key and ca file.
@@ -40,7 +40,13 @@ function icinga2::cert(
4040
$default_dir = $icinga2::globals::cert_dir
4141

4242
$result = {
43-
'key' => $key,
43+
'key' => if $key =~ Sensitive {
44+
$key
45+
} elsif $key =~ String {
46+
Sensitive($key)
47+
} else {
48+
undef
49+
},
4450
'key_file' => if $key {
4551
if $key_file {
4652
$key_file

functions/db/connect.pp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# @summary
2+
# This function returns a string to connect databases
3+
# with or without TLS information.
4+
#
5+
# @return
6+
# Connection string to connect database.
7+
#
8+
function icinga2::db::connect(
9+
Struct[{
10+
type => Enum['pgsql','mysql','mariadb'],
11+
host => Stdlib::Host,
12+
port => Optional[Stdlib::Port],
13+
database => String,
14+
username => String,
15+
password => Optional[Variant[String, Sensitive[String]]],
16+
}] $db,
17+
Hash[String, Any] $tls,
18+
Optional[Boolean] $use_tls = undef,
19+
) >> String {
20+
# @param db
21+
# Data hash with database information.
22+
#
23+
# @param tls
24+
# Data hash with TLS connection information.
25+
#
26+
# @param use_tls
27+
# Wether or not to use TLS encryption.
28+
#
29+
if $use_tls {
30+
case $db['type'] {
31+
'pgsql': {
32+
$tls_options = regsubst(join(any2array(delete_undef_values({
33+
'sslmode=' => if $tls['noverify'] { 'require' } else { 'verify-full' },
34+
'sslcert=' => $tls['cert_file'],
35+
'sslkey=' => $tls['key_file'],
36+
'sslrootcert=' => $tls['cacert_file'],
37+
})), ' '), '= ', '=', 'G')
38+
}
39+
'mariadb': {
40+
$tls_options = join(any2array(delete_undef_values({
41+
'--ssl' => '',
42+
'--ssl-ca' => $tls['cacert_file'],
43+
'--ssl-cert' => $tls['cert_file'],
44+
'--ssl-key' => $tls['key_file'],
45+
'--ssl-capath' => $tls['capath'],
46+
'--ssl-cipher' => $tls['cipher'],
47+
})), ' ')
48+
}
49+
'mysql': {
50+
$tls_options = join(any2array(delete_undef_values({
51+
'--ssl-mode' => 'required',
52+
'--ssl-ca' => $tls['cacert_file'],
53+
'--ssl-cert' => $tls['cert_file'],
54+
'--ssl-key' => $tls['key_file'],
55+
'--ssl-capath' => $tls['capath'],
56+
'--ssl-cipher' => $tls['cipher'],
57+
})), ' ')
58+
}
59+
default: {
60+
fail('The database type you provided is not supported.')
61+
}
62+
}
63+
} else {
64+
$tls_options = ''
65+
}
66+
67+
if $db['type'] == 'pgsql' {
68+
$options = regsubst(join(any2array(delete_undef_values({
69+
'host=' => $db['host'],
70+
'user=' => $db['username'],
71+
'port=' => $db['port'],
72+
'dbname=' => $db['database'],
73+
})), ' '), '= ', '=', 'G')
74+
} else {
75+
$_password = icinga2::unwrap($db['password'])
76+
$options = join(any2array(delete_undef_values({
77+
'-h' => $db['host'] ? {
78+
/localhost/ => undef,
79+
default => $db['host'],
80+
},
81+
'-P' => $db['port'],
82+
'-u' => $db['username'],
83+
"-p'${_password}'" => '',
84+
'-D' => $db['database'],
85+
})), ' ')
86+
}
87+
88+
"${options} ${tls_options}"
89+
}

functions/newline.pp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# @summary
2+
# Replace newlines for Windows systems.
3+
#
4+
# @return
5+
# Text with correct newlines.
6+
#
7+
function icinga2::newline(
8+
Optional[String] $text,
9+
) >> String {
10+
# @param text
11+
# Text to replace the newlines.
12+
#
13+
14+
if $text {
15+
$result = if $facts['os']['family'] != 'windows' {
16+
$text
17+
} else {
18+
regsubst($text, '\n', "\r\n", 'EMG')
19+
}
20+
} else {
21+
$result = undef
22+
}
23+
24+
return $result
25+
}

manifests/feature/api.pp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -249,43 +249,28 @@
249249
}
250250

251251
if $ssl_key {
252-
$_ssl_key = $facts['os']['family'] ? {
253-
'windows' => regsubst($ssl_key, '\n', "\r\n", 'EMG'),
254-
default => $ssl_key,
255-
}
256-
257252
file { $_ssl_key_path:
258253
ensure => file,
259254
mode => $_ssl_key_mode,
260-
content => $_ssl_key,
255+
content => icinga2::newline($ssl_key),
261256
tag => 'icinga2::config::file',
262257
show_diff => false,
263258
backup => false,
264259
}
265260
}
266261

267262
if $ssl_cert {
268-
$_ssl_cert = $facts['os']['family'] ? {
269-
'windows' => regsubst($ssl_cert, '\n', "\r\n", 'EMG'),
270-
default => $ssl_cert,
271-
}
272-
273263
file { $_ssl_cert_path:
274264
ensure => file,
275-
content => $_ssl_cert,
265+
content => icinga2::newline($ssl_cert),
276266
tag => 'icinga2::config::file',
277267
}
278268
}
279269

280270
if $ssl_cacert {
281-
$_ssl_cacert = $facts['os']['family'] ? {
282-
'windows' => regsubst($ssl_cacert, '\n', "\r\n", 'EMG'),
283-
default => $ssl_cacert,
284-
}
285-
286271
file { $_ssl_cacert_path:
287272
ensure => file,
288-
content => $_ssl_cacert,
273+
content => icinga2::newline($ssl_cacert),
289274
tag => 'icinga2::config::file',
290275
}
291276
}

0 commit comments

Comments
 (0)