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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
# File 'manifests/database.pp', line 66
class zabbix::database (
$zabbix_type = 'server',
$zabbix_web = $zabbix::params::zabbix_web,
$zabbix_web_ip = $zabbix::params::zabbix_web_ip,
$zabbix_server = $zabbix::params::zabbix_server,
$zabbix_server_ip = $zabbix::params::zabbix_server_ip,
$zabbix_proxy = $zabbix::params::zabbix_proxy,
$zabbix_proxy_ip = $zabbix::params::zabbix_proxy_ip,
$manage_database = $zabbix::params::manage_database,
Zabbix::Databases $database_type = $zabbix::params::database_type,
$database_schema_path = $zabbix::params::database_schema_path,
$database_name = $zabbix::params::server_database_name,
$database_user = $zabbix::params::server_database_user,
$database_password = $zabbix::params::server_database_password,
$database_host = $zabbix::params::server_database_host,
$database_host_ip = $zabbix::params::server_database_host_ip,
$database_charset = $zabbix::params::server_database_charset,
$database_collate = $zabbix::params::server_database_collate,
Optional[String[1]] $database_tablespace = $zabbix::params::server_database_tablespace,
) inherits zabbix::params {
# So lets create the databases and load all files. This can only be
# happen when manage_database is set to true (Default).
if $manage_database == true {
# Complain if database_tablespace is set and the database_type is not postgresql
if ($database_tablespace and $database_type != 'postgresql') {
fail("database_tablespace is set to '${database_tablespace}'. This setting is only useful for PostgreSQL databases.")
}
case $database_type {
'postgresql': {
# This is the PostgreSQL part.
include postgresql::server
# Create the postgres database.
postgresql::server::db { $database_name:
user => $database_user,
owner => $database_user,
password => postgresql::postgresql_password($database_user, $database_password),
tablespace => $database_tablespace,
}
# When database not in some server with zabbix server include pg_hba_rule to server
if ($database_host_ip != $zabbix_server_ip) or ($zabbix_web_ip != $zabbix_server_ip) {
postgresql::server::pg_hba_rule { 'Allow zabbix-server to access database':
description => 'Open up postgresql for access from zabbix-server',
type => 'host',
database => $database_name,
user => $database_user,
address => "${zabbix_server_ip}/32",
auth_method => 'md5',
}
}
# When every component has its own server, we have to allow those servers to
# access the database from the network. Postgresql allows this via the
# pg_hba.conf file. As this file only accepts ip addresses, the ip address
# of server and web has to be supplied as an parameter.
if $zabbix_web_ip != $zabbix_server_ip {
postgresql::server::pg_hba_rule { 'Allow zabbix-web to access database':
description => 'Open up postgresql for access from zabbix-web',
type => 'host',
database => $database_name,
user => $database_user,
address => "${zabbix_web_ip}/32",
auth_method => 'md5',
}
} # END if $zabbix_web_ip != $zabbix_server_ip
# This is some specific action for the zabbix-proxy. This is due to better
# parameter naming.
if $zabbix_type == 'proxy' {
postgresql::server::pg_hba_rule { 'Allow zabbix-proxy to access database':
description => 'Open up postgresql for access from zabbix-proxy',
type => 'host',
database => $database_name,
user => $database_user,
address => "${zabbix_proxy_ip}/32",
auth_method => 'md5',
}
} # END if $zabbix_type == 'proxy'
}
'mysql': {
# This is the MySQL part.
include mysql::server
# First we check what kind of zabbix component it is. We have to use clear names
# as it may be confusing when you need to fill in the zabbix-proxy name into the
# zabbix_server parameter. These are 2 different things. So we need to use an
# if statement for this.
if $zabbix_type == 'server' {
mysql::db { $database_name:
user => $database_user,
password => $database_password,
charset => $database_charset,
collate => $database_collate,
host => $zabbix_server,
grant => ['all'],
require => Class['mysql::server'],
}
}
# And the proxy part.
if $zabbix_type == 'proxy' {
mysql::db { $database_name:
user => $database_user,
password => $database_password,
charset => $database_charset,
collate => $database_collate,
host => $zabbix_proxy,
grant => ['all'],
require => Class['mysql::server'],
}
}
# When the zabbix web and zabbix database aren't running on the same host, some
# extra users/grants needs to be created.
if $zabbix_web != $zabbix_server {
mysql_user { "${database_user}@${zabbix_web}":
ensure => 'present',
password_hash => mysql::password($database_password),
}
# And this is the grant part. It will grant the users which is created earlier
# to the zabbix-server database with all rights, like the user for the zabbix
# -server itself.
mysql_grant { "${database_user}@${zabbix_web}/${database_name}.*":
ensure => 'present',
options => ['GRANT'],
privileges => ['ALL'],
table => "${database_name}.*",
user => "${database_user}@${zabbix_web}",
require => [
Class['mysql::server'],
Mysql::Db[$database_name],
Mysql_user["${database_user}@${zabbix_web}"]
],
}
} # END if $zabbix_web != $zabbix_server
}
'sqlite': {
class { 'zabbix::database::sqlite': }
}
default: {
fail('Unrecognized database type for server.')
}
} # END case $database_type
}
}
|