Add module graphite

This commit is contained in:
Tom De Vylder 2015-04-22 15:24:44 +02:00
parent d56c51c3f7
commit b2817fc85f
2 changed files with 197 additions and 0 deletions

74
manifests/mod/graphite.pp Normal file
View file

@ -0,0 +1,74 @@
# == Class icingaweb2::mod::graphite
#
class icingaweb2::mod::graphite (
$git_repo = 'https://github.com/philiphoy/icingaweb2-module-graphite.git',
$git_revision = undef,
$graphite_base_url = 'http://graphite.com/render?',
$graphite_metric_prefix = 'icinga',
$install_method = 'git',
$pkg_deps = undef,
$pkg_ensure = 'present',
$web_root = $::icingaweb2::params::web_root,
) {
require ::icingaweb2
validate_absolute_path($web_root)
validate_re($install_method,
[
'git',
]
)
File {
require => Class['::icingaweb2::config'],
owner => $::icingaweb2::config_user,
group => $::icingaweb2::config_group,
mode => $::icingaweb2::config_file_mode,
}
file {
"${web_root}/modules/graphite":
ensure => directory,
mode => $::icingaweb2::config_dir_mode;
"${::icingaweb2::config_dir}/modules/graphite":
ensure => directory,
mode => $::icingaweb2::config_dir_mode;
}
Ini_Setting {
ensure => present,
require => File["${::icingaweb2::config_dir}/modules/graphite"],
path => "${::icingaweb2::config_dir}/modules/graphite/config.ini",
}
ini_setting { 'base_url':
section => 'graphite',
setting => 'base_url',
value => $graphite_base_url,
}
ini_setting { 'metric_prefix':
section => 'graphite',
setting => 'metric_prefix',
value => $graphite_metric_prefix,
}
if $install_method == 'git' {
if $pkg_deps {
package { $pkg_deps:
ensure => $pkg_ensure,
before => Vcsrepo['graphite'],
}
}
vcsrepo { 'graphite':
ensure => present,
path => "${web_root}/modules/graphite",
provider => 'git',
revision => $git_revision,
source => $git_repo,
}
}
}

View file

@ -0,0 +1,123 @@
require 'spec_helper'
describe 'icingaweb2::mod::graphite', :type => :class do
let (:pre_condition) { '$concat_basedir = "/tmp"' }
let (:facts) { debian_facts }
let :pre_condition do
'include ::icingaweb2'
end
describe 'without parameters' do
it { should create_class('icingaweb2::mod::graphite') }
it { should contain_file('/usr/share/icingaweb2/modules/graphite') }
it { should contain_vcsrepo('graphite') }
end
describe 'with parameter: git_repo' do
let (:params) {
{
:install_method => 'git',
:git_repo => '_git_repo_'
}
}
it {
should contain_vcsrepo('graphite').with(
'path' => /modules\/graphite$/
)
}
end
describe 'with parameter: git_revision' do
let (:params) {
{
:install_method => 'git',
:git_revision => '_git_revision_'
}
}
it {
should contain_vcsrepo('graphite').with(
'revision' => /_git_revision_/
)
}
end
describe 'with parameter: graphite_base_url' do
let (:params) {
{
:graphite_base_url => '_graphite_base_url_'
}
}
it { should contain_ini_setting('base_url').with(
'section' => /graphite/,
'setting' => /base_url/,
'value' => /_graphite_base_url_/
)
}
end
describe 'with parameter: graphite_metric_prefix' do
let (:params) {
{
:graphite_metric_prefix => '_graphite_metric_prefix_'
}
}
it { should contain_ini_setting('metric_prefix').with(
'section' => /graphite/,
'setting' => /metric_prefix/,
'value' => /_graphite_metric_prefix_/
)
}
end
describe 'with parameter: install_method' do
let (:params) {
{
:install_method => 'git'
}
}
it { should contain_vcsrepo('graphite') }
end
describe 'with parameter: pkg_deps' do
let (:params) {
{
:pkg_deps => '_pkg_deps_'
}
}
it { should contain_package('_pkg_deps_').with(
'ensure' => 'present'
)
}
end
describe 'with parameter: pkg_ensure' do
let (:params) {
{
:pkg_deps => '_pkg_deps_',
:pkg_ensure => '_pkg_ensure_'
}
}
it { should contain_package('_pkg_deps_').with(
'ensure' => '_pkg_ensure_'
)
}
end
describe 'with parameter: web_root' do
let (:params) {
{
:web_root => '/web/root'
}
}
it { should contain_file('/web/root/modules/graphite') }
end
end