Skip to content

Commit

Permalink
Add windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
ripclawffb committed Jan 24, 2017
1 parent f617cd5 commit 46bbed4
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 18 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ There's a couple of fairly standard dependencies for this module, as follows:
for TLS-enabled repos in place. This can be achieved by installing the
`apt-transport-https` package.

In addition, for Windows, the following dependencies must be met:

* Chocolatey installed
* [`chocolatey/chocolatey`](https://forge.puppet.com/chocolatey/chocolatey) OR [`puppetlabs/chocolatey`](https://forge.puppet.com/puppetlabs/chocolatey)
* **Note:** either or both of these modules can handle ensuring the install of Chocolatey.

### Usage

Telegraf's configuration is split into four main sections - global tags,
Expand Down Expand Up @@ -162,6 +168,18 @@ Will create the file `/etc/telegraf/telegraf.d/snmp.conf`:
version = 2
get_oids = ["1.3.6.1.2.1.1.5"]

Example 4:

```puppet
class { '::telegraf':
ensure => '1.0.1',
hostname => $::hostname,
windows_package_url => http://internal_repo:8080/chocolatey,
}
```

Will install telegraf version 1.0.1 on Windows using an internal chocolatey repo

## Hierarchical configuration from multiple files

Hiera YAML and JSON backends support [deep hash merging](https://docs.puppet.com/hiera/3.1/configuring.html#mergebehavior) which is needed for inheriting configuration from multiple files.
Expand Down Expand Up @@ -214,6 +232,7 @@ This module has been developed and tested against:
* Debian 8
* CentOS / RHEL 6
* CentOS / RHEL 7
* Windows 2008, 2008 R2, 2012, 2012 R2

Support for other distributions / operating systems is planned. Feel free to assist with development in this regard!

Expand Down
10 changes: 5 additions & 5 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
$::telegraf::config_file:
ensure => file,
content => template('telegraf/telegraf.conf.erb'),
owner => 'telegraf',
group => 'telegraf',
owner => $::telegraf::config_file_owner,
group => $::telegraf::config_file_group,
mode => '0640',
notify => Class['::telegraf::service'],
require => Class['::telegraf::install'],
;
$::telegraf::config_fragment_dir:
$::telegraf::config_folder:
ensure => directory,
owner => 'telegraf',
group => 'telegraf',
owner => $::telegraf::config_file_owner,
group => $::telegraf::config_file_group,
mode => '0750',
purge => $::telegraf::purge_config_fragments,
recurse => true,
Expand Down
28 changes: 24 additions & 4 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
# [*config_file*]
# String. Path to the configuration file.
#
# [*config_fragment_dir*]
# String. Path to the configuration fragment directory.
# [*config_file_owner*]
# String. User to own the telegraf config file.
#
# [*config_file_group*]
# String. Group to own the telegraf config file.
#
# [*config_folder*]
# String. Path of additional telegraf config files.
#
# [*hostname*]
# String. Override default hostname used to identify this agent.
Expand Down Expand Up @@ -69,10 +75,15 @@
# [*repo_type*]
# String. Which repo (stable, unstable, nightly) to use
#
# [*windows_package_url*]
# String. URL for windows telegraf chocolatey repo
#
class telegraf (
$ensure = $telegraf::params::ensure,
$config_file = $telegraf::params::config_file,
$config_fragment_dir = $telegraf::params::config_fragment_dir,
$config_file_owner = $telegraf::params::config_file_owner,
$config_file_group = $telegraf::params::config_file_group,
$config_folder = $telegraf::params::config_folder,
$hostname = $telegraf::params::hostname,
$omit_hostname = $telegraf::params::omit_hostname,
$interval = $telegraf::params::interval,
Expand All @@ -91,12 +102,18 @@
$manage_repo = $telegraf::params::manage_repo,
$purge_config_fragments = $telegraf::params::purge_config_fragments,
$repo_type = $telegraf::params::repo_type,
$windows_package_url = $telegraf::params::windows_package_url,
) inherits ::telegraf::params
{

$service_hasstatus = $telegraf::params::service_hasstatus
$service_restart = $telegraf::params::service_restart

validate_string($ensure)
validate_string($config_file)
validate_absolute_path($config_fragment_dir)
validate_string($config_file_owner)
validate_string($config_file_group)
validate_absolute_path($config_folder)
validate_string($hostname)
validate_bool($omit_hostname)
validate_string($interval)
Expand All @@ -115,6 +132,9 @@
validate_bool($manage_repo)
validate_bool($purge_config_fragments)
validate_string($repo_type)
validate_string($windows_package_url)
validate_bool($service_hasstatus)
validate_string($service_restart)

# currently the only way how to obtain merged hashes
# from multiple files (`:merge_behavior: deeper` needs to be
Expand Down
2 changes: 1 addition & 1 deletion manifests/input.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

Class['::telegraf::config']
->
file {"${telegraf::config_fragment_dir}/${name}.conf":
file {"${telegraf::config_folder}/${name}.conf":
content => template('telegraf/input.conf.erb')
}
~>
Expand Down
19 changes: 17 additions & 2 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,27 @@
}
Yumrepo['influxdata'] -> Package['telegraf']
}
'windows': {
# repo is not applicable to windows
}
default: {
fail('Only RedHat, CentOS, Debian and Ubuntu are supported at this time')
fail('Only RedHat, CentOS, Debian, Ubuntu and Windows are supported at this time')
}
}
}

ensure_packages(['telegraf'], { ensure => $::telegraf::ensure })
if $::osfamily == 'windows' {
# required to install telegraf on windows
require chocolatey

# package install
package { 'telegraf':
ensure => $::telegraf::ensure,
provider => chocolatey,
source => $::telegraf::windows_package_url,
}
} else {
ensure_packages(['telegraf'], { ensure => $::telegraf::ensure })
}

}
24 changes: 20 additions & 4 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,27 @@
#
class telegraf::params {

if $::osfamily == 'windows' {
$config_file = 'C:/Program Files/telegraf/telegraf.conf'
$config_file_owner = 'Administrator'
$config_file_group = 'Administrators'
$config_folder = 'C:/Program Files/telegraf/telegraf.d'
$windows_package_url = 'https://chocolatey.org/api/v2/'
$manage_repo = false
$service_hasstatus = false
$service_restart = undef
} else {
$config_file = '/etc/telegraf/telegraf.conf'
$config_file_owner = 'telegraf'
$config_file_group = 'telegraf'
$config_folder = '/etc/telegraf/telegraf.d'
$repo_type = 'stable'
$manage_repo = true
$service_hasstatus = true
$service_restart = 'pkill -HUP telegraf'
}

$ensure = 'present'
$config_file = '/etc/telegraf/telegraf.conf'
$config_fragment_dir = '/etc/telegraf/telegraf.d'
$hostname = $::hostname
$omit_hostname = false
$interval = '10s'
Expand All @@ -20,9 +38,7 @@
$quiet = false
$global_tags = {}
$manage_service = true
$manage_repo = true
$purge_config_fragments = false
$repo_type = 'stable'

$outputs = {
'influxdb' => {
Expand Down
4 changes: 2 additions & 2 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
if $::telegraf::manage_service {
service { 'telegraf':
ensure => running,
hasstatus => true,
hasstatus => $telegraf::service_hasstatus,
enable => true,
restart => 'pkill -HUP telegraf',
restart => $telegraf::service_restart,
require => Class['::telegraf::config'],
}
}
Expand Down
4 changes: 4 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
"operatingsystem": "RedHat",
"operatingsystemrelease": [ "6", "7" ]
}
{
"operatingsystem": "Windows",
"operatingsystemrelease": [ "Server 2008 R2", "Server 2012", "Server 2012 R2" ]
}
],
"dependencies": [
{ "name": "puppetlabs-stdlib", "version_requirement": ">=4.10.0 < 5.0.0" },
Expand Down

0 comments on commit 46bbed4

Please sign in to comment.