diff --git a/data/common.yaml b/data/common.yaml index 927ed5b..ce95316 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -1,17 +1,18 @@ --- icingaweb2::conf_group: icingaweb2 icingaweb2::module::businessprocess::git_repository: https://github.com/Icinga/icingaweb2-module-businessprocess.git icingaweb2::module::cube::git_repository: https://github.com/Icinga/icingaweb2-module-cube.git icingaweb2::module::director::git_repository: https://github.com/Icinga/icingaweb2-module-director.git icingaweb2::module::elasticsearch::git_repository: https://github.com/Icinga/icingaweb2-module-elasticsearch.git icingaweb2::module::fileshipper::git_repository: https://github.com/Icinga/icingaweb2-module-fileshipper.git icingaweb2::module::generictts::git_repository: https://github.com/Icinga/icingaweb2-module-generictts.git icingaweb2::module::graphite::git_repository: https://github.com/Icinga/icingaweb2-module-graphite.git icingaweb2::module::incubator::git_repository: https://github.com/Icinga/icingaweb2-module-incubator.git icingaweb2::module::incubator::git_revision: v0.5.0 icingaweb2::module::ipl::git_repository: https://github.com/Icinga/icingaweb2-module-ipl.git icingaweb2::module::ipl::git_revision: v0.5.0 icingaweb2::module::puppetdb::git_repository: https://github.com/Icinga/icingaweb2-module-puppetdb.git icingaweb2::module::reactbundle::git_repository: https://github.com/Icinga/icingaweb2-module-reactbundle.git icingaweb2::module::reactbundle::git_revision: v0.7.0 icingaweb2::module::vsphere::git_repository: https://github.com/Icinga/icingaweb2-module-vsphere.git +icingaweb2::module::vspheredb::git_repository: https://github.com/Icinga/icingaweb2-module-vspheredb.git diff --git a/manifests/module/vspheredb.pp b/manifests/module/vspheredb.pp new file mode 100644 index 0000000..a12b111 --- /dev/null +++ b/manifests/module/vspheredb.pp @@ -0,0 +1,71 @@ +# @summary Installs the vsphereDB plugin +# +# @param Enum['absent', 'present'] ensure +# Ensur es the state of the vspheredb module. +# @param String git_repository +# The upstream module repository. +# @param Optional[String] git_revision +# The version of the module that needs to be used. +# @param Enum['mysql', 'pgsql'] db_type +# The database type. Either mysql or postgres. +# @param String db_host +# The host where the vspheredb-database will be running +# @param Integer[1,65535] db_port +# The port on which the database is accessible. +# @param String db_name +# The name of the database this module should use. +# @param String db_username +# The username needed to access the database. +# @param String db_password +# The password needed to access the database. +# @param String db_charset +# The charset the database is set to. +# +# @example +# class { 'icingaweb2::module::vspheredb': +# ensure => 'present', +# git_revision => 'v1.1.0', +# db_host => 'localhost', +# db_name => 'vspheredb', +# db_username => 'vspheredb', +# db_password => 'supersecret', +# } +# +class icingaweb2::module::vspheredb ( + String $git_repository, + Enum['absent', 'present'] $ensure = 'present', + Optional[String] $git_revision = undef, + Enum['mysql', 'pgsql'] $db_type = 'mysql', + Optional[Stdlib::Host] $db_host = undef, + Stdlib::Port $db_port = 3306, + Optional[String] $db_name = undef, + Optional[String] $db_username = undef, + Optional[String] $db_password = undef, + String $db_charset = 'utf8mb4', +){ + icingaweb2::config::resource { 'icingaweb2-module-vspheredb': + type => 'db', + db_type => $db_type, + host => $db_host, + port => $db_port, + db_name => $db_name, + db_username => $db_username, + db_password => $db_password, + db_charset => $db_charset, + } + + icingaweb2::module { 'vspheredb': + ensure => $ensure, + git_repository => $git_repository, + git_revision => $git_revision, + settings => { + 'icingaweb2-module-vspheredb' => { + 'section_name' => 'db', + 'target' => "${::icingaweb2::globals::conf_dir}/modules/vspheredb", + 'settings' => { + 'resource' => 'icingaweb2-module-vspheredb', + }, + }, + }, + } +} diff --git a/manifests/module/vspheredb/service.pp b/manifests/module/vspheredb/service.pp new file mode 100644 index 0000000..d5ac37d --- /dev/null +++ b/manifests/module/vspheredb/service.pp @@ -0,0 +1,51 @@ +# @summary Installs and configures the vspheredb service. +# +# @note Only systemd is supported by the Icinga Team and this module. +# +# @param [Stdlib::Ensure::Service] ensure +# Whether the vspheredb service should be running. +# @param [Boolean] enable +# Enable or disable the service. +# @param [String] user +# Specifies the user to run the vsphere service daemon as. +# @param [String] group +# Specifies the primary group to run the vspheredb service daemon as. +# @param [Boolean] manage_user +# Whether to manage the server user resource. +# +# @example +# include icingaweb2::module::vspheredb::service +# +class icingaweb2::module::vspheredb::service ( + Stdlib::Ensure::Service $ensure = 'running', + Boolean $enable = true, + String $user = 'icingavspheredb', + String $group = 'icingaweb2', + Boolean $manage_user = true, +) { + + require ::icingaweb2::module::vspheredb + + if $manage_user { + user { $user: + ensure => 'present', + gid => $group, + shell => '/bin/false', + before => Systemd::Unit_file['icinga-vspheredb.service'], + } + } + + systemd::unit_file { 'icinga-vspheredb.service': + ensure => 'present', + content => epp('icingaweb2/icinga-vspheredb.service.epp', { + 'conf_user' => $icingaweb2::conf_user, + 'icingacli_bin' => $icingaweb2::globals::icingacli_bin, + }), + notify => Service['icinga-vspheredb'], + } + + service {'icinga-vspheredb': + ensure => $ensure, + enable => $enable, + } +} diff --git a/spec/classes/vspheredb_service_spec.rb b/spec/classes/vspheredb_service_spec.rb new file mode 100644 index 0000000..09083f4 --- /dev/null +++ b/spec/classes/vspheredb_service_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe('icingaweb2::module::vspheredb::service', type: :class) do + let(:pre_condition) do + [ + "class { 'icingaweb2': }", + "class { 'icingaweb2::module::vspheredb': }", + ] + end + + on_supported_os.each do |os, facts| + context "on #{os}" do + let :facts do + facts + end + + context "#{os} with defaults" do + it do + is_expected.to contain_user('icingavspheredb') + .with( + 'ensure' => 'present', + 'gid' => 'icingaweb2', + 'shell' => '/bin/false', + ).that_comes_before('Systemd::Unit_file[icinga-vspheredb.service]') + end + it do + is_expected.to contain_systemd__unit_file('icinga-vspheredb.service').with( + content: %r{[Unit]}, + ).that_notifies('Service[icinga-vspheredb]') + end + it do + is_expected.to contain_service('icinga-vspheredb') + .with( + 'ensure' => 'running', + 'enable' => true, + ) + end + end + end + end +end diff --git a/spec/classes/vspheredb_spec.rb b/spec/classes/vspheredb_spec.rb new file mode 100644 index 0000000..9d8badf --- /dev/null +++ b/spec/classes/vspheredb_spec.rb @@ -0,0 +1,52 @@ +require 'spec_helper' + +describe('icingaweb2::module::vspheredb', type: :class) do + let(:pre_condition) do + [ + "class { 'icingaweb2': }", + ] + end + + on_supported_os.each do |os, facts| + context "on #{os}" do + let :facts do + facts + end + + context "#{os} with git_revision 'v1.1.0'" do + let(:params) do + { git_revision: 'v1.1.0', + db_host: 'localhost', + db_name: 'vspheredb', + db_username: 'vspheredb', + db_password: 'vspheredb' } + end + + it { + is_expected.to contain_icingaweb2__config__resource('icingaweb2-module-vspheredb') + .with_type('db') + .with_db_type('mysql') + .with_host('localhost') + .with_port('3306') + .with_db_name('vspheredb') + .with_db_username('vspheredb') + .with_db_password('vspheredb') + .with_db_charset('utf8mb4') + } + + it { + is_expected.to contain_icingaweb2__module('vspheredb') + .with_install_method('git') + .with_git_revision('v1.1.0') + .with_settings('icingaweb2-module-vspheredb' => { + 'section_name' => 'db', + 'target' => '/etc/icingaweb2/modules/vspheredb', + 'settings' => { + 'resource' => 'icingaweb2-module-vspheredb', + }, + }) + } + end + end + end +end diff --git a/templates/icinga-vspheredb.service.epp b/templates/icinga-vspheredb.service.epp new file mode 100644 index 0000000..aa33cdb --- /dev/null +++ b/templates/icinga-vspheredb.service.epp @@ -0,0 +1,23 @@ +<%- | + String $conf_user, + String $icingacli_bin, +| -%> +[Unit] +Description=Icinga vSphereDB Daemon +Documentation=https://icinga.com/docs/vsphere/latest/ +Wants=network.target + +[Service] +Type=notify +ExecStart=<%= $icingacli_bin %> vspheredb daemon run +User=<%= $conf_user %> +SyslogIdentifier=icingavspheredb + +NotifyAccess=main +WatchdogSec=10 + +Restart=on-failure +RestartSec=30 + +[Install] +WantedBy=multi-user.target