diff --git a/examples/init_idomysql.pp b/examples/init_idomysql.pp index b4f7e16..00eb654 100644 --- a/examples/init_idomysql.pp +++ b/examples/init_idomysql.pp @@ -1,21 +1,24 @@ include ::mysql::server mysql::db { 'icinga2': user => 'icinga2', password => 'supersecret', host => 'localhost', grant => ['SELECT', 'INSERT', 'UPDATE', 'DELETE', 'DROP', 'CREATE VIEW', 'CREATE', 'INDEX', 'EXECUTE', 'ALTER'], } class { '::icinga2': manage_repos => true, } class{ '::icinga2::feature::idomysql': user => 'icinga2', password => 'supersecret', database => 'icinga2', import_schema => true, require => Mysql::Db['icinga2'], + cleanup => { + hostchecks_age => '3m', + servicechecks_age => '36h', + }, } - diff --git a/manifests/feature/idomysql.pp b/manifests/feature/idomysql.pp index e063c1d..9e0a188 100644 --- a/manifests/feature/idomysql.pp +++ b/manifests/feature/idomysql.pp @@ -1,336 +1,336 @@ # @summary # Installs and configures the Icinga 2 feature ido-mysql. # # @example The ido-mysql featue requires an existing database and a user with permissions. This example uses the [puppetlabs/mysql](https://forge.puppet.com/puppetlabs/mysql) module. # include mysql::server # # mysql::db { 'icinga2': # user => 'icinga2', # password => 'supersecret', # host => 'localhost', # grant => ['SELECT', 'INSERT', 'UPDATE', 'DELETE', 'DROP', 'CREATE VIEW', 'CREATE', 'INDEX', 'EXECUTE', 'ALTER'], # } # # class{ 'icinga2::feature::idomysql': # user => "icinga2", # password => "supersecret", # database => "icinga2", # import_schema => true, # require => Mysql::Db['icinga2'] # } # # @param [Enum['absent', 'present']] ensure # Set to present enables the feature ido-mysql, absent disables it. # # @param [Stdlib::Host] host # MySQL database host address. # # @param [Optional[Stdlib::Port::Unprivileged]] port # MySQL database port. # # @param [Optional[Stdlib::Absolutepath]] socket_path # MySQL socket path. # # @param [String] user # MySQL database user with read/write permission to the icinga database. # # @param [String] password # MySQL database user's password. The password parameter isn't parsed anymore. # # @param [String] database # MySQL database name. # # @param [Boolean] enable_ssl # Either enable or disable SSL/TLS. Other SSL parameters are only affected if this is set to 'true'. # # @param [Optional[Stdlib::Absolutepath]] ssl_key_path # Location of the private key. Only valid if ssl is enabled. # # @param [Optional[Stdlib::Absolutepath]] ssl_cert_path # Location of the certificate. Only valid if ssl is enabled. # # @param [Optional[Stdlib::Absolutepath]] ssl_cacert_path # Location of the CA certificate. Only valid if ssl is enabled. # # @param [Optional[Stdlib::Base64]] ssl_key # The private key in a base64 encoded string to store in spicified ssl_key_path file. # Only valid if ssl is enabled. # # @param [Optional[Stdlib::Base64]] ssl_cert # The certificate in a base64 encoded string to store in spicified ssl_cert_path file. # Only valid if ssl is enabled. # # @param [Optional[Stdlib::Base64]] ssl_cacert # The CA root certificate in a base64 encoded string to store in spicified ssl_cacert_path file. # Only valid if ssl is enabled. # # @param [Optional[Stdlib::Absolutepath]] ssl_capath # MySQL SSL trusted SSL CA certificates in PEM format directory path. Only valid if ssl is enabled. # # @param [Optional[String]] ssl_cipher # MySQL SSL list of allowed ciphers. Only valid if ssl is enabled. # # @param [Optional[String]] table_prefix # MySQL database table prefix. # # @param [Optional[String]] instance_name # Unique identifier for the local Icinga 2 instance. # # @param [Optional[String]] instance_description # Description for the Icinga 2 instance. # # @param [Optional[Boolean]] enable_ha # Enable the high availability functionality. Only valid in a cluster setup. # # @param [Optional[Icinga2::Interval]] failover_timeout # Set the failover timeout in a HA cluster. Must not be lower than 60s. # -# @param [Optional[Hash[String,Icinga2::Interval]]] cleanup +# @param [Optional[Icinga2::IdoCleanup]] cleanup # Hash with items for historical table cleanup. # # @param [Optional[Array]] categories # Array of information types that should be written to the database. # # @param [Boolean] import_schema # Whether to import the MySQL schema or not. # class icinga2::feature::idomysql( - String $password, - Enum['absent', 'present'] $ensure = present, - Stdlib::Host $host = 'localhost', - Optional[Stdlib::Port::Unprivileged] $port = undef, - Optional[Stdlib::Absolutepath] $socket_path = undef, - String $user = 'icinga', - String $database = 'icinga', - Boolean $enable_ssl = false, - Optional[Stdlib::Absolutepath] $ssl_key_path = undef, - Optional[Stdlib::Absolutepath] $ssl_cert_path = undef, - Optional[Stdlib::Absolutepath] $ssl_cacert_path = undef, - Optional[Stdlib::Base64] $ssl_key = undef, - Optional[Stdlib::Base64] $ssl_cert = undef, - Optional[Stdlib::Base64] $ssl_cacert = undef, - Optional[Stdlib::Absolutepath] $ssl_capath = undef, - Optional[String] $ssl_cipher = undef, - Optional[String] $table_prefix = undef, - Optional[String] $instance_name = undef, - Optional[String] $instance_description = undef, - Optional[Boolean] $enable_ha = undef, - Optional[Icinga2::Interval] $failover_timeout = undef, - Optional[Hash[String,Icinga2::Interval]] $cleanup = undef, - Optional[Array] $categories = undef, - Boolean $import_schema = false, + String $password, + Enum['absent', 'present'] $ensure = present, + Stdlib::Host $host = 'localhost', + Optional[Stdlib::Port::Unprivileged] $port = undef, + Optional[Stdlib::Absolutepath] $socket_path = undef, + String $user = 'icinga', + String $database = 'icinga', + Boolean $enable_ssl = false, + Optional[Stdlib::Absolutepath] $ssl_key_path = undef, + Optional[Stdlib::Absolutepath] $ssl_cert_path = undef, + Optional[Stdlib::Absolutepath] $ssl_cacert_path = undef, + Optional[Stdlib::Base64] $ssl_key = undef, + Optional[Stdlib::Base64] $ssl_cert = undef, + Optional[Stdlib::Base64] $ssl_cacert = undef, + Optional[Stdlib::Absolutepath] $ssl_capath = undef, + Optional[String] $ssl_cipher = undef, + Optional[String] $table_prefix = undef, + Optional[String] $instance_name = undef, + Optional[String] $instance_description = undef, + Optional[Boolean] $enable_ha = undef, + Optional[Icinga2::Interval] $failover_timeout = undef, + Optional[Icinga2::IdoCleanup] $cleanup = undef, + Optional[Array] $categories = undef, + Boolean $import_schema = false, ) { if ! defined(Class['::icinga2']) { fail('You must include the icinga2 base class before using any icinga2 feature class!') } $owner = $::icinga2::globals::user $group = $::icinga2::globals::group $conf_dir = $::icinga2::globals::conf_dir $ssl_dir = $::icinga2::globals::cert_dir $ido_mysql_package_name = $::icinga2::globals::ido_mysql_package_name $ido_mysql_schema = $::icinga2::globals::ido_mysql_schema $manage_package = $::icinga2::manage_package $manage_packages = $::icinga2::manage_packages $_ssl_key_mode = $::facts['os']['family'] ? { 'windows' => undef, default => '0600', } $_notify = $ensure ? { 'present' => Class['::icinga2::service'], default => undef, } # to build mysql exec command to import schema if $import_schema { $_mysql_options = join(any2array(delete_undef_values({ '-h' => $host ? { /localhost/ => undef, default => $host, }, '-P' => $port, '-u' => $user, })), ' ') } File { owner => $owner, group => $group, } if $enable_ssl { # Set defaults for certificate stuff if $ssl_key { if $ssl_key_path { $_ssl_key_path = $ssl_key_path } else { $_ssl_key_path = "${ssl_dir}/IdoMysqlConnection_ido-mysql.key" } $_ssl_key = $::facts['os']['family'] ? { 'windows' => regsubst($ssl_key, '\n', "\r\n", 'EMG'), default => $ssl_key, } file { $_ssl_key_path: ensure => file, mode => $_ssl_key_mode, content => $ssl_key, tag => 'icinga2::config::file', } } else { $_ssl_key_path = $ssl_key_path } if $ssl_cert { if $ssl_cert_path { $_ssl_cert_path = $ssl_cert_path } else { $_ssl_cert_path = "${ssl_dir}/IdoMysqlConnection_ido-mysql.crt" } $_ssl_cert = $::facts['os']['family'] ? { 'windows' => regsubst($ssl_cert, '\n', "\r\n", 'EMG'), default => $ssl_cert, } file { $_ssl_cert_path: ensure => file, content => $ssl_cert, tag => 'icinga2::config::file', } } else { $_ssl_cert_path = $ssl_cert_path } if $ssl_cacert { if $ssl_cacert_path { $_ssl_cacert_path = $ssl_cacert_path } else { $_ssl_cacert_path = "${ssl_dir}/IdoMysqlConnection_ido-mysql_ca.crt" } $_ssl_cacert = $::facts['os']['family'] ? { 'windows' => regsubst($ssl_cacert, '\n', "\r\n", 'EMG'), default => $ssl_cacert, } file { $_ssl_cacert_path: ensure => file, content => $ssl_cacert, tag => 'icinga2::config::file', } } else { $_ssl_cacert_path = $ssl_cacert_path } if $import_schema { if $enable_ssl { $_ssl_options = join(any2array(delete_undef_values({ '--ssl' => '', '--ssl-ca' => $_ssl_cacert_path, '--ssl-cert' => $_ssl_cert_path, '--ssl-key' => $_ssl_key_path, '--ssl-capath' => $ssl_capath, '--ssl-cipher' => $ssl_cipher, })), ' ') } else { $_ssl_options = '' } # set cli options for mysql connection via tls $_mysql_command = "mysql ${_mysql_options} -p'${password}' ${_ssl_options} ${database}" } $attrs_ssl = { enable_ssl => $enable_ssl, ssl_ca => $_ssl_cacert_path, ssl_cert => $_ssl_cert_path, ssl_key => $_ssl_key_path, ssl_capath => $ssl_capath, ssl_cipher => $ssl_cipher, } } # enable_ssl else { # set cli options for mysql connection if $import_schema { $_mysql_command = "mysql ${_mysql_options} -p'${password}' ${database}" } $attrs_ssl = { enable_ssl => $enable_ssl } } $attrs = { host => $host, port => $port, socket_path => $socket_path, user => $user, password => "-:\"${password}\"", # The password parameter isn't parsed anymore. database => $database, table_prefix => $table_prefix, instance_name => $instance_name, instance_description => $instance_description, enable_ha => $enable_ha, failover_timeout => $failover_timeout, cleanup => $cleanup, categories => $categories, } # install additional package if $ido_mysql_package_name and ($manage_package or $manage_packages) { if $::facts['os']['family'] == 'debian' { ensure_resources('file', { '/etc/dbconfig-common' => { ensure => directory, owner => 'root', group => 'root' } }) file { "/etc/dbconfig-common/${ido_mysql_package_name}.conf": ensure => file, content => "dbc_install='false'\ndbc_upgrade='false'\ndbc_remove='false'\n", owner => 'root', group => 'root', mode => '0600', before => Package[$ido_mysql_package_name], } } # Debian package { $ido_mysql_package_name: ensure => installed, before => Icinga2::Feature['ido-mysql'], } } # import db schema if $import_schema { if $ido_mysql_package_name and ($manage_package or $manage_packages) { Package[$ido_mysql_package_name] -> Exec['idomysql-import-schema'] } exec { 'idomysql-import-schema': user => 'root', path => $::facts['path'], command => "${_mysql_command} < \"${ido_mysql_schema}\"", unless => "${_mysql_command} -Ns -e 'select version from icinga_dbversion'", } } # create object icinga2::object { 'icinga2::object::IdoMysqlConnection::ido-mysql': object_name => 'ido-mysql', object_type => 'IdoMysqlConnection', attrs => delete_undef_values(merge($attrs, $attrs_ssl)), attrs_list => concat(keys($attrs), keys($attrs_ssl)), target => "${conf_dir}/features-available/ido-mysql.conf", order => 10, notify => $_notify, } # import library concat::fragment { 'icinga2::feature::ido-mysql': target => "${conf_dir}/features-available/ido-mysql.conf", content => "library \"db_ido_mysql\"\n\n", order => '05', } icinga2::feature { 'ido-mysql': ensure => $ensure, } } diff --git a/manifests/feature/idopgsql.pp b/manifests/feature/idopgsql.pp index 0799bc1..87300c2 100644 --- a/manifests/feature/idopgsql.pp +++ b/manifests/feature/idopgsql.pp @@ -1,289 +1,289 @@ # @summary # Installs and configures the Icinga 2 feature ido-pgsql. # # @example The ido-pgsql featue requires an existing database and a user with permissions. This example uses the [puppetlab/postgresql](https://forge.puppet.com/puppetlabs/postgresql) module. # include icinga2 # include postgresql::server # # postgresql::server::db { 'icinga2': # user => 'icinga2', # password => postgresql_password('icinga2', 'supersecret'), # } # # class{ 'icinga2::feature::idopgsql': # user => 'icinga2', # password => 'supersecret', # database => 'icinga2', # import_schema => true, # require => Postgresql::Server::Db['icinga2'] # } # # @param [Enum['absent', 'present']] ensure # Set to present enables the feature ido-pgsql, absent disables it. # # @param [Stdlib::Host] host # PostgreSQL database host address. # # @param [Stdlib::Port::Unprivileged] port # PostgreSQL database port. # # @param [String] user # PostgreSQL database user with read/write permission to the icinga database. # # @param [String] password # PostgreSQL database user's password. The password parameter isn't parsed anymore. # # @param [String] database # PostgreSQL database name. # # @param [Optional[Enum[disable', 'allow', 'prefer', 'verify-full', 'varify-ca', 'require']]] ssl_mode # Enable SSL connection mode. # # @param [Optional[Stdlib::Absolutepath]] ssl_key_path # Location of the private key. # # @param [Optional[Stdlib::Absolutepath]] ssl_cert_path # Location of the certificate. # # @param [Optional[Stdlib::Absolutepath]] ssl_cacert_path # Location of the CA certificate. # # @param [Optional[Stdlib::Base64]] ssl_key # The private key in a base64 encoded string to store in spicified ssl_key_path file. # # @param [Optional[Stdlib::Base64]] ssl_cert # The certificate in a base64 encoded string to store in spicified ssl_cert_path file. # # @param [Optional[Stdlib::Base64]] ssl_cacert # The CA root certificate in a base64 encoded string to store in spicified ssl_cacert_path file. # # @param [Optional[String]] table_prefix # PostgreSQL database table prefix. # # @param [Optional[String]] instance_name # Unique identifier for the local Icinga 2 instance. # # @param [Optional[String]] instance_description # Description of the Icinga 2 instance. # # @param [Optional[Boolean]] enable_ha # Enable the high availability functionality. Only valid in a cluster setup. # # @param [Optional[Icinga2::Interval]] failover_timeout # Set the failover timeout in a HA cluster. Must not be lower than 60s. # -# @param [Optional[Hash]] cleanup +# @param [Optional[Icinga2::IdoCleanup]] cleanup # Hash with items for historical table cleanup. # # @param [Optional[Array]] categories # Array of information types that should be written to the database. # # @param [Boolean] import_schema # Whether to import the PostgreSQL schema or not. # class icinga2::feature::idopgsql( String $password, Enum['absent', 'present'] $ensure = present, Stdlib::Host $host = 'localhost', Stdlib::Port::Unprivileged $port = 5432, String $user = 'icinga', String $database = 'icinga', Optional[Enum[ 'disable', 'allow', 'prefer', 'verify-full', 'verify-ca', 'require']] $ssl_mode = undef, Optional[Stdlib::Absolutepath] $ssl_key_path = undef, Optional[Stdlib::Absolutepath] $ssl_cert_path = undef, Optional[Stdlib::Absolutepath] $ssl_cacert_path = undef, Optional[Stdlib::Base64] $ssl_key = undef, Optional[Stdlib::Base64] $ssl_cert = undef, Optional[Stdlib::Base64] $ssl_cacert = undef, Optional[String] $table_prefix = undef, Optional[String] $instance_name = undef, Optional[String] $instance_description = undef, Optional[Boolean] $enable_ha = undef, Optional[Icinga2::Interval] $failover_timeout = undef, - Optional[Hash] $cleanup = undef, + Optional[Icinga2::IdoCleanup] $cleanup = undef, Optional[Array] $categories = undef, Boolean $import_schema = false, ) { if ! defined(Class['::icinga2']) { fail('You must include the icinga2 base class before using any icinga2 feature class!') } $owner = $::icinga2::globals::user $group = $::icinga2::globals::group $conf_dir = $::icinga2::globals::conf_dir $ssl_dir = $::icinga2::globals::cert_dir $ido_pgsql_package_name = $::icinga2::globals::ido_pgsql_package_name $ido_pgsql_schema = $::icinga2::globals::ido_pgsql_schema $manage_package = $::icinga2::manage_package $manage_packages = $::icinga2::manage_packages $_notify = $ensure ? { 'present' => Class['::icinga2::service'], default => undef, } $_ssl_key_mode = $::facts['os']['family'] ? { 'windows' => undef, default => '0600', } File { owner => $owner, group => $group, } # Set defaults for certificate stuff if $ssl_key { if $ssl_key_path { $_ssl_key_path = $ssl_key_path } else { $_ssl_key_path = "${ssl_dir}/IdoPgsqlConnection_ido-pgsql.key" } $_ssl_key = $::facts['os']['family'] ? { 'windows' => regsubst($ssl_key, '\n', "\r\n", 'EMG'), default => $ssl_key, } file { $_ssl_key_path: ensure => file, mode => $_ssl_key_mode, content => $ssl_key, tag => 'icinga2::config::file', } } else { $_ssl_key_path = $ssl_key_path } if $ssl_cert { if $ssl_cert_path { $_ssl_cert_path = $ssl_cert_path } else { $_ssl_cert_path = "${ssl_dir}/IdoPgsqlConnection_ido-pgsql.crt" } $_ssl_cert = $::facts['os']['family'] ? { 'windows' => regsubst($ssl_cert, '\n', "\r\n", 'EMG'), default => $ssl_cert, } file { $_ssl_cert_path: ensure => file, content => $ssl_cert, tag => 'icinga2::config::file', } } else { $_ssl_cert_path = $ssl_cert_path } if $ssl_cacert { if $ssl_cacert_path { $_ssl_cacert_path = $ssl_cacert_path } else { $_ssl_cacert_path = "${ssl_dir}/IdoPgsqlConnection_ido-pgsql_ca.crt" } $_ssl_cacert = $::facts['os']['family'] ? { 'windows' => regsubst($ssl_cacert, '\n', "\r\n", 'EMG'), default => $ssl_cacert, } file { $_ssl_cacert_path: ensure => file, content => $ssl_cacert, tag => 'icinga2::config::file', } } else { $_ssl_cacert_path = $ssl_cacert_path } $attrs = { host => $host, port => $port, user => $user, password => "-:\"${password}\"", # The password parameter isn't parsed anymore. database => $database, ssl_mode => $ssl_mode, ssl_key => $_ssl_key_path, ssl_cert => $_ssl_cert_path, ssl_ca => $_ssl_cacert_path, table_prefix => $table_prefix, instance_name => $instance_name, instance_description => $instance_description, enable_ha => $enable_ha, failover_timeout => $failover_timeout, cleanup => $cleanup, categories => $categories, } # install additional package if $ido_pgsql_package_name and ($manage_package or $manage_packages) { if $::facts['os']['family'] == 'debian' { ensure_resources('file', { '/etc/dbconfig-common' => { ensure => directory, owner => 'root', group => 'root' } }) file { "/etc/dbconfig-common/${ido_pgsql_package_name}.conf": ensure => file, content => "dbc_install='false'\ndbc_upgrade='false'\ndbc_remove='false'\n", owner => 'root', group => 'root', mode => '0600', before => Package[$ido_pgsql_package_name], } } # Debian package { $ido_pgsql_package_name: ensure => installed, before => Icinga2::Feature['ido-pgsql'], } } # import db schema if $import_schema { if $ido_pgsql_package_name and ($manage_package or $manage_packages) { Package[$ido_pgsql_package_name] -> Exec['idopgsql-import-schema'] } $_connection = regsubst(join(any2array(delete_undef_values({ 'host=' => $host, 'sslmode=' => $ssl_mode, 'sslcert=' => $_ssl_cert_path, 'sslkey=' => $_ssl_key_path, 'sslrootcert=' => $_ssl_cacert_path, 'user=' => $user, 'port=' => $port, 'dbname=' => $database, })), ' '), '= ', '=', 'G') exec { 'idopgsql-import-schema': user => 'root', path => $::facts['path'], environment => ["PGPASSWORD=${password}"], command => "psql '${_connection}' -w -f '${ido_pgsql_schema}'", unless => "psql '${_connection}' -w -c 'select version from icinga_dbversion'", } } # create object icinga2::object { 'icinga2::object::IdoPgsqlConnection::ido-pgsql': object_name => 'ido-pgsql', object_type => 'IdoPgsqlConnection', attrs => delete_undef_values($attrs), attrs_list => keys($attrs), target => "${conf_dir}/features-available/ido-pgsql.conf", order => 10, notify => $_notify, } # import library concat::fragment { 'icinga2::feature::ido-pgsql': target => "${conf_dir}/features-available/ido-pgsql.conf", content => "library \"db_ido_pgsql\"\n\n", order => '05', } icinga2::feature { 'ido-pgsql': ensure => $ensure, } } diff --git a/types/idocleanup.pp b/types/idocleanup.pp new file mode 100644 index 0000000..a498989 --- /dev/null +++ b/types/idocleanup.pp @@ -0,0 +1,19 @@ +# A type for the structure of settings to cleanup IDO databases +type Icinga2::IdoCleanup = Hash[ + Enum[ + 'acknowledgements_age', + 'commenthistory_age', + 'contactnotifications_age', + 'contactnotificationmethods_age', + 'downtimehistory_age', + 'eventhandlers_age', + 'externalcommands_age', + 'flappinghistory_age', + 'hostchecks_age', + 'logentries_age', + 'notifications_age', + 'processevents_age', + 'statehistory_age', + 'servicechecks_age', + 'systemcommands_age', + ], String]