+ Adding notificationcommand object
Signed-off-by: Nick Chappell <nick@intronic.org> Merged in from: https://github.com/Icinga/puppet-icinga2/pull/32 refs#7228: https://dev.icinga.org/issues/7228
This commit is contained in:
parent
6f7a249841
commit
f0415a6c5a
3 changed files with 149 additions and 0 deletions
30
README.md
30
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.
|
||||
|
||||
<pre>
|
||||
#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$"'
|
||||
}
|
||||
}
|
||||
|
||||
</pre>
|
||||
|
||||
This oobject use the same parameter defined to `checkcommand`.
|
||||
|
||||
####[`icinga2::object::service`](id:object_service)
|
||||
|
||||
Coming soon...
|
||||
|
|
57
manifests/object/notificationcommand.pp
Normal file
57
manifests/object/notificationcommand.pp
Normal file
|
@ -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'],
|
||||
}
|
||||
|
||||
}
|
62
templates/object_notificationcommand.conf.erb
Normal file
62
templates/object_notificationcommand.conf.erb
Normal file
|
@ -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 -%>
|
||||
}
|
Loading…
Reference in a new issue