diff --git a/README.md b/README.md index e9122f5..4dcfc79 100644 --- a/README.md +++ b/README.md @@ -325,6 +325,60 @@ If you would like to use Puppet or Facter variables in an `assign_where` or `ign assign_where => "\"linux_servers\" in host.${facter_variable}"", +####`icinga2::object::checkcommand` + +The `checkcommand` defined type can create `checkcommand` objects. + +
+#Create the http check command: +icinga2::object::checkcommand { 'check_http': + command => ['"/check_http"'], + arguments => {'"-H"' => '"$http_vhost$"', + '"-I"' => '"$http_address$"', + '"-u"' => '"$http_uri$"', + '"-p"' => '"$http_port$"', + '"-S"' => { + 'set_if' => '"$http_ssl$"' + }, + '"--sni"' => { + 'set_if' => '"$http_sni$"' + }, + '"-a"' => { + 'value' => '"$http_auth_pair$"', + 'description' => '"Username:password on sites with basic authentication"' + }, + '"--no-body"' => { + 'set_if' => '"$http_ignore_body$"' + }, + '"-r"' => '"$http_expect_body_regex$"', + '"-w"' => '"$http_warn_time$"', + '"-c"' => '"$http_critical_time$"', + '"-e"' => '"$http_expect$"' + }, + vars => { + 'vars.http_address' => '"$address$"', + 'vars.http_ssl' => 'false', + 'vars.http_sni' => 'false' + } +} + ++ +This vailible parameters are: + +* `template_to_import`: . +* `command`: . +* `cmd_path`: . +* `arguments`: . +* `env`: . +* `vars`: . +* `timeout`: . +* `target_dir`: . +* `target_file_name`: . +* `target_file_owner`: . +* `target_file_group`: . +* `target_file_mode`: . + ####[`icinga2::object::host`](id:object_host) This defined type creates host objects. diff --git a/manifests/object/checkcommand.pp b/manifests/object/checkcommand.pp index 3787917..7f34ce7 100644 --- a/manifests/object/checkcommand.pp +++ b/manifests/object/checkcommand.pp @@ -10,56 +10,39 @@ # define icinga2::object::checkcommand ( - $methods, - $command, - $env, - $vars {}, - $timeout, - $arguments = {} - # $object_servicename = $name, - # $template_to_import = 'generic-service', - # $display_name = $name, - # $assign_where = undef, - # $ignore_where = undef, - # $groups = [], - # $vars = {}, - # $check_command = undef, - # $max_check_attempts = undef, - # $check_period = undef, - # $check_interval = undef, - # $retry_interval = undef, - # $enable_notifications = undef, - # $enable_active_checks = undef, - # $enable_passive_checks = undef, - # $enable_event_handler = undef, - # $enable_flap_detection = undef, - # $enable_perfdata = undef, - # $event_command = undef, - # #flapping_threshold is defined as a percentage, eg. 10%, 50%, etc. - # $flapping_threshold = undef, - # $volatile = undef, - # $notes = undef, - # $notes_url = undef, - # $action_url = undef, - # $icon_image = undef, - # $icon_image_alt = undef, - # $target_dir = '/etc/icinga2/conf.d', - # $target_file_name = "${name}.conf", - # $target_file_owner = 'root', - # $target_file_group = 'root', - # $target_file_mode = '0644' + $object_checkcommandname = $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_servicename) + validate_string($object_checkcommandname) validate_string($template_to_import) - validate_array($groups) + 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_string($target_file_mode) + validate_re($target_file_mode, '^\d{4}$') file {"${target_dir}/${target_file_name}": @@ -67,7 +50,7 @@ define icinga2::object::checkcommand ( owner => $target_file_owner, group => $target_file_group, mode => $target_file_mode, - content => template('icinga2/object_apply_service_to_host.conf.erb'), + content => template('icinga2/object_checkcommand.conf.erb'), notify => Service['icinga2'], } diff --git a/templates/object_checkcommand.conf.erb b/templates/object_checkcommand.conf.erb new file mode 100644 index 0000000..666d3bb --- /dev/null +++ b/templates/object_checkcommand.conf.erb @@ -0,0 +1,62 @@ +/** +* WARNING: This CheckCommand definition is automatically generated by Puppet. +* ANY MANUAL CHANGES TO IT WILL GET OVERWRITTEN! +*/ + +/** +* A CheckCommand 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 CheckCommand "<%= @object_checkcommandname %>" { + <%#- 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 -%> +}