Puppet Class: icingaweb2::module::idoreports

Defined in:
manifests/module/idoreports.pp

Summary

Installs, configures and enables the idoreports module.

Overview

Note:

If you want to use ‘git` as `install_method`, the CLI `git` command has to be installed. You can manage it yourself as package resource or declare the package name in icingaweb2 class parameter `extra_packages`.

Examples:

class { 'icingaweb2::module::idoreports':
  git_revision  => 'v0.10.0',
}

Parameters:

  • ensure (Enum['absent', 'present'])

    Enable or disable module.

  • module_dir (Optional[Stdlib::Absolutepath]) (defaults to: undef)

    Target directory of the module.

  • git_repository (String)

    Set a git repository URL.

  • git_revision (Optional[String]) (defaults to: undef)

    Set either a branch or a tag name, eg. ‘master` or `v2.1.0`.

  • install_method (Enum['git', 'none', 'package'])

    Install methods are ‘git`, `package` and `none` is supported as installation method.

  • package_name (String)

    Package name of the module. This setting is only valid in combination with the installation method ‘package`.

  • import_schema (Variant[Boolean, Enum['mariadb', 'mysql']]) (defaults to: false)

    The IDO database needs some extensions for reorting. Whether to import the database extensions or not. Options ‘mariadb` and `mysql`, both means true. With mariadb its cli options are used for the import, whereas with mysql its different options.

  • ido_db_username (Optional[String]) (defaults to: $icingaweb2::module::monitoring::ido_db_username)

    An alternative username to login into the database. By default, the user from the ‘monitoring` module is used.

  • ido_db_password (Optional[Icingaweb2::Secret]) (defaults to: $icingaweb2::module::monitoring::ido_db_password)

    The password for the alternative user. By default, the password from the ‘monitoring` module is used.

  • use_tls (Optional[Boolean]) (defaults to: $icingaweb2::module::monitoring::use_tls)

    Either enable or disable TLS encryption to the database. Other TLS parameters are only affected if this is set to ‘true’. By default, same value from the ‘monitoring` module is used.

  • tls_key_file (Optional[Stdlib::Absolutepath]) (defaults to: $icingaweb2::module::monitoring::tls_key_file)

    Location of the private key for client authentication. Only valid if tls is enabled. By default, same value from the ‘monitoring` module is used.

  • tls_cert_file (Optional[Stdlib::Absolutepath]) (defaults to: $icingaweb2::module::monitoring::tls_cert_file)

    Location of the certificate for client authentication. Only valid if tls is enabled. By default, same value from the ‘monitoring` module is used.

  • tls_cacert_file (Optional[Stdlib::Absolutepath]) (defaults to: $icingaweb2::module::monitoring::tls_cacert_file)

    Location of the ca certificate. Only valid if tls is enabled. By default, same value from the ‘monitoring` module is used.

  • tls_key (Optional[Icingaweb2::Secret]) (defaults to: $icingaweb2::module::monitoring::tls_key)

    The private key to store in spicified ‘tls_key_file` file. Only valid if tls is enabled. By default, same value from the `monitoring` module is used.

  • tls_cert (Optional[String]) (defaults to: $icingaweb2::module::monitoring::tls_cert)

    The certificate to store in spicified ‘tls_cert_file` file. Only valid if tls is enabled. By default, same value from the `monitoring` module is used.

  • tls_cacert (Optional[String]) (defaults to: $icingaweb2::module::monitoring::tls_cacert)

    The ca certificate to store in spicified ‘tls_cacert_file` file. Only valid if tls is enabled. By default, same value from the `monitoring` module is used.

  • tls_capath (Optional[Stdlib::Absolutepath]) (defaults to: $icingaweb2::module::monitoring::tls_capath)

    The file path to the directory that contains the trusted SSL CA certificates, which are stored in PEM format. Only available for the mysql database. By default, same value from the ‘monitoring` module is used.

  • tls_noverify (Optional[Boolean]) (defaults to: $icingaweb2::module::monitoring::tls_noverify)

    Disable validation of the server certificate. By default, same value from the ‘monitoring` module is used.

  • tls_cipher (Optional[String]) (defaults to: $icingaweb2::module::monitoring::tls_cipher)

    Cipher to use for the encrypted database connection. By default, same value from the ‘monitoring` module is used.



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
# File 'manifests/module/idoreports.pp', line 81

class icingaweb2::module::idoreports (
  Enum['absent', 'present']                  $ensure,
  Enum['git', 'none', 'package']             $install_method,
  String                                     $git_repository,
  String                                     $package_name,
  Optional[Stdlib::Absolutepath]             $module_dir      = undef,
  Optional[String]                           $git_revision    = undef,
  Variant[Boolean, Enum['mariadb', 'mysql']] $import_schema   = false,
  Optional[String]                           $ido_db_username = $icingaweb2::module::monitoring::ido_db_username,
  Optional[Icingaweb2::Secret]               $ido_db_password = $icingaweb2::module::monitoring::ido_db_password,
  Optional[Boolean]                          $use_tls         = $icingaweb2::module::monitoring::use_tls,
  Optional[Stdlib::Absolutepath]             $tls_key_file    = $icingaweb2::module::monitoring::tls_key_file,
  Optional[Stdlib::Absolutepath]             $tls_cert_file   = $icingaweb2::module::monitoring::tls_cert_file,
  Optional[Stdlib::Absolutepath]             $tls_cacert_file = $icingaweb2::module::monitoring::tls_cacert_file,
  Optional[Stdlib::Absolutepath]             $tls_capath      = $icingaweb2::module::monitoring::tls_capath,
  Optional[Icingaweb2::Secret]               $tls_key         = $icingaweb2::module::monitoring::tls_key,
  Optional[String]                           $tls_cert        = $icingaweb2::module::monitoring::tls_cert,
  Optional[String]                           $tls_cacert      = $icingaweb2::module::monitoring::tls_cacert,
  Optional[Boolean]                          $tls_noverify    = $icingaweb2::module::monitoring::tls_noverify,
  Optional[String]                           $tls_cipher      = $icingaweb2::module::monitoring::tls_cipher,
) {
  unless defined(Class['icingaweb2::module::monitoring']) {
    fail('You must declare the icingaweb2::module::monitoring class before using icingaweb2::module::idoreports!')
  }

  $conf_dir          = $icingaweb2::globals::conf_dir
  $module_conf_dir   = "${conf_dir}/modules/idoreports"

  Exec {
    path     => $facts['path'],
    provider => shell,
    user     => 'root',
    require  => Icingaweb2::Module['idoreports'],
  }

  icingaweb2::module { 'idoreports':
    ensure         => $ensure,
    git_repository => $git_repository,
    git_revision   => $git_revision,
    install_method => $install_method,
    module_dir     => $module_dir,
    package_name   => $package_name,
    settings       => {
      'module-idoreports-config' => {
        target => "${module_conf_dir}/config.ini",
      },
    },
  }

  if $import_schema {
    $db = {
      type => $icingaweb2::module::monitoring::ido_type,
      host => $icingaweb2::module::monitoring::ido_host,
      port => pick($icingaweb2::module::monitoring::ido_port, $icingaweb2::globals::port[$icingaweb2::module::monitoring::ido_type]),
      name => $icingaweb2::module::monitoring::ido_db_name,
      user => $ido_db_username,
      pass => $ido_db_password,
    }

    $tls = merge(delete($icingaweb2::config::tls, ['key', 'cert', 'cacert']), delete_undef_values(merge(icingaweb2::cert::files(
            'client',
            $module_conf_dir,
            $tls_key_file,
            $tls_cert_file,
            $tls_cacert_file,
            $tls_key,
            $tls_cert,
            $tls_cacert,
          ), {
            capath   => $tls_capath,
            noverify => $tls_noverify,
            cipher   => $tls_cipher,
    })))

    icingaweb2::tls::client { 'icingaweb2::module::idoreports tls client config':
      args => $tls,
    }

    # determine the real dbms, because there are some differnces between
    # the mysql and mariadb client
    $real_db_type = if $import_schema =~ Boolean {
      if $db['type'] == 'pgsql' { 'pgsql' } else { 'mariadb' }
    } else {
      $import_schema
    }
    $db_cli_options = icingaweb2::db::connect($db + { type => $real_db_type }, $tls, $use_tls)

    case $db['type'] {
      'mysql': {
        exec { 'import slaperiods':
          command => "mysql ${db_cli_options} < '${icingaweb2::globals::mysql_idoreports_slaperiods}'",
          unless  => "mysql ${db_cli_options} -Ns -e 'SELECT 1 FROM icinga_sla_periods'",
        }
        exec { 'import get_sla_ok_percent':
          command => "mysql ${db_cli_options} < '${icingaweb2::globals::mysql_idoreports_sla_percent}'",
          unless  => "if [ \"X$(mysql ${db_cli_options} -Ns -e 'SELECT 1 FROM information_schema.routines WHERE routine_name=\"idoreports_get_sla_ok_percent\"')\" != \"X1\" ];then exit 1; fi",
        }
      }
      'pgsql': {
        $_db_password = icingaweb2::unwrap($db['pass'])
        exec { 'import slaperiods':
          environment => ["PGPASSWORD=${_db_password}"],
          command     => "psql '${db_cli_options}' -w -f ${icingaweb2::globals::pgsql_idoreports_slaperiods}",
          unless      => "psql '${db_cli_options}' -w -c 'SELECT 1 FROM icinga_outofsla_periods'",
        }
        exec { 'import get_sla_ok_percent':
          environment => ["PGPASSWORD=${_db_password}"],
          command     => "psql '${db_cli_options}' -w -f ${icingaweb2::globals::pgsql_idoreports_sla_percent}",
          unless      => "if [ \"X$(psql '${db_cli_options}' -w -t -c \"SELECT 1 FROM information_schema.routines WHERE routine_name='idoreports_get_sla_ok_percent'\"|xargs)\" != \"X1\" ];then exit 1; fi",
        }
      }
      default: {
        fail('The database type you provided is not supported.')
      }
    }
  }
}