[icinga-checkins] icinga.org: puppet-icinga2/master: Adding notification object. #2716

git at icinga.org git at icinga.org
Wed Nov 12 06:50:10 CET 2014


Module: puppet-icinga2
Branch: master
Commit: 09db5bba182793b0cc302ddb99b5602b24d1b54e
URL:    https://git.icinga.org/?p=puppet-icinga2.git;a=commit;h=09db5bba182793b0cc302ddb99b5602b24d1b54e

Author: Ricardo Melo <ricardo.melo at gameloft.com>
Date:   Mon Nov  3 17:49:31 2014 -0500

Adding notification object. #2716

Signed-off-by: Nick Chappell <nick at intronic.org>

Merged from: https://github.com/Icinga/puppet-icinga2/pull/36

refs#7216: https://dev.icinga.org/issues/7216

---

 README.md                              |   49 +++++++++++++++++++-
 manifests/object/notification.pp       |   79 ++++++++++++++++++++++++++++++++
 templates/object_notification.conf.erb |   71 ++++++++++++++++++++++++++++
 3 files changed, 198 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index d8af224..343b812 100644
--- a/README.md
+++ b/README.md
@@ -335,6 +335,7 @@ Object types:
 * [icinga2::object::hostgroup](id:object_hostgroup)
 * [icinga2::object::idomysqlconnection](id:object_idomysqlconnection)
 * [icinga2::object::idopgsqlconnection](id:object_idopgsqlconnection)
+* [icinga2::object::notification](id:object_notification)
 * [icinga2::object::notificationcommand](id:object_notificationcommand)
 * [icinga2::object::service](id:object_service)
 * [icinga2::object::servicegroup](id:object_servicegroup)
@@ -552,6 +553,52 @@ This defined type supports all of the parameters that **IdoMySqlConnection** obj
 
 See [IdoPgSqlConnection](http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/configuring-icinga2#objecttype-idopgsqlconnection) on [docs.icinga.org](http://docs.icinga.org/icinga2/latest/doc/module/icinga2/toc) for a full list of parameters.
 
+####`icinga2::object::notification`
+
+The `notification` defined type can create `notification` objects.
+
+<pre>
+#Defining Create the mail notification command:
+icinga2::object::notification { 'localhost-ping-notification':
+
+  host_name = "localhost"
+
+  service_name = "ping4"
+
+  command = "mail-service-notification"
+
+  types = [ Problem, Recovery ]
+  }
+}
+
+</pre>
+
+Available parameters are:
+
+* `host_name`: Required.
+* `service_name`: Optional.
+* `vars`: Optional.
+* `users`: Optional.
+* `user_groups`: Optional.
+* `times`: Optional.
+* `command`: Required.
+* `interval`: Optional.
+* `period`: Optional.
+* `types`: Optional.
+* `states`: Optional.
+* `target_file_name`: Optional.
+* `target_file_owner`: Optional.
+* `target_file_group`: Optional.
+* `target_file_mode`: Optional.
+
+Notes on specific parameters:
+
+* `vars`: needs to be a dictionary
+* `users`,`user_groups`,`types`,`states`: should be an array, see [Notification](http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/configuring-icinga2#objecttype-notification) for list of valid state and type filters
+* `times`: needs to be a dictionary with `begin` and `end` attributes
+* `interval`: needs to be a [number](https://docs.puppetlabs.com/puppet/latest/reference/lang_datatypes.html#numbers), not a quoted string
+
+
 ####`icinga2::object::notificationcommand`
 
 The `notificationcommand` defined type can create `notificationcommand` objects.
@@ -579,7 +626,7 @@ icinga2::object::notificationcommand { 'mail-service-notification':
 
 </pre>
 
-This oobject use the same parameter defined to `checkcommand`.
+This object use the same parameter defined to `checkcommand`.
 
 ####[`icinga2::object::service`](id:object_service)
 
diff --git a/manifests/object/notification.pp b/manifests/object/notification.pp
new file mode 100644
index 0000000..611ded4
--- /dev/null
+++ b/manifests/object/notification.pp
@@ -0,0 +1,79 @@
+# == Defined type: icinga2::object::notification
+#
+# This is a defined type for Icinga 2 apply objects that create notification commands
+# See the following Icinga 2 doc page for more info:
+# http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/configuring-icinga2#objecttype-notification
+#
+# === Parameters
+#
+# See the inline comments.
+#
+
+define icinga2::object::notification (
+  $object_notificationname = $name,
+  $command           = undef,
+  $host_name         = undef,
+  $service_name         = undef,
+  $vars              = {},
+  $users             = [],
+  $user_groups       = [],
+  $times             = {},
+  $interval          = undef,
+  $period            = undef,
+  $types             = [],
+  $states            = [],
+  $target_dir        = '/etc/icinga2/objects/notifications',
+  $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($command)
+  if $host_name {
+    validate_string($host_name)
+  }
+  if $service_name {
+    validate_string($service_name)
+  }
+  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)
+/** Array concatenation not available,
+  if $types - ['DowntimeStart','DowntimeEnd','DowntimeRemoved','Custom','Acknowledgement','Problem','Recovery','FlappingStart','FlappingEnd'] != [] {
+    fail ('You are using unavailable notification type filter.')
+  }
+*/
+  validate_array($states)
+/** Array concatenation not available,
+  if $states - ['OK','Warning','Critical','Unknown','Up','Down'] != [] {
+    fail ('You are using unavailable state type filter.')
+  }
+*/
+  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_notification.conf.erb'),
+    notify  => Service['icinga2'],
+  }
+
+}
diff --git a/templates/object_notification.conf.erb b/templates/object_notification.conf.erb
new file mode 100644
index 0000000..014c0ea
--- /dev/null
+++ b/templates/object_notification.conf.erb
@@ -0,0 +1,71 @@
+/**
+* WARNING: This Notification definition is automatically generated by Puppet.
+* ANY MANUAL CHANGES TO IT WILL GET OVERWRITTEN!
+*/
+
+/**
+* A Notification definition. You can create your own configuration files
+* in the conf.d directory (e.g. one per commnand). By default all *.conf
+* files in this directory are included.
+*
+*/
+
+object Notification "<%= @object_notificationname %>" {
+  <%#- If any of the @ parameters are undefined, don't print anything for them: -%>
+  <%- if @host_name -%>
+
+  host_name = "<%= @host_name -%>"
+  <%- end -%>
+  <%- if @service_name -%>
+
+  service_name = "<%= @service_name -%>"
+  <%- 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 -%>
+}



More information about the icinga-checkins mailing list