Skip to content

Commit

Permalink
Merge pull request #438 from opentable/sensu_for_windows
Browse files Browse the repository at this point in the history
Adding windows support.
  • Loading branch information
jlambert121 committed Feb 25, 2016
2 parents 70ec343 + 1f6997d commit cf636de
Show file tree
Hide file tree
Showing 21 changed files with 227 additions and 135 deletions.
3 changes: 1 addition & 2 deletions .fixtures.yml
Expand Up @@ -2,7 +2,6 @@ fixtures:
repositories:
apt: git://github.com/puppetlabs/puppetlabs-apt.git
stdlib: git://github.com/puppetlabs/puppetlabs-stdlib.git
wget: git://github.com/maestrodev/puppet-wget.git
remote_file: git://github.com/lwf/puppet-remote_file.git
symlinks:
sensu: "#{source_dir}"

2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -35,7 +35,7 @@ Sensu-Puppet module.

- puppetlabs/apt
- puppetlabs/stdlib
- maestrodev/wget
- lwf/puppet-remote_file

See `metadata.json` for details.

Expand Down
7 changes: 6 additions & 1 deletion lib/puppet/provider/package/sensu_gem.rb
Expand Up @@ -11,7 +11,12 @@

has_feature :versionable, :install_options

commands :gemcmd => "/opt/sensu/embedded/bin/gem"
commands :gemcmd =>
if File.exists?("#{ENV['SYSTEMDRIVE']}\\opt\\sensu\\embedded\\bin\\gem.bat")
"#{ENV['SYSTEMDRIVE']}\\opt\\sensu\\embedded\\bin\\gem.bat"
else
"/opt/sensu/embedded/bin/gem"
end

def uninstall
command = [command(:gemcmd), "uninstall"]
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/sensu_api_config/json.rb
Expand Up @@ -71,7 +71,7 @@ def port
end

def config_file
"#{resource[:base_path]}/api.json"
File.join(resource[:base_path], 'api.json').gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
end

# Public: Set the port that the API should listen on.
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/sensu_client_config/json.rb
Expand Up @@ -25,7 +25,7 @@ def flush
end

def config_file
"#{resource[:base_path]}/client.json"
File.join(resource[:base_path], 'client.json').gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
end

def pre_create
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/sensu_rabbitmq_config/json.rb
Expand Up @@ -94,7 +94,7 @@ def ssl_cert_chain=(value)
end

def config_file
"#{resource[:base_path]}/rabbitmq.json"
File.join(resource[:base_path],'rabbitmq.json').gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
end

def port
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/sensu_redis_config/json.rb
Expand Up @@ -26,7 +26,7 @@ def pre_create
end

def config_file
"#{resource[:base_path]}/redis.json"
File.join(resource[:base_path], 'redis.json').gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
end

def destroy
Expand Down
21 changes: 11 additions & 10 deletions manifests/api/config.pp
Expand Up @@ -14,20 +14,21 @@
$ensure = 'present'
}

file { '/etc/sensu/conf.d/api.json':
file { "${sensu::etc_dir}/conf.d/api.json":
ensure => $ensure,
owner => 'sensu',
group => 'sensu',
mode => '0440',
owner => $sensu::user,
group => $sensu::group,
mode => $sensu::file_mode,
}

sensu_api_config { $::fqdn:
ensure => $ensure,
bind => $sensu::api_bind,
host => $sensu::api_host,
port => $sensu::api_port,
user => $sensu::api_user,
password => $sensu::api_password,
ensure => $ensure,
base_path => "${sensu::etc_dir}/conf.d",
bind => $sensu::api_bind,
host => $sensu::api_host,
port => $sensu::api_port,
user => $sensu::api_user,
password => $sensu::api_password,
}

}
12 changes: 7 additions & 5 deletions manifests/api/service.pp
Expand Up @@ -31,11 +31,13 @@
}
}

service { 'sensu-api':
ensure => $ensure,
enable => $enable,
hasrestart => $hasrestart,
subscribe => [ Class['sensu::package'], Class['sensu::api::config'], Class['sensu::redis::config'] ],
if $::osfamily != 'windows' {
service { 'sensu-api':
ensure => $ensure,
enable => $enable,
hasrestart => $hasrestart,
subscribe => [ Class['sensu::package'], Class['sensu::api::config'], Class['sensu::redis::config'] ],
}
}
}
}
28 changes: 23 additions & 5 deletions manifests/check.pp
Expand Up @@ -129,16 +129,34 @@

$check_name = regsubst(regsubst($name, ' ', '_', 'G'), '[\(\)]', '', 'G')

file { "/etc/sensu/conf.d/checks/${check_name}.json":
case $::osfamily {
'windows': {
$etc_dir = 'C:/opt/sensu'
$conf_dir = "${etc_dir}/conf.d"
$user = undef
$group = undef
$file_mode = undef
}
default: {
$etc_dir = '/etc/sensu'
$conf_dir = "${etc_dir}/conf.d"
$user = 'sensu'
$group = 'sensu'
$file_mode = '0440'
}
}

file { "${conf_dir}/checks/${check_name}.json":
ensure => $ensure,
owner => 'sensu',
group => 'sensu',
mode => '0440',
owner => $user,
group => $group,
mode => $file_mode,
before => Sensu_check[$check_name],
}

sensu_check { $check_name:
ensure => $ensure,
base_path => "${conf_dir}/checks",
type => $type,
standalone => $standalone,
command => $command,
Expand All @@ -157,7 +175,7 @@
dependencies => $dependencies,
custom => $custom,
subdue => $subdue,
require => File['/etc/sensu/conf.d/checks'],
require => File["${conf_dir}/checks"],
notify => $::sensu::check_notify,
ttl => $ttl,
}
Expand Down
9 changes: 5 additions & 4 deletions manifests/client/config.pp
Expand Up @@ -14,15 +14,16 @@
$ensure = 'present'
}

file { '/etc/sensu/conf.d/client.json':
file { "${sensu::conf_dir}/client.json":
ensure => $ensure,
owner => 'sensu',
group => 'sensu',
mode => '0440',
owner => $sensu::user,
group => $sensu::group,
mode => $sensu::file_mode,
}

sensu_client_config { $::fqdn:
ensure => $ensure,
base_path => $sensu::conf_dir,
client_name => $sensu::client_name,
address => $sensu::client_address,
socket => {
Expand Down
17 changes: 17 additions & 0 deletions manifests/client/service.pp
Expand Up @@ -31,6 +31,23 @@
}
}

if $::osfamily == 'windows' {

file { 'C:/opt/sensu/bin/sensu-client.xml':
ensure => present,
content => template("${module_name}/sensu-client.erb"),
}

exec { 'install-sensu-client':
command => "powershell.exe -ExecutionPolicy RemoteSigned -Command \"New-Service -Name sensu-client -BinaryPathName c:\\opt\\sensu\\bin\\sensu-client.exe -DisplayName 'Sensu Client' -StartupType Automatic\"",
unless => 'powershell.exe -ExecutionPolicy RemoteSigned -Command "Get-Service sensu-client"',
path => $::path,
before => Service['sensu-client'],
require => File['C:/opt/sensu/bin/sensu-client.xml'],
}

}

service { 'sensu-client':
ensure => $ensure,
enable => $enable,
Expand Down
20 changes: 20 additions & 0 deletions manifests/init.pp
Expand Up @@ -488,6 +488,26 @@
create_resources('::sensu::filter', $filters, $filter_defaults)
create_resources('::sensu::mutator', $mutators)

case $::osfamily {
'Debian','RedHat': {
$etc_dir = '/etc/sensu'
$conf_dir = "${etc_dir}/conf.d"
$user = 'sensu'
$group = 'sensu'
$dir_mode = '0555'
$file_mode = '0440'
}

'windows': {
$etc_dir = 'C:/opt/sensu'
$conf_dir = "${etc_dir}/conf.d"
$user = undef
$group = undef
$dir_mode = undef
$file_mode = undef
}
}

# Include everything and let each module determine its state. This allows
# transitioning to purged config and stopping/disabling services
anchor { 'sensu::begin': } ->
Expand Down

0 comments on commit cf636de

Please sign in to comment.