diff --git a/README.md b/README.md index 7b60bcf..22d9c21 100644 --- a/README.md +++ b/README.md @@ -116,4 +116,78 @@ class { 'icinga2::server': } -This will stop the `icinga2::server` class from trying to install the plugins pacakges, since the `icinga2::nrpe` class will already be installing them and will prevent a resulting duplicate resource error. \ No newline at end of file +This will stop the `icinga2::server` class from trying to install the plugins pacakges, since the `icinga2::nrpe` class will already be installing them and will prevent a resulting duplicate resource error. + +####Object type usage + +This module includes several defined types that can be used to automatically generate Icinga 2 format object definitions. They function in a similar way to [the built-in Nagios types that are included in Puppet](http://docs.puppetlabs.com/guides/exported_resources.html#exported-resources-with-nagios). + +#####Exported resources + +Like the built-in Nagios types, they can be exported to PuppetDB as virtual resources and collected on your Icinga 2 server. + +Nodes that are being monitored can have the `@@` virtual resources applied to them: + +
+@@icinga2::object::host { $::fqdn:
+  display_name => $::fqdn,
+  ipv4_address => $::ipaddress_eth0,
+  groups => ['linux_servers', 'mysql_servers'],
+  vars => {
+    os              => 'linux',
+    virtual_machine => 'true',
+    distro          => $::operatingsystem,
+  },
+  target_dir => '/etc/icinga2/objects/hosts',
+  target_file_name => "${fqdn}.conf"
+}
+
+ +Then, on your Icinga 2 server, you can collect the exported virtual resources (notice the camel casing in the class name): + +
+#Collect all @@icinga2::object::host resources from PuppetDB that were exported by other machines:
+Icinga2::Object::Host <<| |>> { }
+
+ +Unlike the built-in Nagios types, the file owner, group and mode of the automatically generated files can be controlled via the `target_file_owner`, `target_file_group` and `target_file_mode` parameters: + +
+@@icinga2::object::host { $::fqdn:
+  display_name => $::fqdn,
+  ipv4_address => $::ipaddress_eth0,
+  groups => ['linux_servers', 'mysql_servers'],
+  vars => {
+    os              => 'linux',
+    virtual_machine => 'true',
+    distro          => $::operatingsystem,
+  },
+  target_dir => '/etc/icinga2/objects/hosts',
+  target_file_name => "${fqdn}.conf"
+  target_file_owner = 'root',
+  target_file_group = 'root',
+  target_file_mode = '644'
+}
+
+ +#####`undef` and default object values + +Most of the object parameters *in the Puppet module* are set to **undef**. + +This means that they will not be added to the rendered object definition files. + +**However**, this doesn't mean that the values are not set. Icinga 2 itself has default values for many object parameters and falls back to them if one isn't present in an object definition. See the docs for individual object types in [Configuring Icinga 2](http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/configuring-icinga2) for more info about which object parameters have what default values. + +#####`icinga2::object::host` + +**Note:** The `ipv6_address` parameter is set to **undef** by default. This is because `facter` can return either IPv4 or IPv6 addresses for the `ipaddress_ethX` facts. The default value for the `ipv6_address` parameter is set to **undef** and not `ipaddress_eth0` so that an IPv4 address isn't set as the value for `address6` in the rendered host definition. + +If you would like to use an IPv6 address, make sure to set the `ipv6_address` parameter to the `ipaddress_ethX` fact that will give you the right IPv6 address for the machine: + +
+@@icinga2::object::host { $::fqdn:
+  display_name => $::fqdn,
+  ipv6_address => $::ipaddress_eth1,
+....
+}
+
\ No newline at end of file diff --git a/manifests/object.pp b/manifests/object.pp new file mode 100644 index 0000000..cfefdbd --- /dev/null +++ b/manifests/object.pp @@ -0,0 +1,13 @@ +# == Class: icinga2::params +# +# This class is intentionally empty. It just serves as a container class for other +# icinga2::object:: classes to make the module's file layout cleaner (all object defined types +# can be put into an objects/ subdirectory) +# +# === Parameters +# +# None. See inline comments for parameters on the individual object type manifests for +# more details. +# + +class icinga2::objects { } \ No newline at end of file diff --git a/manifests/objects/host.pp b/manifests/object/host.pp similarity index 52% rename from manifests/objects/host.pp rename to manifests/object/host.pp index e677ba8..91ed54d 100644 --- a/manifests/objects/host.pp +++ b/manifests/object/host.pp @@ -7,14 +7,34 @@ # See the inline comments. # -define icinga2::objects::host ( +define icinga2::object::host ( $object_hostname = $name, $display_name = $fqdn, $ipv4_address = $ipaddress_eth0, - $ipv6_address = $ipaddress_eth0, + $ipv6_address = undef, $template_to_import = 'generic-host', $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 = "${fqdn}.conf", $target_file_owner = 'root', diff --git a/manifests/objects/hostgroup.pp b/manifests/object/hostgroup.pp similarity index 94% rename from manifests/objects/hostgroup.pp rename to manifests/object/hostgroup.pp index 8cd460d..810ebfe 100644 --- a/manifests/objects/hostgroup.pp +++ b/manifests/object/hostgroup.pp @@ -6,7 +6,7 @@ # See the inline comments. # -define icinga2::objects::hostgroup ( +define icinga2::object::hostgroup ( $object_hostgroup_name = $name, $display_name = $name, $template_to_import = undef, diff --git a/manifests/objects.pp b/manifests/objects.pp deleted file mode 100644 index 50ce4b9..0000000 --- a/manifests/objects.pp +++ /dev/null @@ -1,11 +0,0 @@ -# == Class: icinga2::params -# -# This class is purposefully empty. It just serves as a container class for other -# icinga2::objects:: classes. -# -# === Parameters -# -# See the inline comments. -# - -class icinga2::objects { } \ No newline at end of file diff --git a/templates/object_host.conf.erb b/templates/object_host.conf.erb index 2e50820..599fd05 100644 --- a/templates/object_host.conf.erb +++ b/templates/object_host.conf.erb @@ -10,32 +10,6 @@ * */ -//Parameters to include: -// * displayname -// * address -// * address6 -// * groups -// * vars -// * check_command -// * max_check_attempts -// * check_period -// * check_interval -// * retry_interval -// * enable_notifications -// * enable_active_checks -// * enable_passive_checks -// * enable_event_handler -// * enable_flap_detection -// * enable_perfdata -// * event_command -// * flapping_threshold -// * volatile -// * notes -// * notes_url -// * action_url -// * icon_image -// * icon_image_alt - object Host "<%= @object_hostname %>" { <%#- If any of the @ parameters are undefined, don't print anything for them: -%> <%- if @template_to_import -%> @@ -48,7 +22,72 @@ object Host "<%= @object_hostname %>" { <%- if @ipv4_address -%> address = "<%= @ipv4_address -%>" <%- end -%> + <%- if @ipv6_address -%> + address6 = "<%= @ipv6_address -%>" + <%- end -%> <%- if @groups.length != 0 -%> groups = [ <%- @groups.each do |group| -%> "<%= group %>", <%- end -%>] <%- end -%> + <%- if @vars.empty? != true -%> + <%- @vars.each_pair do |key, value| -%> + vars.<%= key %> = "<%= value %>" + <%- end -%> + <%- end -%> + <%- if @check_command -%> + check_command = "<%= @check_command -%>" + <%- end -%> + <%- if @max_check_attempts -%> + max_check_attempts = <%= @max_check_attempts -%> + <%- end -%> + <%- if @check_period -%> + check_period = <%= @check_period -%> + <%- end -%> + <%- if @check_interval -%> + check_interval = <%= @check_interval -%> + <%- end -%> + <%- if @retry_interval -%> + retry_interval = <%= @retry_interval -%> + <%- end -%> + <%- if @enable_notifications -%> + enable_notifications = <%= @enable_notifications -%> + <%- end -%> + <%- if @enable_active_checks -%> + enable_active_checks = <%= @enable_active_checks -%> + <%- end -%> + <%- if @enable_passive_checks -%> + enable_passive_checks = <%= @enable_passive_checks -%> + <%- end -%> + <%- if @enable_event_handler -%> + enable_event_handler = <%= @enable_event_handler -%> + <%- end -%> + <%- if @enable_flap_detection -%> + enable_flap_detection = <%= @enable_flap_detection -%> + <%- end -%> + <%- if @enable_perfdata -%> + enable_perfdata = <%= @enable_perfdata -%> + <%- end -%> + <%- if @event_command -%> + event_command = "<%= @event_command -%>" + <%- end -%> + <%- if @flapping_threshold -%> + flapping_threshold = "<%= @flapping_threshold -%>" + <%- end -%> + <%- if @volatile -%> + volatile = "<%= @volatile -%>" + <%- end -%> + <%- if @notes -%> + notes = "<%= @notes -%>" + <%- end -%> + <%- if @notes_url -%> + notes_url = "<%= @notes_url -%>" + <%- end -%> + <%- if @action_url -%> + action_url = "<%= @action_url -%>" + <%- end -%> + <%- if @icon_image -%> + icon_image = "<%= @icon_image -%>" + <%- end -%> + <%- if @icon_image_alt -%> + icon_image_alt = "<%= @icon_image_alt -%>" + <%- end -%> }