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

Add Windows support for Sensu Go agent #1108

Merged
merged 2 commits into from
May 18, 2019
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
5 changes: 2 additions & 3 deletions .fixtures-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ fixtures:
repositories:
apt:
repo: git://github.com/puppetlabs/puppetlabs-apt.git
ref: 6.3.0
stdlib:
repo: git://github.com/puppetlabs/puppetlabs-stdlib.git
ref: 5.1.0
yumrepo_core:
repo: git://github.com/puppetlabs/puppetlabs-yumrepo_core
ref: 1.0.1
puppet_version: ">= 6.0.0"
archive:
repo: git://github.com/voxpupuli/puppet-archive.git
symlinks:
sensu: "#{source_dir}"
3 changes: 3 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ fixtures:
repo: git://github.com/puppetlabs/puppetlabs-yumrepo_core
ref: 1.0.1
puppet_version: ">= 6.0.0"
archive:
repo: git://github.com/voxpupuli/puppet-archive.git
ref: 'v3.0.0'
ghoneycutt marked this conversation as resolved.
Show resolved Hide resolved
symlinks:
sensu: "#{source_dir}"
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--format documentation
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ matrix:
env: BEAKER_set="amazonlinux-201803" BEAKER_PUPPET_COLLECTION=puppet6
bundler_args:
script: bundle exec rake beaker
allow_failures:
- rvm: 2.4.4
env: PUPPET_GEM_VERSION="~> 5" FIXTURES_YML=".fixtures-latest.yml"
- rvm: 2.5.3
env: PUPPET_GEM_VERSION="~> 6" FIXTURES_YML=".fixtures-latest.yml"
branches:
only:
- master
Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
3. [Usage - Configuration options and additional functionality](#usage)
* [Basic Sensu backend](#basic-sensu-backend)
* [Basic Sensu agent](#basic-sensu-agent)
* [Manage Windows Agent](#manage-windows-agent)
* [Advanced agent](#advanced-agent)
* [Advanced SSL](#advanced-ssl)
* [Enterprise support](#enterprise-support)
Expand Down Expand Up @@ -65,6 +66,8 @@ This module has a soft dependency on the [puppetlabs/apt](https://forge.puppet.c

If using Puppet >= 6.0.0 there is a soft dependency on the [puppetlabs/yumrepo_core](https://forge.puppet.com/puppetlabs/yumrepo_core) module (`>= 1.0.1 < 2.0.0`) for systems using `yum`.

If managing Windows there is a soft dependency on the [puppet/archive](https://forge.puppet.com/puppet/archive) module (`>= 3.0.0 < 4.0.0`).

### Beginning with sensu

This module provides Vagrant definitions that can be used to get started with Sensu.
Expand Down Expand Up @@ -119,6 +122,36 @@ associated to `linux` and `apache-servers` subscriptions.
}
```

### Manage Windows Agent

ghoneycutt marked this conversation as resolved.
Show resolved Hide resolved
This module supports Windows Sensu Go agent starting with version 5.7.0.

The Windows package source must be specified as either a URL, a Puppet source or a filesystem path.

Install sensu-go-agent on Windows from URL:

```puppet
class { 'sensu::agent':
package_source => 'https://s3-us-west-2.amazonaws.com/sensu.io/sensu-go/5.7.0/sensu-go-agent_5.7.0.2380_en-US.x64.msi',
}
```

Install sensu-go-agent on Windows from Puppet source:

```puppet
class { 'sensu::agent':
package_source => 'puppet:///modules/profile/sensu/sensu-go-agent.msi',
}
```

If a system already has the necessary MSI present it can be installed without downloading from an URL:

```puppet
class { 'sensu::agent':
package_source => 'C:\Temp\sensu-go-agent.msi',
}
```

### Advanced agent

If you wish to change the `agent` password you must provide the new and old password.
Expand Down
28 changes: 28 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,25 @@ Windows MSI packaging and to avoid surprising upgrades.

Default value: `undef`

##### `package_source`

Data type: `Optional[String[1]]`

Source of package for installing Windows.
Paths with http:// or https:// will be downloaded
Paths with puppet:// or absolute filesystem paths will also be installed.

Default value: `undef`

##### `package_download_path`
ghoneycutt marked this conversation as resolved.
Show resolved Hide resolved

Data type: `Optional[Stdlib::Absolutepath]`

Where to download the MSI for Windows. Defaults to `C:\`.
This parameter only used when `package_source` is an URL or when it's a puppet source (`puppet://`).

Default value: `undef`

##### `package_name`

Data type: `String`
Expand Down Expand Up @@ -229,6 +248,15 @@ Sets show_diff parameter for agent.yml configuration file

Default value: `true`

##### `log_file`

Data type: `Optional[Stdlib::Absolutepath]`

Path to agent log file, only for Windows.
Defaults to `C:\ProgramData\sensu\log\sensu-agent.log`

Default value: `undef`

### sensu::backend

Class to manage the Sensu backend.
Expand Down
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,10 @@ desc 'Generate REFERENCE.md'
task :reference do
sh 'puppet strings generate --format markdown'
end

namespace :acceptance do
ghoneycutt marked this conversation as resolved.
Show resolved Hide resolved
desc 'Run acceptance tests against current code for Windows'
RSpec::Core::RakeTask.new(:windows) do |t|
t.pattern = 'spec/acceptance/windows_spec.rb'
end
end
43 changes: 43 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,47 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
agent.vm.provision :shell, :inline => "puppet apply /vagrant/tests/sensu-agent.pp"
agent.vm.provision :shell, :inline => "facter --custom-dir=/vagrant/lib/facter sensu_agent"
end

config.vm.define "win2008r2-agent", autostart: false do |agent|
agent.vm.box = "opentable/win-2008r2-standard-amd64-nocm"
agent.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
vb.customize ["modifyvm", :id, "--cpus", "1"]
end
agent.vm.hostname = 'win2008r2-agent'
agent.vm.network :private_network, ip: "192.168.52.25"
agent.vm.network "forwarded_port", host: 3390, guest: 3389, auto_correct: true
agent.vm.provision :shell, :path => "tests/provision_basic_win.ps1"
agent.vm.provision :shell, :inline => '$env:PATH += ";C:\Program Files\Puppet Labs\Puppet\bin" ; iex "puppet apply -v C:/vagrant/tests/sensu-agent.pp"'
agent.vm.provision :shell, :inline => '$env:PATH += ";C:\Program Files\Puppet Labs\Puppet\bin" ; iex "facter --custom-dir=C:\vagrant\lib\facter sensu_agent"'
end

config.vm.define "win2012r2-agent", autostart: false do |agent|
treydock marked this conversation as resolved.
Show resolved Hide resolved
agent.vm.box = "opentable/win-2012r2-standard-amd64-nocm"
treydock marked this conversation as resolved.
Show resolved Hide resolved
agent.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
vb.customize ["modifyvm", :id, "--cpus", "1"]
end
agent.vm.hostname = 'win2012r2-agent'
agent.vm.network :private_network, ip: "192.168.52.24"
agent.vm.network "forwarded_port", host: 3389, guest: 3389, auto_correct: true
agent.vm.provision :shell, :path => "tests/provision_basic_win.ps1"
agent.vm.provision :shell, :inline => 'iex "puppet apply -v C:/vagrant/tests/sensu-agent.pp"'
agent.vm.provision :shell, :inline => 'iex "facter --custom-dir=C:\vagrant\lib\facter sensu_agent"'
end

config.vm.define "win2016-agent", autostart: false do |agent|
agent.vm.box = "mwrock/Windows2016"
agent.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
vb.customize ["modifyvm", :id, "--cpus", "1"]
vb.gui = false
end
agent.vm.hostname = 'win2016-agent'
agent.vm.network :private_network, ip: "192.168.52.26"
agent.vm.network "forwarded_port", host: 3391, guest: 3389, auto_correct: true
agent.vm.provision :shell, :path => "tests/provision_basic_win.ps1"
agent.vm.provision :shell, :inline => 'iex "puppet apply -v C:/vagrant/tests/sensu-agent.pp"'
agent.vm.provision :shell, :inline => 'iex "facter --custom-dir=C:\vagrant\lib\facter sensu_agent"'
end
end
58 changes: 58 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: '{build}-{branch}'
platform:
- x64
build: off
max_jobs: 2
branches:
only:
- master
- /^v\d/
cache:
- C:\downloads
- C:\vendor\bundle
init:
- ps: $env:GEM_SOURCE = "http://rubygems.org"
install:
- set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
- ps: |
if (!(Test-Path C:\downloads)) { mkdir C:\downloads | Out-Null }
$log = "C:/puppet-agent.log"
$agent_url = "https://downloads.puppetlabs.com/windows/${ENV:PUPPET_REPO}/puppet-agent-x64-latest.msi"
Write-Output "Installing Puppet from $agent_url"
Write-Output "Log will be written to $log"
if ( Test-Path $log ) { Remove-Item $log }
cd C:\downloads
if (!(Test-Path "puppet-agent-x64-latest.msi")) { Start-FileDownload $agent_url }
Start-Process msiexec.exe -Wait -NoNewWindow -ArgumentList @("/i", "C:\downloads\puppet-agent-x64-latest.msi", "/qn", "/l*", "$log")
cd $ENV:APPVEYOR_BUILD_FOLDER
- ps: Copy-Item -Path $ENV:APPVEYOR_BUILD_FOLDER -Destination C:/ProgramData/PuppetLabs/code/environments/production/modules/sensu -Recurse
- ps: Copy-Item -Path "${ENV:APPVEYOR_BUILD_FOLDER}/tests/ssl" -Destination C:/ProgramData/PuppetLabs/puppet/etc/ssl -Recurse
- ps: Copy-Item -Path "${ENV:APPVEYOR_BUILD_FOLDER}/lib/facter" -Destination C:/ProgramData/PuppetLabs/puppet/cache/lib/facter -Recurse
- set PATH=C:\Program Files\Puppet Labs\Puppet\bin;%PATH%
- puppet --version
- puppet module install puppetlabs-stdlib
- puppet module install puppet-archive
- puppet config set --section main certname sensu_agent
- facter -p --debug
- ruby -v
- gem update --system 2.7.9
- gem -v
- bundle -v
- bundle install --jobs 4 --retry 2 --path C:\vendor\bundle
test_script:
- bundle exec rake acceptance:windows
image:
treydock marked this conversation as resolved.
Show resolved Hide resolved
# Windows 2012 R2
- Visual Studio 2015
# Windows 2016
- Visual Studio 2017
environment:
treydock marked this conversation as resolved.
Show resolved Hide resolved
matrix:
- PUPPET_GEM_VERSION: '~>5.x'
PUPPET_REPO: puppet5
RUBY_VERSION: 24-x64
- PUPPET_GEM_VERSION: '~>6.x'
PUPPET_REPO: puppet6
RUBY_VERSION: 25-x64
matrix:
fast_finish: false
8 changes: 7 additions & 1 deletion data/os/windows.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
---
sensu::etc_dir: 'C:/opt/sensu'
sensu::manage_repo: false
sensu::etc_dir: 'C:\ProgramData\Sensu\config'
sensu::ssl_dir: 'C:\ProgramData\Sensu\config\ssl'
sensu::agent::package_name: 'Sensu Agent'
sensu::agent::package_download_path: 'C:\'
sensu::agent::log_file: 'C:\ProgramData\sensu\log\sensu-agent.log'
sensu::agent::service_name: SensuAgent
13 changes: 11 additions & 2 deletions lib/facter/sensu_facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@

module SensuFacts
def self.which(cmd)
path = Facter::Core::Execution.which(cmd)
path = nil
if File.exists?("C:\\Program Files\\sensu\\sensu-agent\\bin\\#{cmd}.exe")
path = "C:\\Program Files\\sensu\\sensu-agent\\bin\\#{cmd}.exe"
else
path = Facter::Core::Execution.which(cmd)
end
path
end

def self.get_version_info(cmd)
path = self.which(cmd)
return nil unless path
output = Facter::Core::Execution.exec("#{path} version 2>&1")
if Facter.value(:kernel) == 'windows'
output = Facter::Core::Execution.exec("\"#{path}\" version")
else
output = Facter::Core::Execution.exec("#{path} version 2>&1")
end
version = nil
if output =~ /^#{cmd} version ([^,]+)/
version = $1.split('#')[0]
Expand Down
58 changes: 56 additions & 2 deletions manifests/agent.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
# @param version
# Version of sensu agent to install. Defaults to `installed` to support
# Windows MSI packaging and to avoid surprising upgrades.
# @param package_source
# Source of package for installing Windows.
# Paths with http:// or https:// will be downloaded
# Paths with puppet:// or absolute filesystem paths will also be installed.
# @param package_download_path
# Where to download the MSI for Windows. Defaults to `C:\`.
# This parameter only used when `package_source` is an URL or when it's a puppet source (`puppet://`).
# @param package_name
# Name of Sensu agent package.
# @param service_name
Expand All @@ -30,16 +37,22 @@
# Passing `backend-url` as part of `config_hash` takes precedence.
# @param show_diff
# Sets show_diff parameter for agent.yml configuration file
# @param log_file
# Path to agent log file, only for Windows.
# Defaults to `C:\ProgramData\sensu\log\sensu-agent.log`
#
class sensu::agent (
Optional[String] $version = undef,
Optional[String[1]] $package_source = undef,
Optional[Stdlib::Absolutepath] $package_download_path = undef,
String $package_name = 'sensu-go-agent',
String $service_name = 'sensu-agent',
String $service_ensure = 'running',
Boolean $service_enable = true,
Hash $config_hash = {},
Array[Sensu::Backend_URL] $backends = ['localhost:8081'],
Boolean $show_diff = true,
Optional[Stdlib::Absolutepath] $log_file = undef,
) {

include ::sensu
Expand All @@ -52,7 +65,7 @@
if $use_ssl {
$backend_protocol = 'wss'
$ssl_config = {
'trusted-ca-file' => "${ssl_dir}/ca.crt",
'trusted-ca-file' => $::sensu::trusted_ca_file_path,
}
$service_subscribe = Class['::sensu::ssl']
} else {
Expand All @@ -72,17 +85,58 @@
}
$config = $default_config + $ssl_config + $config_hash

if $facts['os']['family'] == 'windows' {
$sensu_agent_exe = "C:\\Program Files\\sensu\\sensu-agent\\bin\\sensu-agent.exe"
exec { 'install-agent-service':
command => "C:\\windows\\system32\\cmd.exe /c \"\"${sensu_agent_exe}\" service install --config-file \"${::sensu::agent_config_path}\" --log-file \"${log_file}\"\"",
unless => "C:\\windows\\system32\\sc.exe query SensuAgent",
before => Service['sensu-agent'],
require => [
Package['sensu-go-agent'],
File['sensu_agent_config'],
],
}
if $package_source and ($package_source =~ Stdlib::HTTPSUrl or $package_source =~ Stdlib::HTTPUrl) {
$package_source_basename = basename($package_source)
$_package_source = "${package_download_path}\\${package_source_basename}"
archive { 'sensu-go-agent.msi':
source => $package_source,
path => $_package_source,
extract => false,
cleanup => false,
before => Package['sensu-go-agent'],
}
} elsif $package_source and $package_source =~ /^puppet:/ {
$package_source_basename = basename($package_source)
$_package_source = "${package_download_path}\\${package_source_basename}"
file { 'sensu-go-agent.msi':
ensure => 'file',
path => $_package_source,
source => $package_source,
before => Package['sensu-go-agent'],
}
} else {
$_package_source = $package_source
}
} else {
$_package_source = undef
}

package { 'sensu-go-agent':
ensure => $_version,
name => $package_name,
source => $_package_source,
before => File['sensu_etc_dir'],
require => $::sensu::package_require,
}

file { 'sensu_agent_config':
ensure => 'file',
path => "${etc_dir}/agent.yml",
path => $::sensu::agent_config_path,
content => to_yaml($config),
owner => $::sensu::sensu_user,
group => $::sensu::sensu_group,
mode => $::sensu::file_mode,
show_diff => $show_diff,
require => Package['sensu-go-agent'],
notify => Service['sensu-agent'],
Expand Down
Loading