Skip to content

Commit

Permalink
fix #38 add director support
Browse files Browse the repository at this point in the history
  • Loading branch information
lbetz committed Sep 23, 2021
1 parent 8a997a1 commit 51bec84
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 10 deletions.
22 changes: 17 additions & 5 deletions examples/mysql/standalone.pp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
class { '::icinga::repos':
manage_epel => true,
manage_epel => true,
manage_extras => true,
}

class { '::icinga::server':
ca => true,
config_server => true,
global_zones => [ 'global-templates', 'linux-commands', 'windows-commands' ],
web_api_pass => 'icingaweb2',
ca => true,
config_server => true,
global_zones => [ 'global-templates', 'linux-commands', 'windows-commands' ],
web_api_pass => 'icingaweb2',
director_api_pass => 'director',
}

class { '::icinga::ido':
Expand All @@ -26,3 +28,13 @@
manage_database => true,
api_pass => $icinga::server::web_api_pass,
}

class { '::icinga::web::director':
db_type => 'mysql',
db_host => 'localhost',
db_pass => 'director',
manage_database => true,
endpoint => $::fqdn,
api_host => 'localhost',
api_pass => $icinga::server::director_api_pass,
}
22 changes: 17 additions & 5 deletions examples/pgsql/standalone.pp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
class { '::icinga::repos':
manage_epel => true,
manage_epel => true,
manage_extras => true,
}

class { '::icinga::server':
ca => true,
config_server => true,
global_zones => [ 'global-templates', 'linux-commands', 'windows-commands' ],
web_api_pass => 'icingaweb2',
ca => true,
config_server => true,
global_zones => [ 'global-templates', 'linux-commands', 'windows-commands' ],
web_api_pass => 'icingaweb2',
director_api_pass => 'director',
}

class { '::icinga::ido':
Expand All @@ -26,3 +28,13 @@
manage_database => true,
api_pass => $icinga::server::web_api_pass,
}

class { '::icinga::web::director':
db_type => 'pgsql',
db_host => 'localhost',
db_pass => 'director',
manage_database => true,
endpoint => $::fqdn,
api_host => 'localhost',
api_pass => $icinga::server::director_api_pass,
}
14 changes: 14 additions & 0 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
# @param [Optional[String]] web_api_pass
# Icinga API user password.
#
# @param [String] director_api_user
# Icinga API director user to connect Icinga 2.
#
# @param [Optional[String]] director_api_pass
# Icinga API director user password.
#
# @param [Enum['file', 'syslog']] logging_type
# Switch the log target. Only `file` is supported on Windows.
#
Expand All @@ -50,6 +56,8 @@
Optional[String] $ticket_salt = undef,
String $web_api_user = 'icingaweb2',
Optional[String] $web_api_pass = undef,
String $director_api_user = 'director',
Optional[String] $director_api_pass = undef,
Enum['file', 'syslog'] $logging_type = 'file',
Optional[Icinga::LogLevel] $logging_level = undef,
) {
Expand Down Expand Up @@ -96,6 +104,12 @@
target => "/etc/icinga2/zones.d/${zone}/api-users.conf",
}

::icinga2::object::apiuser { $director_api_user:
password => $director_api_pass,
permissions => [ '*' ],
target => "/etc/icinga2/zones.d/${zone}/api-users.conf",
}

($global_zones + keys($_workers) + $zone).each |String $dir| {
file { "${::icinga2::globals::conf_dir}/zones.d/${dir}":
ensure => directory,
Expand Down
68 changes: 68 additions & 0 deletions manifests/web/director.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# @summary
# Setup Director module for Icinga Web 2
#
# @param [String] db_pass
# Password to connect the database.
#
class icinga::web::director(
String $db_pass,
String $api_pass,
String $endpoint,
Enum['mysql','pgsql'] $db_type = 'mysql',
Stdlib::Host $db_host = 'localhost',
Optional[Stdlib::Port] $db_port = undef,
String $db_name = 'director',
String $db_user = 'director',
Boolean $manage_database = false,
Stdlib::Host $api_host = 'localhost',
String $api_user = 'director',
) {

unless $db_port {
$_db_port = $db_type ? {
'pgsql' => 5432,
default => 3306,
}
} else {
$_db_port = $db_port
}

#
# Database
#
if $manage_database {
class { '::icinga::web::director::database':
db_type => $db_type,
db_name => $db_name,
db_user => $db_user,
db_pass => $db_pass,
web_instances => [ 'localhost' ],
before => Class['icingaweb2::module::director'],
}
$_db_host = 'localhost'
} else {
if $db_type != 'pgsql' {
include ::mysql::client
} else {
include ::postgresql::client
}
$_db_host = $db_host
}

class { 'icingaweb2::module::director':
install_method => 'package',
db_type => $db_type,
db_host => $_db_host,
db_name => $db_name,
db_username => $db_user,
db_password => $db_pass,
import_schema => true,
kickstart => true,
endpoint => $endpoint,
api_host => $api_host,
api_username => $api_user,
api_password => $api_pass,
db_charset => 'UTF8',
}

}
37 changes: 37 additions & 0 deletions manifests/web/director/database.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# @summary
# Setup Director database.
#
# @param [Enum['mysql','pgsql']] db_type
# What kind of database type to use.
#
# @param [Array[Stdlib::Host]] web_instances
# List of Hosts to allow write access to the database. Usually an Icinga Web 2 instance.
#
# @param [String] db_pass
# Password to connect the database.
#
# @param [String] db_name
# Name of the database.
#
# @param [String] db_user
# Database user name.
#
class icinga::web::director::database(
Enum['mysql','pgsql'] $db_type,
Array[Stdlib::Host] $web_instances,
String $db_pass,
String $db_name = 'director',
String $db_user = 'director',
) {

::icinga::database { "${db_type}-${db_name}":
db_type => $db_type,
db_name => $db_name,
db_user => $db_user,
db_pass => $db_pass,
access_instances => $web_instances,
mysql_privileges => ['ALL'],
db_encoding => 'UTF8',
}
}

0 comments on commit 51bec84

Please sign in to comment.