Skip to content

Commit

Permalink
WIP (sensu#637) Add check proxy_requests functionality
Browse files Browse the repository at this point in the history
Left off setting up an example for proxy request checks using Vagrant.  Pick
back up here following the proxy requests guide:

https://sensuapp.org/docs/0.29/reference/checks.html#proxy-requests-attributes
  • Loading branch information
jeffmccune committed Jul 12, 2017
1 parent 9e5b3d9 commit 35830c0
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/puppet/provider/sensu_check/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,4 @@ def set_property(property, value)
conf['checks'][resource[:name]][property.to_s] = value
end
end

end
5 changes: 5 additions & 0 deletions lib/puppet/type/sensu_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ def insync?(is)
newvalues(/.*/, :absent)
end

newproperty(:proxy_requests) do
desc "Proxy Requests"
newvalues(/.*/, :absent)
end

newproperty(:ttl) do
desc "Check ttl in seconds"
newvalues(/.*/, :absent)
Expand Down
18 changes: 18 additions & 0 deletions manifests/check.pp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@
# Set this to 'absent' to remove it completely.
# Default: undef
#
# [*proxy_requests*]
# Hash. [Proxy Check
# Requests](https://sensuapp.org/docs/latest/reference/checks.html#proxy-requests-attributes)
# Since Sensu 0.28.0. Publishes a check request to every Sensu client which
# matches the defined client attributes. See the documentation for the format
# of the Hash value.
# Default: undef
define sensu::check(
$command,
$ensure = 'present',
Expand All @@ -133,6 +140,7 @@
$custom = undef,
$ttl = undef,
$subdue = undef,
$proxy_requests = undef,
) {

validate_re($ensure, ['^present$', '^absent$'] )
Expand Down Expand Up @@ -187,6 +195,15 @@
if $aggregates and !is_array($aggregates) and !is_string($aggregates) {
fail("sensu::check{${name}}: aggregates must be an array or a string (got: ${aggregates})")
}
if $proxy_requests {
if is_has($proxy_requests) {
if !( has_key($proxy_requests, 'client_attributes') ) {
fail("sensu::check{${name}}: proxy_requests hash should have a proper format. (got: ${proxy_requests}) See https://sensuapp.org/docs/latest/reference/checks.html#proxy-requests-attributes")
}
} elsif !($proxy_requests == 'absent') {
fail("sensu::check{${name}}: proxy_requests must be a hash or 'absent' (got: ${proxy_requests})")
}
}

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

Expand Down Expand Up @@ -238,6 +255,7 @@
dependencies => $dependencies,
custom => $custom,
subdue => $subdue,
proxy_requests => $proxy_requests,
require => File["${conf_dir}/checks"],
notify => $::sensu::check_notify,
ttl => $ttl,
Expand Down
55 changes: 55 additions & 0 deletions tests/sensu-client-proxy.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Proxy Client. See:
# https://sensuapp.org/docs/latest/guides/getting-started/adding-a-client.html#proxy-clients
node default {
$filters = {
'offhours' => {
'attributes' => {
'client' => {
'environment' => 'production',
},
},
'when' => {
'days' => {
'all' => [
{
'begin' => '2:00 AM',
'end' => '1:00 AM',
},
],
},
},
},
}

$filter_defaults = {
'when' => {
'days' => {
'all' => [
{
'begin' => '2:00 AM',
'end' => '1:00 AM',
},
],
},
},
}

# Use the internal 192.168.56.* address
if $facts['networking']['interfaces']['eth1'] != undef {
$ip = $facts['networking']['interfaces']['eth1']['ip']
} elsif $facts['networking']['interfaces']['enp0s8'] != undef {
$ip = $facts['networking']['interfaces']['enp0s8']['ip']
} else {
$ip = $facts['networking']['ip']
}

class { '::sensu':
rabbitmq_password => 'correct-horse-battery-staple',
rabbitmq_host => '192.168.56.10',
rabbitmq_vhost => '/sensu',
subscriptions => 'all',
client_address => $ip,
filters => $filters,
filter_defaults => $filter_defaults,
}
}
98 changes: 98 additions & 0 deletions tests/sensu-server-proxy-checks.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# This test manifest is intended to layer on top of the sensu-server Vagrant VM.
# It defines additional checks executed using proxy clients. To add a remote
# proxy client, use the Uchiwa UI at http://localhost:3000/#/clients and add a
# client like so. Once added, request a check for `remote_http` and it will
# automatically run against the Google proxy client.
#
# {
# "address": "www.google.com",
# "keepalives": false,
# "name": "google",
# "subscriptions": [
# "client:google",
# "http"
# ],
# "type": "proxy"
# }
node 'sensu-server' {
Package {
ensure => installed,
}
Sensu::Plugin {
type => 'package',
pkg_provider => 'sensu_gem',
pkg_version => 'installed',
require => [Package['gcc-c++']],
}

class { '::sensu':
install_repo => true,
server => true,
manage_services => true,
manage_user => true,
rabbitmq_password => 'correct-horse-battery-staple',
rabbitmq_vhost => '/sensu',
api => true,
api_user => 'admin',
api_password => 'secret',
client_address => $::ipaddress_eth1,
subscriptions => ['all', 'poller', 'proxytarget', 'roundrobin:poller'],
}

sensu::handler { 'default':
command => 'mail -s \'sensu alert\' [email protected]',
}

sensu::check { 'check_ntp':
command => 'PATH=$PATH:/usr/lib64/nagios/plugins check_ntp_time -H pool.ntp.org -w 30 -c 60',
handlers => 'default',
subscribers => 'sensu-test',
}

# sensu-plugins-http requires a c++ compiler during install
package { 'gcc-c++': }

# (#637) Create a [Proxy
# Check](https://sensuapp.org/docs/latest/reference/checks.html#proxy-requests-attributes)
# This needs to have a corresponding sensu-client matching the client
# attributes.
sensu::plugin { 'sensu-plugins-http': }

# A client defined in the Dashboard with a subscription of "http" will
# automatically have this check associated with it.
sensu::check { 'remote_http':
command => "/opt/sensu/embedded/bin/check-http.rb -u http://:::address:::",
occurrences => 2,
interval => 300,
refresh => 600,
low_flap_threshold => 20,
high_flap_threshold => 60,
standalone => false,
subscribers => 'roundrobin:poller',
custom => {
'proxy_requests' => {
'client_attributes' => {
'subscriptions' => 'eval: value.include?("http")'
}
}
},
}
# Similar to above, but not using round robin checks.
sensu::check { 'remote_http-dashboard':
command => "/opt/sensu/embedded/bin/check-http.rb -u http://:::address::::3000",
occurrences => 2,
interval => 300,
refresh => 600,
low_flap_threshold => 20,
high_flap_threshold => 60,
standalone => false,
subscribers => 'poller',
custom => {
'proxy_requests' => {
'client_attributes' => {
'subscriptions' => 'eval: value.include?("proxytarget")'
}
}
},
}
}

0 comments on commit 35830c0

Please sign in to comment.