|
11 | 11 | # @param database_path Path to the database executable |
12 | 12 | # @author Werner Dijkerman <[email protected]> |
13 | 13 | class zabbix::database::mysql ( |
14 | | - $zabbix_type = '', |
15 | | - $zabbix_version = $zabbix::params::zabbix_version, |
16 | | - $database_schema_path = '', |
17 | | - $database_name = '', |
18 | | - $database_user = '', |
19 | | - $database_password = '', |
20 | | - $database_host = '', |
21 | | - Optional[Stdlib::Port::Unprivileged] $database_port = undef, |
22 | | - $database_path = $zabbix::params::database_path, |
| 14 | + $zabbix_type = '', |
| 15 | + $zabbix_version = $zabbix::params::zabbix_version, |
| 16 | + $database_schema_path = '', |
| 17 | + $database_name = '', |
| 18 | + $database_user = '', |
| 19 | + Optional[Variant[String[1], Sensitive[String[1]]]] $database_password = '', |
| 20 | + $database_host = '', |
| 21 | + Optional[Stdlib::Port::Unprivileged] $database_port = undef, |
| 22 | + $database_path = $zabbix::params::database_path, |
23 | 23 | ) inherits zabbix::params { |
24 | 24 | assert_private() |
25 | 25 |
|
| 26 | + $database_password_unsensitive = if $database_password =~ Sensitive[String] { |
| 27 | + $database_password.unwrap |
| 28 | + } else { |
| 29 | + $database_password |
| 30 | + } |
| 31 | + |
26 | 32 | if ($database_schema_path == false) or ($database_schema_path == '') { |
27 | 33 | if versioncmp($zabbix_version, '5.4') >= 0 { |
28 | 34 | $schema_path = '/usr/share/doc/zabbix-sql-scripts/mysql/' |
|
43 | 49 | case $zabbix_type { |
44 | 50 | 'proxy': { |
45 | 51 | $zabbix_proxy_create_sql = versioncmp($zabbix_version, '6.0') >= 0 ? { |
46 | | - true => "cd ${schema_path} && mysql -h '${database_host}' -u '${database_user}' -p'${database_password}' ${port}-D '${database_name}' < proxy.sql && touch /etc/zabbix/.schema.done", |
47 | | - false => "cd ${schema_path} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && mysql -h '${database_host}' -u '${database_user}' -p'${database_password}' ${port}-D '${database_name}' < schema.sql && touch /etc/zabbix/.schema.done" |
| 52 | + true => "cd ${schema_path} && mysql -h '${database_host}' -u '${database_user}' -p\"\${database_password}\" ${port}-D '${database_name}' < proxy.sql && touch /etc/zabbix/.schema.done", |
| 53 | + false => "cd ${schema_path} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && mysql -h '${database_host}' -u '${database_user}' -p\"\${database_password}\" ${port}-D '${database_name}' < schema.sql && touch /etc/zabbix/.schema.done" |
48 | 54 | } |
49 | 55 | } |
50 | 56 | default: { |
51 | 57 | $zabbix_server_create_sql = versioncmp($zabbix_version, '6.0') >= 0 ? { |
52 | | - true => "cd ${schema_path} && if [ -f server.sql.gz ]; then gunzip -f server.sql.gz ; fi && mysql -h '${database_host}' -u '${database_user}' -p'${database_password}' ${port}-D '${database_name}' < server.sql && touch /etc/zabbix/.schema.done", |
53 | | - false => "cd ${schema_path} && if [ -f create.sql.gz ]; then gunzip -f create.sql.gz ; fi && mysql -h '${database_host}' -u '${database_user}' -p'${database_password}' ${port}-D '${database_name}' < create.sql && touch /etc/zabbix/.schema.done" |
| 58 | + true => "cd ${schema_path} && if [ -f server.sql.gz ]; then gunzip -f server.sql.gz ; fi && mysql -h '${database_host}' -u '${database_user}' -p\"\${database_password}\" ${port}-D '${database_name}' < server.sql && touch /etc/zabbix/.schema.done", |
| 59 | + false => "cd ${schema_path} && if [ -f create.sql.gz ]; then gunzip -f create.sql.gz ; fi && mysql -h '${database_host}' -u '${database_user}' -p\"\${database_password}\" ${port}-D '${database_name}' < create.sql && touch /etc/zabbix/.schema.done" |
54 | 60 | } |
55 | 61 | $zabbix_server_images_sql = 'touch /etc/zabbix/.images.done' |
56 | 62 | $zabbix_server_data_sql = 'touch /etc/zabbix/.data.done' |
57 | 63 | } |
58 | 64 | } |
59 | 65 |
|
60 | 66 | # Loading the sql files. |
| 67 | + $_mysql_env = [ "database_password=${database_password_unsensitive}" ] |
61 | 68 | case $zabbix_type { |
62 | 69 | 'proxy' : { |
63 | 70 | exec { 'zabbix_proxy_create.sql': |
64 | 71 | command => $zabbix_proxy_create_sql, |
65 | 72 | path => "/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:${database_path}", |
66 | 73 | unless => 'test -f /etc/zabbix/.schema.done', |
67 | 74 | provider => 'shell', |
| 75 | + environment => $_mysql_env, |
68 | 76 | } |
69 | 77 | } |
70 | 78 | 'server' : { |
|
73 | 81 | path => "/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:${database_path}", |
74 | 82 | unless => 'test -f /etc/zabbix/.schema.done', |
75 | 83 | provider => 'shell', |
| 84 | + environment => $_mysql_env, |
76 | 85 | } |
77 | 86 | -> exec { 'zabbix_server_images.sql': |
78 | 87 | command => $zabbix_server_images_sql, |
79 | 88 | path => "/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:${database_path}", |
80 | 89 | unless => 'test -f /etc/zabbix/.images.done', |
81 | 90 | provider => 'shell', |
| 91 | + environment => $_mysql_env, |
82 | 92 | } |
83 | 93 | -> exec { 'zabbix_server_data.sql': |
84 | 94 | command => $zabbix_server_data_sql, |
85 | 95 | path => "/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:${database_path}", |
86 | 96 | unless => 'test -f /etc/zabbix/.data.done', |
87 | 97 | provider => 'shell', |
| 98 | + environment => $_mysql_env, |
88 | 99 | } |
89 | 100 | } |
90 | 101 | default : { |
|
0 commit comments