Skip to content

Commit

Permalink
Support MacOS client
Browse files Browse the repository at this point in the history
  • Loading branch information
csolei2 authored and ghoneycutt committed Jan 4, 2018
1 parent e05d84c commit 684d2ba
Show file tree
Hide file tree
Showing 28 changed files with 451 additions and 101 deletions.
18 changes: 18 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,22 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
client.vm.provision :shell, :path => "tests/provision_basic_debian.sh"
client.vm.provision :shell, :inline => "puppet apply /vagrant/tests/sensu-client.pp"
end

# The rsync used to populate /vagrant will fail if the repo has the spec
# fixtures created. To avoid, run `rake spec_clean` before `vagrant up`.
config.vm.define "macos-client", autostart: false do |client|
client.vm.box = "jhcook/macos-sierra"
client.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "1024"]
end
client.vm.hostname = 'macos-client.example.com'
client.vm.network :private_network, ip: "192.168.56.19"
client.vm.synced_folder ".", "/vagrant", type: "rsync", group: "wheel"
client.vm.provision :shell, :path => "tests/provision_macos.sh"
client.vm.provision :shell, :inline => "puppet apply /vagrant/tests/sensu-client.pp"
client.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--usb", "on"]
vb.customize ["modifyvm", :id, "--usbehci", "off"]
end
end
end
15 changes: 14 additions & 1 deletion manifests/api.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
Boolean $hasrestart = $::sensu::hasrestart,
) {

case $::osfamily {
'Darwin': {
$service_path = '/Library/LaunchDaemons/org.sensuapp.sensu-api.plist'
$service_provider = 'launchd'
}
default: {
$service_path = undef
$service_provider = undef
}
}

if $::sensu::manage_services {

case $::sensu::api {
Expand All @@ -26,10 +37,12 @@
}

if $::osfamily != 'windows' {
service { 'sensu-api':
service { $::sensu::api_service_name:
ensure => $service_ensure,
enable => $service_enable,
hasrestart => $hasrestart,
path => $service_path,
provider => $service_provider,
subscribe => [
Class['sensu::package'],
Sensu_api_config[$::fqdn],
Expand Down
5 changes: 5 additions & 0 deletions manifests/check.pp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
Variant[Undef,Enum['absent'],Hash] $proxy_requests = undef,
Variant[Undef,Enum['absent'],Hash] $hooks = undef,
) {

if $ensure == 'present' and !$command {
fail("sensu::check{${name}}: a command must be given when ensure is present")
}
Expand Down Expand Up @@ -155,11 +156,15 @@
'windows': {
$etc_dir = 'C:/opt/sensu'
$conf_dir = "${etc_dir}/conf.d"
$user = $::sensu::user
$group = $::sensu::group
$file_mode = undef
}
default: {
$etc_dir = '/etc/sensu'
$conf_dir = "${etc_dir}/conf.d"
$user = $::sensu::user
$group = $::sensu::group
$file_mode = '0440'
}
}
Expand Down
44 changes: 33 additions & 11 deletions manifests/client.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,49 @@
$service_enable = false
}
}
case $::osfamily {
'windows': {
$service_name = 'sensu-client'
$service_path = undef
$service_provider = undef
file { 'C:/opt/sensu/bin/sensu-client.xml':
ensure => file,
content => template("${module_name}/sensu-client.erb"),
}

if $::osfamily == 'windows' {

file { 'C:/opt/sensu/bin/sensu-client.xml':
ensure => file,
content => template("${module_name}/sensu-client.erb"),
exec { 'install-sensu-client':
provider => 'powershell',
command => "New-Service -Name sensu-client -BinaryPathName c:\\opt\\sensu\\bin\\sensu-client.exe -DisplayName 'Sensu Client' -StartupType Automatic",
unless => 'if (Get-Service sensu-client -ErrorAction SilentlyContinue) { exit 0 } else { exit 1 }',
before => Service['sensu-client'],
require => File['C:/opt/sensu/bin/sensu-client.xml'],
}
}
'Darwin': {
$service_path = '/Library/LaunchDaemons/org.sensuapp.sensu-client.plist'
$service_provider = 'launchd'

exec { 'install-sensu-client':
provider => 'powershell',
command => "New-Service -Name sensu-client -BinaryPathName c:\\opt\\sensu\\bin\\sensu-client.exe -DisplayName 'Sensu Client' -StartupType Automatic",
unless => 'if (Get-Service sensu-client -ErrorAction SilentlyContinue) { exit 0 } else { exit 1 }',
before => Service['sensu-client'],
require => File['C:/opt/sensu/bin/sensu-client.xml'],
file {$service_path:
ensure => file,
owner => 'root',
group => 'wheel',
mode => '0755',
before => Service['sensu-client'],
}
}
default: {
$service_path = undef
$service_provider = undef
}
}

service { 'sensu-client':
ensure => $service_ensure,
enable => $service_enable,
name => $::sensu::service_name,
hasrestart => $hasrestart,
path => $service_path,
provider => $service_provider,
subscribe => [
Class['sensu::package'],
Sensu_client_config[$::fqdn],
Expand Down
2 changes: 1 addition & 1 deletion manifests/enterprise.pp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
Variant[Undef,String] $heap_dump_path = $::sensu::heap_dump_path,
Variant[Undef,String] $java_opts = $::sensu::java_opts,
Boolean $hasrestart = $::sensu::hasrestart,
){
) {

# Package
if $::sensu::enterprise {
Expand Down
4 changes: 2 additions & 2 deletions manifests/filter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

file { "/etc/sensu/conf.d/filters/${name}.json":
ensure => $ensure,
owner => 'sensu',
group => 'sensu',
owner => $::sensu::user,
group => $::sensu::group,
mode => '0444',
}

Expand Down
98 changes: 59 additions & 39 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,61 @@
Hash $mutators = {},
### END Hiera Lookups ###
) {

case $::kernel {
'Darwin': {
$api_service_name = 'org.sensuapp.sensu-api'
$etc_dir = $sensu_etc_dir
$conf_dir = "${etc_dir}/conf.d"
$user = '_sensu'
$group = 'wheel'
$home_dir = '/opt/sensu'
$shell = '/bin/false'
$dir_mode = '0555'
$file_mode = '0440'
$service_name = 'org.sensuapp.sensu-client'
}
'Linux': {
$api_service_name = 'sensu-api'
$etc_dir = $sensu_etc_dir
$conf_dir = "${etc_dir}/conf.d"
$user = $sensu_user ? {
undef => 'sensu',
default => $sensu_user,
}
$group = $sensu_group ? {
undef => 'sensu',
default => $sensu_group,
}
$home_dir = '/opt/sensu'
$shell = '/bin/false'
$dir_mode = '0555'
$file_mode = '0440'
$service_name = 'sensu-client'
}
'windows': {
$api_service_name = undef
$etc_dir = $sensu_etc_dir
$conf_dir = "${etc_dir}/conf.d"
$user = $sensu_user ? {
undef => 'NT Authority\SYSTEM',
default => $sensu_user,
}
$group = $sensu_group ? {
undef => 'Administrators',
default => $sensu_group,
}
$home_dir = $etc_dir
$shell = undef
$dir_mode = undef
$file_mode = undef
$service_name = 'sensu-client'
}
default: {
fail("Detected kernel is <${::kernel}> and must be Darwin, Linux or windows.")
}
}

if $dashboard { fail('Sensu-dashboard is deprecated, use a dashboard module. See https://github.com/sensu/sensu-puppet#dashboards')}
if $purge_config { fail('purge_config is deprecated, set the purge parameter to a hash containing `config => true` instead') }
if $purge_plugins_dir { fail('purge_plugins_dir is deprecated, set the purge parameter to a hash containing `plugins => true` instead') }
Expand Down Expand Up @@ -486,7 +541,10 @@
}

if $api and $manage_services and $::osfamily != 'windows' {
$api_service = Service['sensu-api']
$api_service = $::osfamily ? {
'Darwin' => Service['org.sensuapp.sensu-client'],
default => Service[$api_service_name],
}
} else {
$api_service = undef
}
Expand Down Expand Up @@ -556,44 +614,6 @@
}
}

case $::osfamily {
'Debian','RedHat': {
$etc_dir = $sensu_etc_dir
$conf_dir = "${etc_dir}/conf.d"
$user = $sensu_user ? {
undef => 'sensu',
default => $sensu_user,
}
$group = $sensu_group ? {
undef => 'sensu',
default => $sensu_group,
}
$home_dir = '/opt/sensu'
$shell = '/bin/false'
$dir_mode = '0555'
$file_mode = '0440'
}

'windows': {
$etc_dir = $sensu_etc_dir
$conf_dir = "${etc_dir}/conf.d"
$user = $sensu_user ? {
undef => 'NT Authority\SYSTEM',
default => $sensu_user,
}
$group = $sensu_group ? {
undef => 'Administrators',
default => $sensu_group,
}
$home_dir = $etc_dir
$shell = undef
$dir_mode = undef
$file_mode = undef
}

default: {}
}

# Include everything and let each module determine its state. This allows
# transitioning to purged config and stopping/disabling services
contain ::sensu::package
Expand Down
56 changes: 44 additions & 12 deletions manifests/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,27 @@
) {

case $::osfamily {
'Darwin': {
$pkg_provider = 'pkgdmg'
$pkg_source = '/tmp/sensu-installer.dmg'
$pkg_require = "Remote_file[${pkg_source}]"
$pkg_title = 'sensu'
$pkg_version = $::sensu::version
$service_name = 'org.sensuapp.sensu-client'

remote_file { $pkg_source:
ensure => present,
source => "https://repositories.sensuapp.org/osx/${::macosx_productversion_major}/x86_64/sensu-${pkg_version}.dmg",
}
}

'Debian': {
$pkg_title = 'sensu'
$pkg_name = 'sensu'
$pkg_version = $::sensu::version
$pkg_source = undef
$pkg_title = 'sensu'
$pkg_name = 'sensu'
$pkg_version = $::sensu::version
$pkg_source = undef
$pkg_provider = undef
$service_name = 'sensu-client'

if $::sensu::manage_repo {
class { '::sensu::repo::apt': }
Expand All @@ -79,6 +93,7 @@
$pkg_version = $::sensu::version
$pkg_source = undef
$pkg_provider = undef
$service_name = 'sensu-client'

if $::sensu::manage_repo {
class { '::sensu::repo::yum': }
Expand All @@ -103,6 +118,7 @@
$pkg_title = $::sensu::windows_package_title
# The name used by the provider to compare to Windows Add/Remove programs.
$pkg_name = $::sensu::windows_package_name
$service_name = 'sensu-client'

# The user can override the computation of the source URL. This URL is
# used with the remote_file resource, it is not used with the chocolatey
Expand Down Expand Up @@ -147,12 +163,24 @@

}

package { $pkg_title:
ensure => $pkg_version,
name => $pkg_name,
source => $pkg_source,
require => $pkg_require,
provider => $pkg_provider,
case $::osfamily {
'Darwin': {
package { $pkg_title:
ensure => present,
source => $pkg_source,
require => $pkg_require,
provider => $pkg_provider,
}
}
default: {
package { $pkg_title:
ensure => $pkg_version,
name => $pkg_name,
source => $pkg_source,
require => $pkg_require,
provider => $pkg_provider,
}
}
}

if $::sensu::sensu_plugin_provider {
Expand All @@ -178,9 +206,13 @@
}

if $::osfamily != 'windows' {
$template_content = $::osfamily ? {
'Darwin' => 'EMBEDDED_RUBY=true',
default => template("${module_name}/sensu.erb")
}
file { '/etc/default/sensu':
ensure => file,
content => template("${module_name}/sensu.erb"),
content => $template_content,
owner => '0',
group => '0',
mode => '0444',
Expand Down Expand Up @@ -256,7 +288,7 @@
$spawn_content = inline_template($spawn_template)
if $::sensu::client and $::sensu::manage_services {
$spawn_notify = [
Service['sensu-client'],
Service[$service_name],
Class['sensu::server::service'],
]
} elsif $::sensu::manage_services {
Expand Down
1 change: 1 addition & 0 deletions manifests/plugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
Boolean $nocheckcertificate = false,
Any $gem_install_options = $::sensu::gem_install_options,
) {

File {
owner => 'sensu',
group => 'sensu',
Expand Down
3 changes: 2 additions & 1 deletion manifests/server/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
}
}

if $::osfamily != 'windows' {
# The server is only supported on Linux
if $::kernel == 'Linux' {
service { 'sensu-server':
ensure => $ensure,
enable => $enable,
Expand Down
Loading

0 comments on commit 684d2ba

Please sign in to comment.