Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple commandtransports #157

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,18 +511,8 @@ Username for IDO DB connection.
##### `ido_db_password`
Password for IDO DB connection.

##### `api_host`
The API host is your Icinga 2.

##### `api_port`
Port of your Icinga 2 API. Defaults to `5665`

##### `api_username`
API username. This is needed to send commands to the Icinga 2 core Make sure you have a proper `ApiUser` configuration
object configured in Icinga 2.

##### `api_password`
Password of the API user.
##### `commandtransports`
A hash of command transports.

#### Class: `icingaweb2::module::director`
Install and configure the director module.
Expand Down
41 changes: 8 additions & 33 deletions manifests/module/monitoring.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,8 @@
# [*ido_db_password*]
# Password for IDO DB connection.
#
# [*api_host*]
# The API host is your Icinga 2.
#
# [*api_port*]
# Port of your Icinga 2 API. Defaults to `5665`
#
# [*api_username*]
# API username. This is needed to send commands to the Icinga 2 core Make sure you have a proper `ApiUser`
# configuration object configured in Icinga 2.
#
# [*api_password*]
# Password of the API user.
# [*commandtransports*]
# A hash of command transports.
#
class icingaweb2::module::monitoring(
$ensure = 'present',
Expand All @@ -51,10 +41,7 @@
$ido_db_name = undef,
$ido_db_username = undef,
$ido_db_password = undef,
$api_host = 'localhost',
$api_port = 5665,
$api_username = undef,
$api_password = undef,
$commandtransports = undef,
){

$conf_dir = $::icingaweb2::params::conf_dir
Expand All @@ -70,10 +57,6 @@
validate_string($ido_db_name)
validate_string($ido_db_username)
validate_string($ido_db_password)
validate_string($api_host)
validate_numeric($api_port)
validate_string($api_username)
validate_string($api_password)

icingaweb2::config::resource { 'icingaweb2-module-monitoring':
type => 'db',
Expand All @@ -90,14 +73,6 @@
'resource' => 'icingaweb2-module-monitoring',
}

$commandtransport_settings = {
'transport' => 'api',
'host' => $api_host,
'port' => $api_port,
'username' => $api_username,
'password' => $api_password,
}

$config_settings = {
'protected_customvars' => $protected_customvars
}
Expand All @@ -108,18 +83,18 @@
'target' => "${module_conf_dir}/backends.ini",
'settings' => delete_undef_values($backend_settings)
},
'module-monitoring-commandtransports' => {
'section_name' => 'commandtransports',
'target' => "${module_conf_dir}/commandtransports.ini",
'settings' => delete_undef_values($commandtransport_settings)
},
'module-monitoring-config' => {
'section_name' => 'config',
'target' => "${module_conf_dir}/config.ini",
'settings' => delete_undef_values($config_settings)
}
}

if $commandtransports {
validate_hash($commandtransports)
create_resources('icingaweb2::module::monitoring::commandtransport', $commandtransports)
}

icingaweb2::module {'monitoring':
ensure => $ensure,
install_method => 'none',
Expand Down
80 changes: 80 additions & 0 deletions manifests/module/monitoring/commandtransport.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# == Define: icingaweb2::module::monitoring::commandtransport
#
# Manage commandtransport configuration for the monitoring module
#
# === Parameters
#
# [*commandtransport*]
# The name of the commandtransport.
#
# [*transport*]
# The transport type you wish to use. Either `api` or `local`. Defaults to `api`
#
# [*host*]
# Hostname/ip for the transport. Only needed for api transport. Defaults to `localhost`
#
# [*port*]
# Port for the transport. Only needed for api transport. Defaults to `5665`
#
# [*username*]
# Username for the transport. Only needed for api transport.
#
# [*password*]
# Password for the transport. Only needed for api transport.
#
# [*path*]
# Path for the transport. Only needed for local transport. Defaults to `/var/run/icinga2/cmd/icinga2.cmd`
#
define icingaweb2::module::monitoring::commandtransport(
$commandtransport = $title,
$transport = 'api',
$host = 'localhost',
$port = '5665',
$username = undef,
$password = undef,
$path = '/var/run/icinga2/cmd/icinga2.cmd',
){
assert_private("You're not supposed to use this defined type manually.")

$conf_dir = $::icingaweb2::params::conf_dir
$module_conf_dir = "${conf_dir}/modules/monitoring"

validate_string($commandtransport)
validate_re($transport, ['api', 'local' ],
"${transport} isn't supported. Valid values are 'api' or 'local'.")

case $transport {
'api': {
validate_string($host)
validate_numeric($port)
validate_string($username)
validate_string($password)

$commandtransport_settings = {
'transport' => $transport,
'host' => $host,
'port' => $port,
'username' => $username,
'password' => $password,
}
}
'local': {
validate_absolute_path($path)

$commandtransport_settings = {
'transport' => $transport,
'path' => $path,
}
}
default: {
fail('The transport type you provided is not supported')
}
}


icingaweb2::inisection { "monitoring-commandtransport-${commandtransport}":
section_name => $commandtransport,
target => "${module_conf_dir}/commandtransports.ini",
settings => delete_undef_values($commandtransport_settings),
}
}
79 changes: 68 additions & 11 deletions spec/classes/monitoring_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
facts
end

context "#{os} with ido_type 'mysql'" do
context "#{os} with ido_type 'mysql' and commandtransport 'api'" do
let(:params) { { :ido_type => 'mysql',
:ido_host => 'localhost',
:ido_db_name => 'icinga2',
:ido_db_username => 'icinga2',
:ido_db_password => 'icinga2',
:api_username => 'root',
:api_password => 'foobar' } }
:commandtransports => {
'foo' => {
'username' => 'root',
'password' => 'foobar',
}
} } }


it { is_expected.to contain_icingaweb2__module('monitoring')
Expand All @@ -32,15 +36,54 @@
'resource'=>'icingaweb2-module-monitoring'
}
},
'module-monitoring-commandtransports'=>{
'section_name' => 'commandtransports',
'target'=>'/etc/icingaweb2/modules/monitoring/commandtransports.ini',
'module-monitoring-config'=>{
'section_name' => 'config',
'target'=>'/etc/icingaweb2/modules/monitoring/config.ini',
'settings'=>{
'protected_customvars'=>'*pw*, *pass*, community'
}
}
}) }

it { is_expected.to contain_icingaweb2__config__resource('icingaweb2-module-monitoring')
.with_type('db')
.with_db_type('mysql')
.with_host('localhost')
.with_port('3306')
.with_db_name('icinga2')
.with_db_username('icinga2')
.with_db_password('icinga2')
}

it { is_expected.to contain_icingaweb2__module__monitoring__commandtransport('foo')
.with_username('root')
.with_password('foobar')
}
end

context "#{os} with ido_type 'pgsql' and commandtransport 'local'" do
let(:params) { { :ido_type => 'pgsql',
:ido_host => 'localhost',
:ido_port => 5432,
:ido_db_name => 'icinga2',
:ido_db_username => 'icinga2',
:ido_db_password => 'icinga2',
:commandtransports => {
'foo' => {
'transport' => 'local',
}
} } }

it { is_expected.to contain_icingaweb2__module('monitoring')
.with_install_method('none')
.with_module_dir('/usr/share/icingaweb2/modules/monitoring')
.with_settings({
'module-monitoring-backends'=>{
'section_name' => 'backends',
'target'=>'/etc/icingaweb2/modules/monitoring/backends.ini',
'settings'=>{
'transport'=>'api',
'host'=>'localhost',
'port'=>'5665',
'username'=>'root',
'password'=>'foobar'
'type'=>'ido',
'resource'=>'icingaweb2-module-monitoring'
}
},
'module-monitoring-config'=>{
Expand All @@ -51,6 +94,20 @@
}
}
}) }

it { is_expected.to contain_icingaweb2__config__resource('icingaweb2-module-monitoring')
.with_type('db')
.with_db_type('pgsql')
.with_host('localhost')
.with_port(5432)
.with_db_name('icinga2')
.with_db_username('icinga2')
.with_db_password('icinga2')
}

it { is_expected.to contain_icingaweb2__module__monitoring__commandtransport('foo')
.with_transport('local')
}
end

context "#{os} with invalid ido_type" do
Expand Down