diff --git a/README.md b/README.md index 2db6765..8fc9d15 100644 --- a/README.md +++ b/README.md @@ -334,6 +334,7 @@ Object types: * [icinga2::object::hostgroup](id:object_hostgroup) * [icinga2::object::idomysqlconnection](id:object_idomysqlconnection) * [icinga2::object::idopgsqlconnection](id:object_idopgsqlconnection) +* [icinga2::object::notificationcommand](id:object_notificationcommand) * [icinga2::object::service](id:object_service) * [icinga2::object::servicegroup](id:object_servicegroup) * [icinga2::object::syslogger](id:object_syslogger) @@ -536,6 +537,35 @@ 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::notificationcommand` + +The `notificationcommand` defined type can create `notificationcommand` objects. + +
+#Create the mail notification command:
+icinga2::object::notificationcommand { 'mail-service-notification':
+  command   => ['"/icinga2/scripts/mail-notification.sh"'],
+  cmd_path  => 'SysconfDir',
+  env       => {
+    'NOTIFICATIONTYPE'  => '"$notification.type$"',
+    'SERVICEDESC' => '"$service.name$"',
+    'HOSTALIAS' => '"$host.display_name$"',
+    'HOSTADDRESS' => '"$address$"',
+    'SERVICESTATE' => '"$service.state$"',
+    'LONGDATETIME' => '"$icinga.long_date_time$"',
+    'SERVICEOUTPUT' => '"$service.output$"',
+    'NOTIFICATIONAUTHORNAME' => '"$notification.author$"',
+    'NOTIFICATIONCOMMENT' => '"$notification.comment$"',
+    'HOSTDISPLAYNAME' => '"$host.display_name$"',
+    'SERVICEDISPLAYNAME' => '"$service.display_name$"',
+    'USEREMAIL' => '"$user.email$"'
+  }
+}
+
+
+ +This oobject use the same parameter defined to `checkcommand`. + ####[`icinga2::object::service`](id:object_service) Coming soon... diff --git a/manifests/object/notificationcommand.pp b/manifests/object/notificationcommand.pp new file mode 100644 index 0000000..833b00c --- /dev/null +++ b/manifests/object/notificationcommand.pp @@ -0,0 +1,57 @@ +# == Defined type: icinga2::object::notificationcommand +# +# 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-notificationcommand +# +# === Parameters +# +# See the inline comments. +# + +define icinga2::object::notificationcommand ( + $object_notificationcommandname = $name, + $template_to_import = 'plugin-check-command', +/* $methods = undef, */ /* Need to get more details about this attribute */ + $command = undef, + $cmd_path = 'PluginDir', + $arguments = {}, + $env = undef, + $vars = {}, + $timeout = undef, + $target_dir = '/etc/icinga2/conf.d', + $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_notificationcommandname) + validate_string($template_to_import) + validate_array($command) + validate_string($cmd_path) + if $env { + validate_hash($env) + } + validate_hash($vars) + if $timeout { + validate_re($timeout, '^\d+$') + } + 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_notificationcommand.conf.erb'), + notify => Service['icinga2'], + } + +} diff --git a/templates/object_notificationcommand.conf.erb b/templates/object_notificationcommand.conf.erb new file mode 100644 index 0000000..4e0f009 --- /dev/null +++ b/templates/object_notificationcommand.conf.erb @@ -0,0 +1,62 @@ +/** +* WARNING: This CheckCommand definition is automatically generated by Puppet. +* ANY MANUAL CHANGES TO IT WILL GET OVERWRITTEN! +*/ + +/** +* A NotificationCommand 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 NotificationCommand "<%= @object_notificationcommandname %>" { + <%#- If any of the @ parameters are undefined, don't print anything for them: -%> + + <%- if @template_to_import -%> + import "<%= @template_to_import -%>" + + <%- end -%> + <%- if @command -%> + command = [ <% if @cmd_path -%><%= @cmd_path -%> + <% end -%><% @command.each_with_index do |cmd, i| %><%= cmd -%><%= ', ' if i < (@command.size - 1) %><% end %> ] + <%- end -%> + <%#- Need to add support to argument value as hash (recursivity) -%> + + <%- if @arguments -%> + arguments = { + <%- @arguments.each_with_index do |(key,value), i| -%> + <%= key %> = <% if value.class == String %><%= value %> + <%- else -%>{ + <%- value.each_pair do |k,v| -%> + <%= k %> = <%= v %> + <%- end -%> + } + <%- end -%> + <%- end -%> + } + <%- end -%> + + <%- if @vars -%> + <%- @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 @timeout -%> + timeout = <%= @timeout %> + <%- end -%> + + <%- if @env -%> + env = { + <%- @vars.each_pair do |key,value| -%> + <%= key %> = <%= value %> + <%- end -%> + } + <%- end -%> +}