[icinga-checkins] icinga.org: puppet-icinga2/master: Add a EventCommand object defined type, refs#7215

git at icinga.org git at icinga.org
Sun Nov 2 05:40:26 CET 2014


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

Author: Ricardo Melo <ricardo.melo at gameloft.com>
Date:   Mon Oct 20 11:21:31 2014 -0400

Add a EventCommand object defined type, refs#7215

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

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

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

---

 README.md                              |   15 ++++++++
 manifests/object/eventcommand.pp       |   58 ++++++++++++++++++++++++++++++
 templates/object_eventcommand.conf.erb |   62 ++++++++++++++++++++++++++++++++
 3 files changed, 135 insertions(+)

diff --git a/README.md b/README.md
index 8fc9d15..9a9eebb 100644
--- a/README.md
+++ b/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.
diff --git a/manifests/object/eventcommand.pp b/manifests/object/eventcommand.pp
new file mode 100644
index 0000000..4c84162
--- /dev/null
+++ b/manifests/object/eventcommand.pp
@@ -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'],
+  }
+
+}
+
diff --git a/templates/object_eventcommand.conf.erb b/templates/object_eventcommand.conf.erb
new file mode 100644
index 0000000..d98896d
--- /dev/null
+++ b/templates/object_eventcommand.conf.erb
@@ -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 -%>
+}



More information about the icinga-checkins mailing list