Add collectd-sensubility configuration

This patch adds possibility to configure collectd-exec to execute
collectd-sensubility and configure this extension.

Change-Id: Ieb5042603ff76fd22f867a17a853bb1ec6a744f2
This commit is contained in:
Martin Magr 2019-09-12 17:07:48 -04:00
parent 2a930a1a8f
commit e78c4f30e0
5 changed files with 271 additions and 1 deletions

View File

@ -205,6 +205,10 @@
# (Optional) List of strings. List of third party python packages to install.
# Defaults to [].
#
# [*enable_sensubility*]
# (Optional) Boolean. Set to true if sensubility should be executed by exec plugin.
# Defaults to false.
#
class tripleo::profile::base::metrics::collectd (
$step = Integer(hiera('step')),
@ -248,7 +252,8 @@ class tripleo::profile::base::metrics::collectd (
$amqp_interval = undef,
$service_names = hiera('enabled_services', []),
$collectd_manage_repo = false,
$python_read_plugins = []
$python_read_plugins = [],
$enable_sensubility = false,
) {
if $step >= 3 {
class {'::collectd':
@ -357,5 +362,9 @@ class tripleo::profile::base::metrics::collectd (
batch_size => $gnocchi_batch_size,
}
}
if $enable_sensubility {
include ::tripleo::profile::base::metrics::collectd::sensubility
}
}
}

View File

@ -0,0 +1,147 @@
# Copyright 2018 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# == Define: tripleo::profile::base::metrics::collectd::sensubility
#
# This is used to create configuration file for collectd-sensubility plugin
#
# === Parameters
#
# [*ensure*]
# (Optional) String. Action to perform with sensubility plugin
# configuration file.
# Defaults to 'present'
#
# [*config_path*]
# (Optional) String. Path to configuration file, which should be populated.
# Defaults to '/etc/collectd-sensubility.conf'.
#
# [*log_file*]
# (Optional) String. Override default log file path (/var/log/collectd/sensubility.log).
# Defaults to undef.
#
# [*log_level*]
# (Optional) String. Override default logging level (WARN).
# Defaults to undef.
#
# [*connection*]
# (Optional) String. URL to Sensu sever side (be default "ampq://sensu:sensu@localhost:5672//sensu")
# Defaults to undef.
#
# [*subscriptions*]
# (Optional) List of strings. List of channels to subscribe to.
# Defaults to undef.
#
# [*client_name*]
# (Optional) String. Name of the client displayed on Sensu server side (by default COLLECTD_HOSTNAME env or hostname).
# Defaults to undef.
#
# [*client_address*]
# (Optional) String. Address of the client displayed on Sensu server side (by default IP address of host).
# Defaults to undef.
#
# [*keepalive_interval*]
# (Optional) Integer. Interval in seconds for sending keepalive messages to Sensu server side (By default 20).
# Defaults to undef.
#
# [*tmp_base_dir*]
# (Optional) String. Path to temporary directory which is used for creation of check scripts
# (by default /var/tmp/collectd-sensubility-checks).
# Defaults to undef.
#
# [*shell_path*]
# (Optional) String. Path to shell used for executing check scripts (by default /usr/bin/sh).
# Defaults to undef.
#
# [*worker_count*]
# (Optional) String. Number of goroutines spawned for executing check scripts (by default 2).
# Defaults to undef.
#
# [*checks*]
# (Optional) Hash representing definitions of standalone checks (by default {}).
# Defaults to undef.
#
# [*amqp_host*]
# (Optional) String. Hostname or IP address of the AMQP 1.0 intermediary.
# Defaults to the undef
#
# [*amqp_port*]
# (Optional) String. Service name or port number on which the AMQP 1.0
# intermediary accepts connections. This argument must be a string,
# even if the numeric form is used.
# Defaults to undef
#
# [*amqp_user*]
# (Optional) String. User part of credentials used to authenticate to the
# AMQP 1.0 intermediary.
# Defaults to undef
#
# [*amqp_password*]
# (Optional) String. Password part of credentials used to authenticate
# to the AMQP 1.0 intermediary.
# Defaults to undef
class tripleo::profile::base::metrics::collectd::sensubility (
$ensure = 'present',
$config_path = '/etc/collectd-sensubility.conf',
$log_file = undef,
$log_level = undef,
$connection = undef,
$subscriptions = undef,
$client_name = undef,
$client_address = undef,
$keepalive_interval = undef,
$tmp_base_dir = undef,
$shell_path = undef,
$worker_count = undef,
$checks = undef,
$amqp_host = undef,
$amqp_port = undef,
$amqp_user = undef,
$amqp_password = undef
) {
include ::collectd
include ::collectd::plugin::exec
package { 'collectd-sensubility':
ensure => $ensure,
}
file { $config_path:
ensure => $ensure,
mode => '0644',
content => epp('tripleo/metrics/collectd-sensubility.conf.epp', {
log_file => $log_file,
log_level => $log_level,
connection => $connection,
subscriptions => $subscriptions,
client_name => $client_name,
client_address => $client_address,
keepalive_interval => $keepalive_interval,
tmp_base_dir => $tmp_base_dir,
shell_path => $shell_path,
worker_count => $worker_count,
checks => inline_template('<%= @checks.to_json %>'),
amqp_host => $amqp_host,
amqp_port => $amqp_port,
amqp_user => $amqp_user,
amqp_password => $amqp_password
})
}
collectd::plugin::exec::cmd { 'sensubility':
user => 'collectd',
group => 'collectd',
exec => ['collectd-sensubility'],
}
}

View File

@ -16,8 +16,27 @@
require 'spec_helper'
sensubility_conf = "
[default]
[sensu]
connection=ampq://sensu:sensu@localhost:5672//sensu
subscriptions=default,test
checks={\"standalone_check\":{\"command\":\"echo 'foobar'\",\"interval\":5}}
[amqp1]
"
exec_cmd = <<-EOS
Exec \"collectd:collectd\" \"collectd-sensubility\"
EOS
describe 'tripleo::profile::base::metrics::collectd' do
shared_examples_for 'tripleo::profile::base::metrics::collectd' do
before :each do
facts.merge!({ :step => params[:step] })
end
context 'with step less than 3' do
let(:params) { { :step => 2, :gnocchi_server => 'localhost' } }
it 'should do nothing' do
@ -80,6 +99,26 @@ describe 'tripleo::profile::base::metrics::collectd' do
)
end
end
context 'with defaults and enabled sensubility' do
let(:params) do
{ :step => 3,
:amqp_host => 'localhost',
:enable_sensubility => true }
end
it 'has collectd class with exec plugin and enabled sensubility' do
is_expected.to compile.with_all_deps
is_expected.to contain_package('collectd-sensubility').with(:ensure => 'present')
is_expected.to contain_class('collectd')
is_expected.to contain_class('collectd::plugin::exec')
is_expected.to contain_concat__fragment('collectd_plugin_exec_conf_sensubility').with({
:order => 50,
:target => '/etc/collectd.d/exec-config.conf',
:content => exec_cmd,
})
is_expected.to contain_file('/etc/collectd-sensubility.conf').with_content(sensubility_conf)
end
end
end
on_supported_os.each do |os, facts|

View File

@ -1,2 +1,10 @@
---
step: 3
tripleo::profile::base::metrics::collectd::sensubility::connection: 'ampq://sensu:sensu@localhost:5672//sensu'
tripleo::profile::base::metrics::collectd::sensubility::subscriptions:
- default
- test
tripleo::profile::base::metrics::collectd::sensubility::checks:
standalone_check:
command: "echo 'foobar'"
interval: 5

View File

@ -0,0 +1,67 @@
<%- | Optional[String] $log_file,
Optional[String] $log_level,
Optional[String] $connection,
Optional[Array] $subscriptions,
Optional[String] $client_name,
Optional[String] $client_address,
Optional[Integer] $keepalive_interval,
Optional[String] $tmp_base_dir,
Optional[String] $shell_path,
Optional[Integer] $worker_count,
Optional[String] $checks,
Optional[String] $amqp_host,
Optional[String] $amqp_port,
Optional[String] $amqp_user,
Optional[String] $amqp_password
| -%>
[default]
<% unless $log_file =~ Undef { -%>
log_file=<%=$log_file%>
<%- } -%>
<% unless $log_level =~ Undef { -%>
log_level=<%=$log_level%>
<%- } -%>
[sensu]
<% unless $connection =~ Undef { -%>
connection=<%=$connection%>
<%- } -%>
<% unless $subscriptions =~ Undef { -%>
subscriptions=<%=$subscriptions.join(',')%>
<%- } -%>
<% unless $client_name =~ Undef { -%>
client_name=<%=$client_name%>
<%- } -%>
<% unless $client_address =~ Undef { -%>
client_address=<%=$client_address%>
<%- } -%>
<% unless $keepalive_interval =~ Undef { -%>
keepalive_interval=<%=$keepalive_interval%>
<%- } -%>
<% unless $tmp_base_dir =~ Undef { -%>
tmp_base_dir=<%=$tmp_base_dir%>
<%- } -%>
<% unless $shell_path =~ Undef { -%>
shell_path=<%=$shell_path%>
<%- } -%>
<% unless $worker_count =~ Undef { -%>
worker_count=<%=$worker_count%>
<%- } -%>
<% unless $checks =~ Undef { -%>
checks=<%=$checks%>
<%- } -%>
[amqp1]
<% unless $amqp_host =~ Undef { -%>
host=<%=$amqp_host%>
<%- } -%>
<% unless $amqp_port =~ Undef { -%>
port=<%=$amqp_port%>
<%- } -%>
<% unless $amqp_user =~ Undef { -%>
user=<%=$amqp_user%>
<%- } -%>
<% unless $amqp_password =~ Undef { -%>
password=<%=$amqp_password%>
<%- } -%>