|
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, '6.0') >= 0 { |
28 | 34 | $schema_path = '/usr/share/zabbix-sql-scripts/mysql/' |
|
45 | 51 | case $zabbix_type { |
46 | 52 | 'proxy': { |
47 | 53 | $zabbix_proxy_create_sql = versioncmp($zabbix_version, '6.0') >= 0 ? { |
48 | | - 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", |
49 | | - 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" |
| 54 | + 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", |
| 55 | + 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" |
50 | 56 | } |
51 | 57 | } |
52 | 58 | default: { |
53 | 59 | $zabbix_server_create_sql = versioncmp($zabbix_version, '6.0') >= 0 ? { |
54 | | - 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", |
55 | | - 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" |
| 60 | + 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", |
| 61 | + 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" |
56 | 62 | } |
57 | 63 | $zabbix_server_images_sql = 'touch /etc/zabbix/.images.done' |
58 | 64 | $zabbix_server_data_sql = 'touch /etc/zabbix/.data.done' |
59 | 65 | } |
60 | 66 | } |
61 | 67 |
|
62 | 68 | # Loading the sql files. |
| 69 | + $_mysql_env = [ "database_password=${database_password_unsensitive}" ] |
63 | 70 | case $zabbix_type { |
64 | 71 | 'proxy' : { |
65 | 72 | exec { 'zabbix_proxy_create.sql': |
66 | 73 | command => $zabbix_proxy_create_sql, |
67 | 74 | path => "/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:${database_path}", |
68 | 75 | unless => 'test -f /etc/zabbix/.schema.done', |
69 | 76 | provider => 'shell', |
| 77 | + environment => $_mysql_env, |
70 | 78 | } |
71 | 79 | } |
72 | 80 | 'server' : { |
|
75 | 83 | path => "/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:${database_path}", |
76 | 84 | unless => 'test -f /etc/zabbix/.schema.done', |
77 | 85 | provider => 'shell', |
| 86 | + environment => $_mysql_env, |
78 | 87 | } |
79 | 88 | -> exec { 'zabbix_server_images.sql': |
80 | 89 | command => $zabbix_server_images_sql, |
81 | 90 | path => "/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:${database_path}", |
82 | 91 | unless => 'test -f /etc/zabbix/.images.done', |
83 | 92 | provider => 'shell', |
| 93 | + environment => $_mysql_env, |
84 | 94 | } |
85 | 95 | -> exec { 'zabbix_server_data.sql': |
86 | 96 | command => $zabbix_server_data_sql, |
87 | 97 | path => "/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:${database_path}", |
88 | 98 | unless => 'test -f /etc/zabbix/.data.done', |
89 | 99 | provider => 'shell', |
| 100 | + environment => $_mysql_env, |
90 | 101 | } |
91 | 102 | } |
92 | 103 | default : { |
|
0 commit comments