Skip to content

Commit

Permalink
fix voxpupuli#227 add prefix parameter to objects with apply parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
lbetz authored and n00by committed Apr 26, 2018
1 parent 506f4e2 commit 9295e1b
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,9 @@ A list of state filters when this dependency should be OK. Defaults to [ OK, War
Dispose an apply instead an object if set to 'true'. Value is taken as statement,
i.e. 'vhost => config in host.vars.vhosts'. Defaults to false.

##### `prefix`
Set dependency_name as prefix in front of 'apply for'. Only effects if apply is a string. Defaults to false.

##### `apply_target`
An object type on which to target the apply rule. Valid values are `Host` and `Service`. Defaults to `Host`.

Expand Down Expand Up @@ -1892,6 +1895,9 @@ A list of state filters when this notification should be triggered. By default e
Dispose an apply instead an object if set to 'true'. Value is taken as statement,
i.e. 'vhost => config in host.vars.vhosts'. Defaults to false.

##### `prefix`
Set notification_name as prefix in front of 'apply for'. Only effects if apply is a string. Defaults to false.

##### `apply_target`
An object type on which to target the apply rule. Valid values are `Host` and `Service`. Defaults to `Host`.

Expand Down Expand Up @@ -2003,6 +2009,9 @@ Icon image description for the service. Used by external interface only.
Dispose an apply instead an object if set to 'true'. Value is taken as statement,
i.e. 'vhost => config in host.vars.vhosts'. Defaults to false.

##### `prefix`
Set service_name as prefix in front of 'apply for'. Only effects if apply is a string. Defaults to false.

##### `assign`
Assign user group members using the group assign rules.

Expand Down Expand Up @@ -2127,6 +2136,9 @@ A dictionary containing information which days and durations apply to this timep
Dispose an apply instead an object if set to 'true'. Value is taken as statement,
i.e. 'vhost => config in host.vars.vhosts'. Defaults to false.

##### `prefix`
Set scheduleddowntime_name as prefix in front of 'apply for'. Only effects if apply is a string. Defaults to false.

##### `apply_target`
An object type on which to target the apply rule. Valid values are `Host` and `Service`. Defaults to `Host`.

Expand Down
80 changes: 80 additions & 0 deletions examples/init_example_config.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
class { '::icinga2':
manage_repo => true,
confd => 'example.d',
}

file { '/etc/icinga2/example.d':
ensure => directory,
tag => 'icinga2::config::file',
}

::icinga2::object::host { 'generic-host':
template => true,
target => '/etc/icinga2/example.d/templates.conf',
check_interval => '1m',
retry_interval => '30s',
max_check_attempts => 3,
check_command => 'hostalive',
}

::icinga2::object::service { 'generic-service':
template => true,
target => '/etc/icinga2/example.d/templates.conf',
check_interval => '1m',
retry_interval => '30s',
max_check_attempts => 5,
}

::icinga2::object::host { 'host1.example.org':
target => '/etc/icinga2/example.d/hosts.conf',
import => [ 'generic-host' ],
address => '127.0.0.1',
vars => {
os => 'Linux',
http_vhosts => {
httpd => {
http_uri => '/',
},
},
procs => {
httpd => {
procs_command => 'httpd',
},
},
},
}

::icinga2::object::service { 'ping4':
target => '/etc/icinga2/example.d/services.conf',
apply => true,
import => [ 'generic-service' ],
check_command => 'ping4',
assign => [ 'host.address' ],
}

::icinga2::object::service { 'ssh':
target => '/etc/icinga2/example.d/services.conf',
apply => true,
import => [ 'generic-service' ],
check_command => 'ssh',
assign => [ '(host.address || host.address6) && host.vars.os == Linux' ],
}

::icinga2::object::service { 'http':
target => '/etc/icinga2/example.d/services.conf',
apply => 'vhost => config in host.vars.http_vhosts',
import => [ 'generic-service' ],
check_command => 'http',
vars => 'vars + config',
}

::icinga2::object::service { 'proc-':
target => '/etc/icinga2/example.d/services.conf',
apply => 'proc => config in host.vars.procs',
prefix => true,
import => [ 'generic-service' ],
check_command => 'procs',
display_name => 'proc + proc',
vars => 'vars + config',
assign => [ 'host.vars.os == Linux' ],
}
5 changes: 5 additions & 0 deletions manifests/object.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
# Dispose an apply instead an object if set to 'true'. Value is taken as statement,
# i.e. 'vhost => config in host.vars.vhosts'. Defaults to false.
#
# [*prefix*]
# Set object_name as prefix in front of 'apply for'. Only effects if apply is a string. Defaults to false.
#
# [*apply_target*]
# An object type on which to target the apply rule. Valid values are `Host` and `Service`. Defaults to `Host`.
#
Expand Down Expand Up @@ -63,6 +66,7 @@
$template = false,
$apply = false,
$apply_target = undef,
$prefix = false,
$import = [],
$assign = [],
$ignore = [],
Expand Down Expand Up @@ -98,6 +102,7 @@
validate_string($object_name)
validate_bool($template)
unless is_bool($apply) { validate_re($apply, '^.+\s+(=>\s+.+\s+)?in\s+.+$') }
validate_bool($prefix)
if $apply_target { validate_re($apply_target, ['^Host$', '^Service$'],
"${apply_target} isn't supported. Valid values are 'Host' and 'Service'.") }
validate_array($import)
Expand Down
6 changes: 6 additions & 0 deletions manifests/object/dependency.pp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
# Dispose an apply instead an object if set to 'true'. Value is taken as statement,
# i.e. 'vhost => config in host.vars.vhosts'. Defaults to false.
#
# [*prefix*]
# Set dependency_name as prefix in front of 'apply for'. Only effects if apply is a string. Defaults to false.
#
# [*apply_target*]
# An object type on which to target the apply rule. Valid values are `Host`
# and `Service`. Defaults to `Host`.
Expand Down Expand Up @@ -84,6 +87,7 @@
$period = undef,
$states = undef,
$apply = false,
$prefix = false,
$apply_target = 'Host',
$assign = [],
$ignore = [],
Expand All @@ -100,6 +104,7 @@
"${ensure} isn't supported. Valid values are 'present' and 'absent'.")
validate_string($dependency_name)
unless is_bool($apply) { validate_string($apply) }
validate_bool($prefix)
validate_re($apply_target, ['^Host$', '^Service$'],
"${apply_target} isn't supported. Valid values are 'Host' and 'Service'.")
validate_array($import)
Expand Down Expand Up @@ -139,6 +144,7 @@
template => $template,
attrs => $attrs,
apply => $apply,
prefix => $prefix,
apply_target => $apply_target,
assign => $assign,
ignore => $ignore,
Expand Down
6 changes: 6 additions & 0 deletions manifests/object/notification.pp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
# Dispose an apply instead an object if set to 'true'. Value is taken as statement,
# i.e. 'vhost => config in host.vars.vhosts'. Defaults to false.
#
# [*prefix*]
# Set notification_name as prefix in front of 'apply for'. Only effects if apply is a string. Defaults to false.
#
# [*apply_target*]
# An object type on which to target the apply rule. Valid values are `Host` and `Service`. Defaults to `Host`.
#
Expand Down Expand Up @@ -92,6 +95,7 @@
$types = undef,
$states = undef,
$apply = false,
$prefix = false,
$apply_target = 'Host',
$assign = [],
$ignore = [],
Expand All @@ -108,6 +112,7 @@
"${ensure} isn't supported. Valid values are 'present' and 'absent'.")
validate_string($notification_name)
unless is_bool($apply) { validate_string($apply) }
validate_bool($prefix)
validate_re($apply_target, ['^Host$', '^Service$'],
"${apply_target} isn't supported. Valid values are 'Host' and 'Service'.")
validate_array($import)
Expand Down Expand Up @@ -164,6 +169,7 @@
target => $target,
order => $order,
apply => $apply,
prefix => $prefix,
apply_target => $apply_target,
assign => $assign,
ignore => $ignore,
Expand Down
6 changes: 6 additions & 0 deletions manifests/object/scheduleddowntime.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
# Dispose an apply instead an object if set to 'true'. Value is taken as statement,
# i.e. 'vhost => config in host.vars.vhosts'. Defaults to false.
#
# [*prefix*]
# Set scheduleddowntime_name as prefix in front of 'apply for'. Only effects if apply is a string. Defaults to false.
#
# [*apply_target*]
# An object type on which to target the apply rule. Valid values are `Host` and `Service`. Defaults to `Host`.
#
Expand Down Expand Up @@ -64,6 +67,7 @@
$duration = undef,
$ranges = undef,
$apply = false,
$prefix = false,
$apply_target = 'Host',
$assign = [],
$ignore = [],
Expand All @@ -78,6 +82,7 @@
"${ensure} isn't supported. Valid values are 'present' and 'absent'.")
validate_string($scheduleddowntime_name)
unless is_bool($apply) { validate_string($apply) }
validate_bool($prefix)
validate_re($apply_target, ['^Host$', '^Service$'],
"${apply_target} isn't supported. Valid values are 'Host' and 'Service'.")
validate_absolute_path($target)
Expand Down Expand Up @@ -109,6 +114,7 @@
object_type => 'ScheduledDowntime',
attrs => $attrs,
apply => $apply,
prefix => $prefix,
apply_target => $apply_target,
assign => $assign,
ignore => $ignore,
Expand Down
6 changes: 6 additions & 0 deletions manifests/object/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
# Dispose an apply instead an object if set to 'true'. Value is taken as statement,
# i.e. 'vhost => config in host.vars.vhosts'. Defaults to false.
#
# [*prefix*]
# Set service_name as prefix in front of 'apply for'. Only effects if apply is a string. Defaults to false.
#
# [*assign*]
# Assign user group members using the group assign rules.
#
Expand Down Expand Up @@ -185,6 +188,7 @@
$icon_image = undef,
$icon_image_alt = undef,
$apply = false,
$prefix = false,
$assign = [],
$ignore = [],
$import = [],
Expand All @@ -201,6 +205,7 @@
"${ensure} isn't supported. Valid values are 'present' and 'absent'.")
validate_string($service_name)
unless is_bool($apply) { validate_string($apply) }
validate_bool($prefix)
validate_array($import)
validate_bool($template)
validate_absolute_path($target)
Expand Down Expand Up @@ -270,6 +275,7 @@
object_type => 'Service',
import => $import,
apply => $apply,
prefix => $prefix,
apply_target => 'Host',
assign => $assign,
ignore => $ignore,
Expand Down
9 changes: 8 additions & 1 deletion templates/object.conf.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@

<% if @apply.is_a?(String) %>apply <%= @object_type -%> for (<%= @apply %>) to <%= @apply_target -%> {
<% if @apply.is_a?(String) %>apply <%= @object_type -%>
<% if @prefix -%>
<% if scope.lookupvar('icinga2::_constants').include?(@object_name) -%>
<%= @object_name -%>
<% else -%>
"<%= @object_name %>" <% end -%>
<% end -%>
for (<%= @apply %>) to <%= @apply_target -%> {
<% else -%>
<% if @apply %>apply<% else -%>
<% if @template %>template<% else %>object<% end -%>
Expand Down

0 comments on commit 9295e1b

Please sign in to comment.