Add a EventCommand object defined type, refs#7215
Signed-off-by: Nick Chappell <nick@intronic.org> Merged in from: https://github.com/Icinga/puppet-icinga2/pull/33 refs#7215: https://dev.icinga.org/issues/7215
This commit is contained in:
parent
c83c1d91e1
commit
f9a4feb746
3 changed files with 135 additions and 0 deletions
15
README.md
15
README.md
|
@ -330,6 +330,7 @@ Object types:
|
|||
|
||||
* [icinga2::object::apply_service_to_host](#object_apply_service_to_host)
|
||||
* [icinga2::object::checkcommand](#object_checkcommand)
|
||||
* [icinga2::object::eventcommand](id:object_eventcommand)
|
||||
* [icinga2::object::host](id:object_host)
|
||||
* [icinga2::object::hostgroup](id:object_hostgroup)
|
||||
* [icinga2::object::idomysqlconnection](id:object_idomysqlconnection)
|
||||
|
@ -428,6 +429,20 @@ Available parameters are:
|
|||
* `target_file_group`
|
||||
* `target_file_mode`
|
||||
|
||||
####`icinga2::object::eventcommand`
|
||||
|
||||
The `eventcommand` defined type can create `eventcommand` objects.
|
||||
|
||||
<pre>
|
||||
#Create the http restart command:
|
||||
icinga2::object::eventcommand { 'restart-httpd-event':
|
||||
command => '"/opt/bin/restart-httpd.sh"'
|
||||
}
|
||||
|
||||
</pre>
|
||||
|
||||
This object use the same parameter defined to `checkcommand`.
|
||||
|
||||
####[`icinga2::object::host`](id:object_host)
|
||||
|
||||
This defined type creates host objects.
|
||||
|
|
58
manifests/object/eventcommand.pp
Normal file
58
manifests/object/eventcommand.pp
Normal file
|
@ -0,0 +1,58 @@
|
|||
# == Defined type: icinga2::object::eventcommand
|
||||
#
|
||||
# This is a defined type for Icinga 2 apply objects that create event commands
|
||||
# See the following Icinga 2 doc page for more info:
|
||||
# http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/configuring-icinga2#objecttype-eventcommand
|
||||
#
|
||||
# === Parameters
|
||||
#
|
||||
# See the inline comments.
|
||||
#
|
||||
|
||||
define icinga2::object::eventcommand (
|
||||
$object_eventcommandname = $name,
|
||||
$template_to_import = 'plugin-event-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_eventcommandname)
|
||||
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_eventcommand.conf.erb'),
|
||||
notify => Service['icinga2'],
|
||||
}
|
||||
|
||||
}
|
||||
|
62
templates/object_eventcommand.conf.erb
Normal file
62
templates/object_eventcommand.conf.erb
Normal file
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
* WARNING: This EventCommand definition is automatically generated by Puppet.
|
||||
* ANY MANUAL CHANGES TO IT WILL GET OVERWRITTEN!
|
||||
*/
|
||||
|
||||
/**
|
||||
* A EventCommand 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 EventCommand "<%= @object_eventcommandname %>" {
|
||||
<%#- 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