Skip to content

Instantly share code, notes, and snippets.

@cdenneen
Created May 24, 2018 18:41
Show Gist options
  • Save cdenneen/622d56132307e7a83878916fcbf1dc22 to your computer and use it in GitHub Desktop.
Save cdenneen/622d56132307e7a83878916fcbf1dc22 to your computer and use it in GitHub Desktop.
Ordering issue
# @summary
# Private class for configuring sensu
#
# @api public
#
# @param server
# @param rabbitmq_host
# @param rabbitmq_password
# @param rabbitmq_vhost
# @param subscriptions
# @param sensu_additional_plugins
# @param client_bind
# @param client_port
# @param client_plugins_script
# @param client_keepalive
# @param client_custom
# @param default_client_name
# @param sensu_plugins
# @param sensu_client_prefix
# @param version
# @param enterprise
# @param enterprise_dashboard
# @param enterprise_user
# @param enterprise_pass
# @param repo_source
# @param manage_user
# @param package_checksum
# @param windows_repo_prefix
# @param windows_logrotate
# @param windows_log_number
# @param windows_log_size
# @param windows_pkg_url
#
class profile_base::sensu (
Boolean $server,
String $rabbitmq_host,
String $rabbitmq_password,
String $rabbitmq_vhost,
Array[String] $subscriptions,
Array[String] $sensu_additional_plugins,
String $client_bind,
Integer $client_port,
Hash $client_plugins_script,
Hash $client_keepalive,
Hash $client_custom,
String $default_client_name,
Array[String] $sensu_plugins = ['sensu-plugins-mailer',
'sensu-plugins-disk-checks',
'sensu-plugins-aws',
'sensu-plugins-process-checks',
'sensu-plugins-graphite',
'sensu-plugins-memory-checks',
'sensu-plugins-cpu-checks',
'sensu-plugins-filesystem-checks',
'sensu-plugins-hardware',
'sensu-plugins-uptime-checks',
'sensu-plugins-load-checks',
'sensu-plugins-logs',
'sensu-plugins-http',
'sensu-plugins-vmstats',
'vmstat'
],
String $sensu_client_prefix,
String $version,
Optional[Boolean] $enterprise,
Optional[Boolean] $enterprise_dashboard,
Optional[String] $enterprise_user,
Optional[String] $enterprise_pass,
Optional[String] $repo_source = undef,
Optional[Boolean] $manage_user = false,
Optional[String] $package_checksum = undef,
Optional[String] $windows_repo_prefix = undef,
Optional[Boolean] $windows_logrotate = false,
Optional[String] $windows_log_number = undef,
Optional[String] $windows_log_size = undef,
Optional[String] $windows_pkg_url = undef,
)
{
assert_private()
if $::facts['ec2_metadata'] {
$client_name = $::facts['ec2_metadata']['instance-id']
} elsif $::facts[hostname] {
$client_name = $::facts[hostname]
} else {
$client_name = $default_client_name
}
$client_name_with_prefix="${sensu_client_prefix}${client_name}"
if $::facts[ipaddress] {
$client_address = $::facts[ipaddress]
} else {
$client_address = '127.0.0.1'
}
if $::facts[os][family] == 'RedHat' {
require profile_base::el
yum::group { 'development group install for sensu' :
ensure => installed,
name => 'Development Tools',
require => Yumrepo['epel'],
timeout => 0
}
}elsif $::facts[os][family] == 'Debian' {
package { 'build-essential':
ensure => 'latest'
}
}
class { '::sensu':
version => $version,
install_repo => true,
repo_source => $repo_source,
server => $server,
api => $server,
client => true,
use_embedded_ruby => true,
rabbitmq_host => $rabbitmq_host,
rabbitmq_password => $rabbitmq_password,
rabbitmq_vhost => $rabbitmq_vhost,
subscriptions => $subscriptions,
client_name => $client_name_with_prefix,
client_address => $client_address,
client_keepalive => $client_keepalive,
client_custom => $client_custom,
client_port => $client_port,
client_bind => $client_bind,
enterprise => $enterprise,
enterprise_dashboard => $enterprise_dashboard,
enterprise_user => $enterprise_user,
enterprise_pass => $enterprise_pass,
gem_install_options => '--source http://artifactory.ap.org/api/rubygems/rubygems',
package_checksum => $package_checksum,
windows_repo_prefix => $windows_repo_prefix,
windows_logrotate => $windows_logrotate,
windows_log_size => $windows_log_size,
windows_log_number => $windows_log_number,
manage_user => $manage_user,
windows_pkg_url => $windows_pkg_url,
}
if $::facts[os][family] == 'RedHat' {
Yumrepo['epel']
-> Yum::Group['development group install for sensu']
-> Package['sensu']
package {['libxslt-devel', 'libxml2-devel']:
ensure => present,
before => Package['sensu-plugins-aws'],
}
}elsif $::facts[os][family] == 'Debian' {
Package['build-essential'] -> Package['sensu']
}
$sensu_plugin_defaults = {
ensure => 'installed',
provider => sensu_gem,
install_options => $::facts['os']['family'] ? {
'RedHat' => ['--','--use-system-libraries'],
'Debian' => ['--','--use-system-libraries'],
default => undef,
},
require => $::facts['os']['family'] ? {
'RedHat' => [
Package['sensu'],
Package['libxml2-devel'],
Package['libxslt-devel']
],
default => Package['sensu'],
}
}
$sensu_plugins.each |String $plugins| {
package { $plugins :
* => $sensu_plugin_defaults
}
}
$sensu_additional_plugins.each |String $plugins| {
package { $plugins :
* => $sensu_plugin_defaults
}
}
# Required to install some nagios plugins
if $::facts['kernel'] == 'Linux' {
if $::facts['os']['family'] == 'RedHat' {
$nagios_packages = ['nagios-plugins', 'nagios-common']
} elsif $::facts['os']['family'] == 'Debian' {
$nagios_packages = ['nagios-plugins-basic', 'nagios-plugins-common']
}
package { $nagios_packages:
ensure => 'installed',
require => Package['sensu'],
}
}
# make script executable
$client_plugins_script.each |String $script_name, String $script_value| {
# sensu plugins add
file { "${::sensu::etc_dir}/plugins/${script_name}":
ensure => 'present',
owner => $sensu::user,
group => $sensu::group,
mode => '0555',
content => $script_value,
require => Package['sensu']
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment