From 51bec84a51a67745501c26f0ea490d99f6793dca Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Thu, 2 Sep 2021 19:57:38 +0200 Subject: [PATCH] fix #38 add director support --- examples/mysql/standalone.pp | 22 +++++++--- examples/pgsql/standalone.pp | 22 +++++++--- manifests/server.pp | 14 ++++++ manifests/web/director.pp | 68 ++++++++++++++++++++++++++++++ manifests/web/director/database.pp | 37 ++++++++++++++++ 5 files changed, 153 insertions(+), 10 deletions(-) create mode 100644 manifests/web/director.pp create mode 100644 manifests/web/director/database.pp diff --git a/examples/mysql/standalone.pp b/examples/mysql/standalone.pp index f43ff35..6956bb6 100644 --- a/examples/mysql/standalone.pp +++ b/examples/mysql/standalone.pp @@ -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': @@ -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, +} diff --git a/examples/pgsql/standalone.pp b/examples/pgsql/standalone.pp index b995fd3..21d32bf 100644 --- a/examples/pgsql/standalone.pp +++ b/examples/pgsql/standalone.pp @@ -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': @@ -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, +} diff --git a/manifests/server.pp b/manifests/server.pp index 1bc745e..18e46a8 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -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. # @@ -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, ) { @@ -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, diff --git a/manifests/web/director.pp b/manifests/web/director.pp new file mode 100644 index 0000000..129e43b --- /dev/null +++ b/manifests/web/director.pp @@ -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', + } + +} diff --git a/manifests/web/director/database.pp b/manifests/web/director/database.pp new file mode 100644 index 0000000..b0c0977 --- /dev/null +++ b/manifests/web/director/database.pp @@ -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', + } +} +