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

Adding windows support. #438

Merged
merged 2 commits into from
Feb 25, 2016
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
3 changes: 1 addition & 2 deletions .fixtures.yml
Original file line number Diff line number Diff line change
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}"

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
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 Expand Up @@ -446,4 +446,3 @@ The following puppet modules exist for managing dashboards
## License

See LICENSE file.

7 changes: 6 additions & 1 deletion lib/puppet/provider/package/sensu_gem.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows doesn't have the various sensu services?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know and per the documentation I believe only the client is supported on windows.

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
Original file line number Diff line number Diff line change
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a windows user, but no defaults for these? Does the sensu package installer create a user or does it just run as a system service? Any way to keep other random users from browsing the sensu config which may contain sensitive information such as passwords?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a bit of a tricky one.
Firstly, no the sensu does not create a user the windows service runs as the Local System user.

Secondly, from a puppet point of view the standard unix modal permissions don't really make sense on windows. We have the puppet-acl for those people who really care about fine-grained security permissions but that is out-of-scope of this module and would probably be managed at the profile layer. With these things set to undef the SYSTEM user and Administrators group have full permissions and standard Users have read and execute.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - the last version of Windows I used was 2008, and not with puppet so my knowledge is old. Makes sense.

}
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,26 @@
create_resources('::sensu::handler', $handlers)
create_resources('::sensu::check', $checks)

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
Loading