From d96a439357514a7edd0d2def9563930ecaa491b9 Mon Sep 17 00:00:00 2001 From: Ricardo Melo Date: Tue, 4 Nov 2014 12:40:30 -0500 Subject: [PATCH 01/11] + Added scheduleddowntime object. #7218 --- README.md | 21 ++++++++ manifests/object/scheduleddowntime.pp | 54 +++++++++++++++++++++ templates/object_scheduleddowntime.conf.erb | 38 +++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 manifests/object/scheduleddowntime.pp create mode 100644 templates/object_scheduleddowntime.conf.erb diff --git a/README.md b/README.md index d8af224..8820d5f 100644 --- a/README.md +++ b/README.md @@ -336,6 +336,7 @@ Object types: * [icinga2::object::idomysqlconnection](id:object_idomysqlconnection) * [icinga2::object::idopgsqlconnection](id:object_idopgsqlconnection) * [icinga2::object::notificationcommand](id:object_notificationcommand) +* [icinga2::object::scheduleddowntime](id:object_scheduleddowntime) * [icinga2::object::service](id:object_service) * [icinga2::object::servicegroup](id:object_servicegroup) * [icinga2::object::syslogger](id:object_syslogger) @@ -581,6 +582,26 @@ icinga2::object::notificationcommand { 'mail-service-notification': This oobject use the same parameter defined to `checkcommand`. +####[`icinga2::object::sicheduleddownload`](id:object_scheduleddownload) + +This defined type creates **ScheduledDowntime** objects + +Example usage: + +
+icinga2::object::scheduleddowntime {'some-downtime':
+  host_name    => 'localhost',
+  service_name => 'ping4',
+  author       => 'icingaadmin',
+  comment      => 'Some comment',
+  fixed        => false,
+  duration     => '30m',
+  ranges       => { 'sunday' => '02:00-03:00' }
+}
+
+ + + ####[`icinga2::object::service`](id:object_service) Coming soon... diff --git a/manifests/object/scheduleddowntime.pp b/manifests/object/scheduleddowntime.pp new file mode 100644 index 0000000..65db762 --- /dev/null +++ b/manifests/object/scheduleddowntime.pp @@ -0,0 +1,54 @@ +# == Defined type: icinga2::object::scheduleddowntime +# +# This is a defined type for Icinga 2 ScheduledDowntime objects. +# See the following Icinga 2 doc page for more info: +# http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/configuring-icinga2#objecttype-scheduleddowntime +# +# === Parameters +# +# See the inline comments. +# + +define icinga2::object::scheduleddowntime ( + $object_scheduleddowntimename = $name, + $host_name = undef, + $service_name = undef, + $author = undef, + $comment = undef, + $fixed = true, + $duration = undef, + $ranges = {}, + $target_dir = '/etc/icinga2/objects/scheduleddowntimes', + $target_file_name = "${name}.conf", + $target_file_owner = 'root', + $target_file_group = 'root', + $target_file_mode = '0644' +) { + + #Do some validation of the define's parameters: + validate_string($object_scheduleddowntimename) + validate_string($host_name) + if $service_name { + validate_string($service_name) + } + validate_string($author) + validate_string($comment) + validate_bool($fixed) + validate_string($duration) + validate_hash($ranges) + validate_string($target_dir) + validate_string($target_file_name) + validate_string($target_file_owner) + validate_string($target_file_group) + validate_string($target_file_mode) + + file {"${target_dir}/${target_file_name}": + ensure => file, + owner => $target_file_owner, + group => $target_file_group, + mode => $target_file_mode, + content => template('icinga2/object_scheduleddowntime.conf.erb'), + notify => Service['icinga2'], + } + +} diff --git a/templates/object_scheduleddowntime.conf.erb b/templates/object_scheduleddowntime.conf.erb new file mode 100644 index 0000000..4793aeb --- /dev/null +++ b/templates/object_scheduleddowntime.conf.erb @@ -0,0 +1,38 @@ +/** + * WARNING: This scheduleddowntime definition is automatically generated by Puppet. + * ANY MANUAL CHANGES TO IT WILL GET OVERWRITTEN! + */ + +/** + * A ScheduledDowntime definition. You can create your own configuration files + * in the conf.d directory (e.g. one per host). By default all *.conf + * files in this directory are included. + * + */ + +object ScheduledDowntime "<%= @object_scheduleddowntimename %>" { + <%#- If any of the @ parameters are undefined, don't print anything for them: -%> + + host_name = "<%= @host_name -%>" + <%- if @service_name -%> + service_name = "<%= @service_name -%>" + <%- end -%> + + author = "<%= @author -%>" + comment = "<%= @comment -%>" + + <%- if @fixed != true -%> + fixed = false + <%- end -%> + <%- if @duration -%> + duration = <%= @duration -%> + <%- end -%> + <%- if @ranges.empty? != true -%> + + ranges = { + <%- @ranges.each_pair do |key, value| -%> + "<%= key %>" = "<%= value %>" + <%- end -%> + } + <%- end -%> +} From a52b14d4a18b0ff8b98a14128ed07a0529c3081a Mon Sep 17 00:00:00 2001 From: Ricardo Melo Date: Tue, 11 Nov 2014 18:28:23 -0500 Subject: [PATCH 02/11] * fixed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8820d5f..788bc24 100644 --- a/README.md +++ b/README.md @@ -582,7 +582,7 @@ icinga2::object::notificationcommand { 'mail-service-notification': This oobject use the same parameter defined to `checkcommand`. -####[`icinga2::object::sicheduleddownload`](id:object_scheduleddownload) +####[`icinga2::object::scheduleddownload`](id:object_scheduleddownload) This defined type creates **ScheduledDowntime** objects From b126dd56861727795886c9ca8f325ee32064e957 Mon Sep 17 00:00:00 2001 From: Ricardo Melo Date: Tue, 4 Nov 2014 12:40:30 -0500 Subject: [PATCH 03/11] + Added scheduleddowntime object. #7218 --- README.md | 21 ++++++++ manifests/object/scheduleddowntime.pp | 54 +++++++++++++++++++++ templates/object_scheduleddowntime.conf.erb | 38 +++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 manifests/object/scheduleddowntime.pp create mode 100644 templates/object_scheduleddowntime.conf.erb diff --git a/README.md b/README.md index a29f1c8..15b13e7 100644 --- a/README.md +++ b/README.md @@ -337,6 +337,7 @@ Object types: * [icinga2::object::idopgsqlconnection](id:object_idopgsqlconnection) * [icinga2::object::notification](id:object_notification) * [icinga2::object::notificationcommand](id:object_notificationcommand) +* [icinga2::object::scheduleddowntime](id:object_scheduleddowntime) * [icinga2::object::service](id:object_service) * [icinga2::object::servicegroup](id:object_servicegroup) * [icinga2::object::syslogger](id:object_syslogger) @@ -623,6 +624,26 @@ icinga2::object::notificationcommand { 'mail-service-notification': This object use the same parameter defined to `checkcommand`. +####[`icinga2::object::sicheduleddownload`](id:object_scheduleddownload) + +This defined type creates **ScheduledDowntime** objects + +Example usage: + +
+icinga2::object::scheduleddowntime {'some-downtime':
+  host_name    => 'localhost',
+  service_name => 'ping4',
+  author       => 'icingaadmin',
+  comment      => 'Some comment',
+  fixed        => false,
+  duration     => '30m',
+  ranges       => { 'sunday' => '02:00-03:00' }
+}
+
+ + + ####[`icinga2::object::service`](id:object_service) Coming soon... diff --git a/manifests/object/scheduleddowntime.pp b/manifests/object/scheduleddowntime.pp new file mode 100644 index 0000000..65db762 --- /dev/null +++ b/manifests/object/scheduleddowntime.pp @@ -0,0 +1,54 @@ +# == Defined type: icinga2::object::scheduleddowntime +# +# This is a defined type for Icinga 2 ScheduledDowntime objects. +# See the following Icinga 2 doc page for more info: +# http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/configuring-icinga2#objecttype-scheduleddowntime +# +# === Parameters +# +# See the inline comments. +# + +define icinga2::object::scheduleddowntime ( + $object_scheduleddowntimename = $name, + $host_name = undef, + $service_name = undef, + $author = undef, + $comment = undef, + $fixed = true, + $duration = undef, + $ranges = {}, + $target_dir = '/etc/icinga2/objects/scheduleddowntimes', + $target_file_name = "${name}.conf", + $target_file_owner = 'root', + $target_file_group = 'root', + $target_file_mode = '0644' +) { + + #Do some validation of the define's parameters: + validate_string($object_scheduleddowntimename) + validate_string($host_name) + if $service_name { + validate_string($service_name) + } + validate_string($author) + validate_string($comment) + validate_bool($fixed) + validate_string($duration) + validate_hash($ranges) + validate_string($target_dir) + validate_string($target_file_name) + validate_string($target_file_owner) + validate_string($target_file_group) + validate_string($target_file_mode) + + file {"${target_dir}/${target_file_name}": + ensure => file, + owner => $target_file_owner, + group => $target_file_group, + mode => $target_file_mode, + content => template('icinga2/object_scheduleddowntime.conf.erb'), + notify => Service['icinga2'], + } + +} diff --git a/templates/object_scheduleddowntime.conf.erb b/templates/object_scheduleddowntime.conf.erb new file mode 100644 index 0000000..4793aeb --- /dev/null +++ b/templates/object_scheduleddowntime.conf.erb @@ -0,0 +1,38 @@ +/** + * WARNING: This scheduleddowntime definition is automatically generated by Puppet. + * ANY MANUAL CHANGES TO IT WILL GET OVERWRITTEN! + */ + +/** + * A ScheduledDowntime definition. You can create your own configuration files + * in the conf.d directory (e.g. one per host). By default all *.conf + * files in this directory are included. + * + */ + +object ScheduledDowntime "<%= @object_scheduleddowntimename %>" { + <%#- If any of the @ parameters are undefined, don't print anything for them: -%> + + host_name = "<%= @host_name -%>" + <%- if @service_name -%> + service_name = "<%= @service_name -%>" + <%- end -%> + + author = "<%= @author -%>" + comment = "<%= @comment -%>" + + <%- if @fixed != true -%> + fixed = false + <%- end -%> + <%- if @duration -%> + duration = <%= @duration -%> + <%- end -%> + <%- if @ranges.empty? != true -%> + + ranges = { + <%- @ranges.each_pair do |key, value| -%> + "<%= key %>" = "<%= value %>" + <%- end -%> + } + <%- end -%> +} From 5d71ca8e3ba6233a414624fe604ee0235f8940ce Mon Sep 17 00:00:00 2001 From: Ricardo Melo Date: Tue, 11 Nov 2014 18:28:23 -0500 Subject: [PATCH 04/11] * fixed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 15b13e7..d561e3e 100644 --- a/README.md +++ b/README.md @@ -624,7 +624,7 @@ icinga2::object::notificationcommand { 'mail-service-notification': This object use the same parameter defined to `checkcommand`. -####[`icinga2::object::sicheduleddownload`](id:object_scheduleddownload) +####[`icinga2::object::scheduleddownload`](id:object_scheduleddownload) This defined type creates **ScheduledDowntime** objects From 2dca509573d8efd66ce791daa5fa872818e88cff Mon Sep 17 00:00:00 2001 From: Ricardo Melo Date: Wed, 12 Nov 2014 08:47:26 -0500 Subject: [PATCH 05/11] * removed duplication. --- README.md | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/README.md b/README.md index 4994c7e..6869632 100644 --- a/README.md +++ b/README.md @@ -337,7 +337,7 @@ Object types: * [icinga2::object::idopgsqlconnection](id:object_idopgsqlconnection) * [icinga2::object::notification](id:object_notification) * [icinga2::object::notificationcommand](id:object_notificationcommand) -* [icinga2::object::scheduleddowntime](id:object_scheduleddowntime) +* [icinga2::object::scheduleddowntime](#icinga2objectscheduleddowntime) * [icinga2::object::service](id:object_service) * [icinga2::object::servicegroup](id:object_servicegroup) * [icinga2::object::syslogger](id:object_syslogger) @@ -644,26 +644,6 @@ icinga2::object::scheduleddowntime {'some-downtime': -####[`icinga2::object::scheduleddownload`](id:object_scheduleddownload) - -This defined type creates **ScheduledDowntime** objects - -Example usage: - -
-icinga2::object::scheduleddowntime {'some-downtime':
-  host_name    => 'localhost',
-  service_name => 'ping4',
-  author       => 'icingaadmin',
-  comment      => 'Some comment',
-  fixed        => false,
-  duration     => '30m',
-  ranges       => { 'sunday' => '02:00-03:00' }
-}
-
- - - ####[`icinga2::object::service`](id:object_service) Coming soon... From a21bc9f9f64148eca2f16b5f8b048459a8abdd0e Mon Sep 17 00:00:00 2001 From: Ricardo Melo Date: Wed, 12 Nov 2014 08:48:40 -0500 Subject: [PATCH 06/11] * removed empty lines. --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 6869632..3291197 100644 --- a/README.md +++ b/README.md @@ -642,8 +642,6 @@ icinga2::object::scheduleddowntime {'some-downtime': } - - ####[`icinga2::object::service`](id:object_service) Coming soon... From fce7f11ff185e7f776056f2567cf07ec3d580829 Mon Sep 17 00:00:00 2001 From: Ricardo Melo Date: Wed, 12 Nov 2014 09:21:18 -0500 Subject: [PATCH 07/11] * fixed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3291197..38df384 100644 --- a/README.md +++ b/README.md @@ -624,7 +624,7 @@ icinga2::object::notificationcommand { 'mail-service-notification': This object use the same parameter defined to `checkcommand`. -####[`icinga2::object::scheduleddownload`](id:object_scheduleddownload) +####[`icinga2::object::scheduleddowntime`](id:object_scheduleddowntime) This defined type creates **ScheduledDowntime** objects From 9995a407479fe7b77e6c8fc8a24a52ab870c1c65 Mon Sep 17 00:00:00 2001 From: Steven Bambling Date: Thu, 13 Nov 2014 09:06:55 -0500 Subject: [PATCH 08/11] adding defined type to apply notifiation to service Signed-off-by: Nick Chappell Merged this from: https://github.com/Icinga/puppet-icinga2/pull/44 refs#7677: https://dev.icinga.org/issues/7677 --- .../object/apply_notification_to_service.pp | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 manifests/object/apply_notification_to_service.pp diff --git a/manifests/object/apply_notification_to_service.pp b/manifests/object/apply_notification_to_service.pp new file mode 100644 index 0000000..ddaed1d --- /dev/null +++ b/manifests/object/apply_notification_to_service.pp @@ -0,0 +1,66 @@ +# == Defined type: icinga2::object::apply_notification_to_service +# +# This is a defined type for Icinga 2 apply dependency objects. +# See the following Icinga 2 doc page for more info: +# http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/configuring-icinga2#objecttype-notification +# http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/configuring-icinga2#apply +# +# === Parameters +# +# See the inline comments. +# + +define icinga2::object::apply_notification_to_service ( + $object_notificationname = $name, + $host_name = undef, + $notification_to_import = undef, + $assign_where = undef, + $ignore_where = undef, + $command = undef, + $vars = {}, + $users = [], + $user_groups = [], + $times = {}, + $interval = undef, + $period = undef, + $types = [], + $states = [], + $target_dir = '/etc/icinga2/objects/applys', + $target_file_name = "${name}.conf", + $target_file_owner = 'root', + $target_file_group = 'root', + $target_file_mode = '0644' +) { + + #Do some validation of the class' parameters: + validate_string($object_notificationname) + validate_string($host_name) + validate_string($notification_to_import) + validate_string($command) + validate_hash($vars) + validate_array($users) + validate_array($user_groups) + validate_hash($times) + if $interval { + validate_re($interval, '^\d$') + } + if $period { + validate_string($period) + } + validate_array($types) + validate_array($states) + validate_string($target_dir) + validate_string($target_file_name) + validate_string($target_file_owner) + validate_string($target_file_group) + validate_re($target_file_mode, '^\d{4}$') + + file { "${target_dir}/${target_file_name}": + ensure => file, + owner => $target_file_owner, + group => $target_file_group, + mode => $target_file_mode, + content => template('icinga2/object_apply_notification_to_service.conf.erb'), + notify => Service['icinga2'], + } +} From ca1f1bbcc8c047a199a823ae0121a0414fa43e4b Mon Sep 17 00:00:00 2001 From: Steven Bambling Date: Thu, 13 Nov 2014 09:08:11 -0500 Subject: [PATCH 09/11] adding erb template for use with apply_notification_to_service define Signed-off-by: Nick Chappell Merged this from: https://github.com/Icinga/puppet-icinga2/pull/44 refs#7677: https://dev.icinga.org/issues/7677 --- ...ect_apply_notification_to_service.conf.erb | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 templates/object_apply_notification_to_service.conf.erb diff --git a/templates/object_apply_notification_to_service.conf.erb b/templates/object_apply_notification_to_service.conf.erb new file mode 100644 index 0000000..3549d07 --- /dev/null +++ b/templates/object_apply_notification_to_service.conf.erb @@ -0,0 +1,67 @@ +/** + * WARNING: This service definition is automatically generated by Puppet. + * ANY MANUAL CHANGES TO IT WILL GET OVERWRITTEN! + */ + +/** + * A object definition that applys notifications to hosts. You can create your + * own configuration files in the conf.d directory (e.g. one per host). + * By default all *.conf files in this directory are included. + * + */ + +apply Notification "<%= @object_notificationname %>" to Service { + <%#- If any of the @ parameters are undefined, don't print anything for them: -%> + <%- if @notification_to_import -%> + <%#- Otherwise, include the parameter: -%> + import "<%= @notification_to_import %>" + <%- end -%> + <%- if @host_name -%> + host_name = "<%= @host_name %>" + <%- end -%> + <%- if @assign_where -%> + assign where <%= @assign_where %> + <%- end -%> + <%- if @ignore_where -%> + ignore where <%= @ignore_where %> + <%- end -%> + <%- if @command -%> + command = "<%= @command %>" + <%- end -%> + <%- if @vars.empty? != true -%> + <%- @vars.each_pair do |key,value| -%> + <%= key %> = <% if value.class == String %><%= value %> + <%- else -%>{ + <%- value.each_pair do |k,v| -%> + <%= k %> = <%= v %> + <%- end -%> + } + <%- end -%> + <%- end -%> + <%- end -%> + <%- if @users.empty? !=true -%> + users = [ <% @users.each_with_index do |usr, i| %>"<%= usr -%>"<%= ', ' if i < (@users.size - 1) %><% end %> ] + <%- end -%> + <%- if @user_groups.empty? !=true -%> + user_groups = [ <% @user_groups.each_with_index do |u_grp, i| %>"<%= u_grp -%>"<%= ', ' if i < (@user_groups.size - 1) %><% end %> ] + <%- end -%> + <%- if @times.empty? != true -%> + times = { + <%- @times.each_pair do |key,value| -%> + <%= key %> = "<%= value %>" + <%- end -%> + } + <%- end -%> + <%- if @interval -%> + interval = "<%= @inteval -%>" + <%- end -%> + <%- if @period -%> + period = "<%= @period -%>" + <%- end -%> + <%- if @types.empty? !=true -%> + types = [ <% @types.each_with_index do |typ, i| %><%= typ -%><%= ', ' if i < (@types.size - 1) %><% end %> ] + <%- end -%> + <%- if @states.empty? !=true -%> + states = [ <% @states.each_with_index do |state, i| %><%= state -%><%= ', ' if i < (@states.size - 1) %><% end %> ] + <%- end -%> +} From 1c6637252e8554471ea35aa2a11c99c56bca5a48 Mon Sep 17 00:00:00 2001 From: Steven Bambling Date: Fri, 14 Nov 2014 06:34:12 -0500 Subject: [PATCH 10/11] correctly merge conflicts Signed-off-by: Nick Chappell Merged this from: https://github.com/Icinga/puppet-icinga2/pull/44 refs#7677: https://dev.icinga.org/issues/7677 --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 56be660..c4b313f 100644 --- a/README.md +++ b/README.md @@ -356,6 +356,7 @@ Object types: * [icinga2::object::applyservicetohost](#icinga2objectapplyservicetohost) * [icinga2::object::applynotificationtohost](#icinga2objectapplynotificationtohost) +* [icinga2::object::applynotificationtoservice](#icinga2objectapplynotificationtoservice) * [icinga2::object::checkcommand](#icinga2objectcheckcommand) * [icinga2::object::eventcommand](#icinga2objecteventcommand) * [icinga2::object::host](#icinga2objecthost) @@ -420,6 +421,23 @@ icinga2::object::apply_notification_to_host { 'pagerduty-host': states => [ 'Up', 'Down' ], types => [ 'Problem', 'Acknowledgement', 'Recovery', 'Custom' ], period => '24x7', + +```` + +####[`icinga2::object::applynotificationtoservice`](id:object_apply_notification_to_service) + +The `apply_notification_to_service` defined type can create `apply` objects to apply notifications to service: + +This defined type has the same available attributes that the `icinga2::object::notification` defined type does. With the addition of assign_where and ignore_where + +```` +icinga2::object::apply_notification_to_service { 'pagerduty-service': + assign_where => 'service.vars.enable_pagerduty == "true"', + command => 'notify-service-by-pagerduty', + users => [ 'pagerduty' ], + states => [ 'OK', 'Warning', 'Critical', 'Unknown' ], + types => [ 'Problem', 'Acknowledgement', 'Recovery', 'Custom' ], + period => '24x7', } ```` From e581fd6b6e20276df2c247f2604bb0c6fd9c679d Mon Sep 17 00:00:00 2001 From: Steven Bambling Date: Fri, 14 Nov 2014 06:35:46 -0500 Subject: [PATCH 11/11] fixing issue with README example Signed-off-by: Nick Chappell Merged this from: https://github.com/Icinga/puppet-icinga2/pull/44 refs#7677: https://dev.icinga.org/issues/7677 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c4b313f..10d4404 100644 --- a/README.md +++ b/README.md @@ -421,7 +421,7 @@ icinga2::object::apply_notification_to_host { 'pagerduty-host': states => [ 'Up', 'Down' ], types => [ 'Problem', 'Acknowledgement', 'Recovery', 'Custom' ], period => '24x7', - +} ```` ####[`icinga2::object::applynotificationtoservice`](id:object_apply_notification_to_service)