Merge branch 'develop'

This commit is contained in:
Nick Chappell 2014-07-26 21:31:20 -07:00
commit e8aed6bd8b
17 changed files with 374 additions and 45 deletions

View file

@ -1,2 +1,6 @@
#Changelog
- - -
###v0.3 (July 26th, 2014)
* Added an object definition for the **host** object type

104
README.md
View file

@ -7,7 +7,7 @@ The module has only been tested on [CentOS 6.5](http://www.centos.org/download/)
Currently, this module does not install or configure any web UIs for Icinga 2. This module also does not install or configure a mail transfer agent (MTA) to send outgoing alert emails.
While NRPE is required for Icinga 2 to check non-network-reachble things on client machines (CPU, load average, etc.), this module itself doesn't have any dependencies between the server component (the `icinga2::server` class) and client component (the `icinga2::client` class). Either one can be used independently of the other.
While NRPE is required for Icinga 2 to check non-network-reachble things on client machines (CPU, load average, etc.), this module itself doesn't have any dependencies between the server component (the `icinga2::server` class) and client component (the `icinga2::nrpe` class). Either one can be used independently of the other.
###Requirements
@ -82,12 +82,112 @@ class { 'icinga2::server':
}
</pre>
**Note:** If you will be installing NRPE or the Nagios plugins packages with the `icinga2::nrpe` class on a node that also has the `icinga2::server` class applied, be sure to set the `$server_install_nagios_plugins` parameter in your call to `icinga2::server` to `false`:
<pre>
#Install Icinga 2:
class { 'icinga2::server':
...
server_install_nagios_plugins => false,
...
}
</pre>
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.
####Client usage
To install NRPE and allow the local machine and Icinga 2 servers (or Icinga 1 or plain old Nagios servers) with various IP addresess to connect:
<pre>
class { 'icinga2::client':
class { 'icinga2::nrpe':
nrpe_allowed_hosts => ['10.0.1.79', '10.0.1.80', '10.0.1.85', '127.0.0.1'],
}
</pre>
**Note:** If you would like to install NRPE on a node that also has the `icinga2::server` class applied, be sure to set the `$server_install_nagios_plugins` parameter in your call to `icinga2::server` to `false`:
<pre>
#Install Icinga 2:
class { 'icinga2::server':
server_db_type => 'pgsql',
server_install_nagios_plugins => false,
}
</pre>
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:
<pre>
@@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"
}
</pre>
Then, on your Icinga 2 server, you can collect the exported virtual resources (notice the camel casing in the class name):
<pre>
#Collect all @@icinga2::object::host resources from PuppetDB that were exported by other machines:
Icinga2::Object::Host <<| |>> { }
</pre>
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:
<pre>
@@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'
}
</pre>
#####`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:
<pre>
@@icinga2::object::host { $::fqdn:
display_name => $::fqdn,
ipv6_address => $::ipaddress_eth1,
....
}
</pre>

View file

@ -1,10 +1,10 @@
# Class: icinga2::client
# Class: icinga2::nrpe
#
# This subclass manages Icinga client components. This class is just the entry point for Puppet to get at the
# icinga2::client:: subclasses.
# icinga2::nrpe:: subclasses.
#
class icinga2::client (
class icinga2::nrpe (
$nrpe_listen_port = $icinga2::params::nrpe_listen_port,
$nrpe_debug_level = $icinga2::params::nrpe_debug_level,
@ -18,7 +18,7 @@ class icinga2::client (
#Apply our classes in the right order. Use the squiggly arrows (~>) to ensure that the
#class left is applied before the class on the right and that it also refreshes the
#class on the right.
class {'icinga2::client::install':} ~>
class {'icinga2::client::config':} ~>
class {'icinga2::client::service':}
class {'icinga2::nrpe::install':} ~>
class {'icinga2::nrpe::config':} ~>
class {'icinga2::nrpe::service':}
}

View file

@ -1,4 +1,4 @@
# Define icinga2::client::command
# Define icinga2::nrpe::command
#
# This defined type creates NRPE command definitions on machines running NRPE.
#
@ -9,7 +9,7 @@
# * $nrpe_plugin_args = The arguments to pass to the plugin. This may be optional,
# depending on the plugin and whether it expects any arguments or parameters
define icinga2::client::command (
define icinga2::nrpe::command (
$command_name = $name,
$nrpe_plugin_liddir = $icinga2::params::nrpe_plugin_liddir,
$nrpe_plugin_name = undef,

View file

@ -1,11 +1,11 @@
# Class: icinga2::client::config
# Class: icinga2::nrpe::config
#
# This subclass configures Icinga clients.
#
class icinga2::client::config inherits icinga2::client {
class icinga2::nrpe::config inherits icinga2::nrpe {
include icinga2::client
include icinga2::nrpe
#config resources here

View file

@ -1,25 +1,25 @@
# Class: icinga2::client::install
# Class: icinga2::nrpe::install
#
# This subclass installs NRPE and Nagios plugin packages on Icinga client machines.
#
class icinga2::client::install inherits icinga2::client {
class icinga2::nrpe::install inherits icinga2::nrpe {
include icinga2::client
include icinga2::nrpe
#Apply our subclasses in the right order. Use the squiggly arrows (~>) to ensure that the
#class left is applied before the class on the right and that it also refreshes the
#class on the right.
class {'icinga2::client::install::repos':} ~>
class {'icinga2::client::install::packages':} ~>
class {'icinga2::client::install::execs':}
class {'icinga2::nrpe::install::repos':} ~>
class {'icinga2::nrpe::install::packages':} ~>
class {'icinga2::nrpe::install::execs':}
}
##################
#Package repositories
##################
class icinga2::client::install::repos inherits icinga2::client {
class icinga2::nrpe::install::repos inherits icinga2::nrpe {
include icinga2::client
include icinga2::nrpe
#repository resources here
}
@ -27,9 +27,9 @@ class icinga2::client::install::repos inherits icinga2::client {
##################
# Packages
##################
class icinga2::client::install::packages inherits icinga2::client {
class icinga2::nrpe::install::packages inherits icinga2::nrpe {
include icinga2::client
include icinga2::nrpe
#Install the packages we specified in the ::params class:
package {$icinga2::params::icinga2_client_packages:
ensure => installed,
@ -42,7 +42,7 @@ class icinga2::client::install::packages inherits icinga2::client {
##################
# Execs
##################
class icinga2::client::install::execs {
class icinga2::nrpe::install::execs {
#exec resources here

View file

@ -1,4 +1,4 @@
# Define icinga2::client::plugin
# Define icinga2::nrpe::plugin
#
# This defined type distributes .
#
@ -14,7 +14,7 @@
# for more info on what formats of URLs you can use to specify which files
# you want to distribute.
define icinga2::client::plugin (
define icinga2::nrpe::plugin (
$plugin_name = $name,
$nrpe_plugin_liddir = $icinga2::params::nrpe_plugin_liddir,
$source_file = undef,

View file

@ -1,12 +1,12 @@
# Class: icinga2::client::service
# Class: icinga2::nrpe::service
#
# This class manges the daemons/services for the server components of Icinga.
#
# Parameters:
class icinga2::client::service inherits icinga2::client {
class icinga2::nrpe::service inherits icinga2::nrpe {
include icinga2::client
include icinga2::nrpe
#Service resource for NRPE.
#This references the daemon name we defined in the icinga2::params class based on the OS:
@ -14,7 +14,7 @@ class icinga2::client::service inherits icinga2::client {
ensure => running,
enable => true, #Enable the service to start on system boot
require => Package[$icinga2::params::icinga2_client_packages],
subscribe => Class['icinga2::client::config'], #Subscribe to the client::config class so the service gets restarted if any config files change
subscribe => Class['icinga2::nrpe::config'], #Subscribe to the client::config class so the service gets restarted if any config files change
}
}

13
manifests/object.pp Normal file
View file

@ -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 { }

54
manifests/object/host.pp Normal file
View file

@ -0,0 +1,54 @@
# == Defined type: icinga2::object::host
#
# This defined type
#
# === Parameters
#
# See the inline comments.
#
define icinga2::object::host (
$object_hostname = $name,
$display_name = $fqdn,
$ipv4_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',
$target_file_group = 'root',
$target_file_mode = '644'
) {
file {"${target_dir}/${target_file_name}":
ensure => file,
owner => $target_file_owner,
group => $target_file_group,
mode => $target_file_mode,
content => template('icinga2/object_host.conf.erb'),
notify => Service['icinga2'],
}
}

View file

@ -0,0 +1,31 @@
# == Defined type: icinga2::object::hostgroup
#
#
# === Parameters
#
# See the inline comments.
#
define icinga2::object::hostgroup (
$object_hostgroup_name = $name,
$display_name = $name,
$template_to_import = undef,
$groups = [],
$target_dir = '/etc/icinga2/conf.d',
$target_file_name = "${name}.conf",
$target_file_owner = 'root',
$target_file_group = 'root',
$target_file_mode = '644',
$assign_where = undef
) {
file {"${target_dir}/${target_file_name}":
ensure => file,
owner => $target_file_owner,
group => $target_file_group,
mode => $target_file_mode,
content => template('icinga2/object_hostgroup.conf.erb'),
notify => Service['icinga2'],
}
}

View file

@ -48,6 +48,9 @@ class icinga2::params {
$db_password = 'password'
$db_host = 'localhost'
#Whether to install the plugin packages when the icinga2::server class is applied:
$server_install_nagios_plugins = 'true'
##############################
# Icinga 2 server package parameters
@ -66,12 +69,12 @@ class icinga2::params {
#Ubuntu 12.04 doesn't have nagios-plugins-common or nagios-plugins-contrib packages available...
'12.04': {
$icinga2_server_package = 'icinga2'
$icinga2_server_plugin_packages = ["nagios-plugins", "nagios-plugins-basic", "nagios-plugins-standard", "nagios-snmp-plugins", "nagios-plugins-extra"]
$icinga2_server_plugin_packages = ["nagios-plugins", "nagios-plugins-basic", "nagios-plugins-standard", "nagios-snmp-plugins", "nagios-plugins-extra", "nagios-nrpe-plugin"]
}
#...but 14.04 does:
'14.04': {
$icinga2_server_package = 'icinga2'
$icinga2_server_plugin_packages = ["nagios-plugins", "nagios-plugins-basic", "nagios-plugins-common", "nagios-plugins-standard", "nagios-snmp-plugins", "nagios-plugins-extra", "nagios-plugins-contrib"]
$icinga2_server_plugin_packages = [ "nagios-plugins", "nagios-plugins-basic", "nagios-plugins-common", "nagios-plugins-standard", "nagios-snmp-plugins", "nagios-plugins-extra", "nagios-plugins-contrib", "nagios-nrpe-plugin"]
}
}
}

View file

@ -21,6 +21,7 @@ class icinga2::server (
$package_provider = $icinga2::params::package_provider,
$icinga2_server_package = $icinga2::params::icinga2_server_package,
#$server_db_schema_path = $icinga2::params::server_db_schema_path
$server_install_nagios_plugins = $icinga2::params::server_install_nagios_plugins,
) inherits icinga2::params {
#Pick set the right path where we can find the DB schema based on the OS...

View file

@ -75,10 +75,12 @@ class icinga2::server::install::packages inherits icinga2::server {
provider => $package_provider,
}
#Install the Nagios plugins packages:
package {$icinga2_server_plugin_packages:
ensure => installed,
provider => $package_provider,
if $server_install_nagios_plugins == true {
#Install the Nagios plugins packages:
package {$icinga2_server_plugin_packages:
ensure => installed,
provider => $package_provider,
}
}
#Pick the right DB lib package name based on the database type the user selected:

View file

@ -29,7 +29,7 @@
# LOG FACILITY
# The syslog facility that should be used for logging purposes.
log_facility=<%= scope.lookupvar('icinga2::client::nrpe_log_facility') %>
log_facility=<%= scope.lookupvar('icinga2::nrpe::nrpe_log_facility') %>
@ -38,7 +38,7 @@ log_facility=<%= scope.lookupvar('icinga2::client::nrpe_log_facility') %>
# number. The file is only written if the NRPE daemon is started by the root
# user and is running in standalone mode.
pid_file=<%= scope.lookupvar('icinga2::client::nrpe_pid_file_path') %>
pid_file=<%= scope.lookupvar('icinga2::nrpe::nrpe_pid_file_path') %>
# PORT NUMBER
@ -46,7 +46,7 @@ pid_file=<%= scope.lookupvar('icinga2::client::nrpe_pid_file_path') %>
# NOTE: This must be a non-priviledged port (i.e. > 1024).
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd
server_port=<%= scope.lookupvar('icinga2::client::nrpe_listen_port') %>
server_port=<%= scope.lookupvar('icinga2::nrpe::nrpe_listen_port') %>
@ -65,7 +65,7 @@ server_port=<%= scope.lookupvar('icinga2::client::nrpe_listen_port') %>
#
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd
nrpe_user=<%= scope.lookupvar('icinga2::client::nrpe_user') %>
nrpe_user=<%= scope.lookupvar('icinga2::nrpe::nrpe_user') %>
@ -75,7 +75,7 @@ nrpe_user=<%= scope.lookupvar('icinga2::client::nrpe_user') %>
#
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd
nrpe_group=<%= scope.lookupvar('icinga2::client::nrpe_group') %>
nrpe_group=<%= scope.lookupvar('icinga2::nrpe::nrpe_group') %>
@ -92,7 +92,7 @@ nrpe_group=<%= scope.lookupvar('icinga2::client::nrpe_group') %>
#
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd
allowed_hosts=<%= scope.lookupvar('icinga2::client::nrpe_allowed_hosts').join(',') %>
allowed_hosts=<%= scope.lookupvar('icinga2::nrpe::nrpe_allowed_hosts').join(',') %>
@ -138,7 +138,7 @@ dont_blame_nrpe=0
# syslog facility.
# Values: 0=debugging off, 1=debugging on
debug=<%= scope.lookupvar('icinga2::client::nrpe_debug_level') %>
debug=<%= scope.lookupvar('icinga2::nrpe::nrpe_debug_level') %>
@ -146,7 +146,7 @@ debug=<%= scope.lookupvar('icinga2::client::nrpe_debug_level') %>
# This specifies the maximum number of seconds that the NRPE daemon will
# allow plugins to finish executing before killing them off.
command_timeout=<%= scope.lookupvar('icinga2::client::nrpe_command_timeout') %>
command_timeout=<%= scope.lookupvar('icinga2::nrpe::nrpe_command_timeout') %>
@ -157,7 +157,7 @@ command_timeout=<%= scope.lookupvar('icinga2::client::nrpe_command_timeout') %>
# all network sessions are connected. This causes the nrpe daemons to
# accumulate, eating system resources. Do not set this too low.
connection_timeout=<%= scope.lookupvar('icinga2::client::nrpe_connection_timeout') %>
connection_timeout=<%= scope.lookupvar('icinga2::nrpe::nrpe_connection_timeout') %>

View file

@ -0,0 +1,93 @@
/**
* WARNING: This host definition is automatically generated by Puppet.
* ANY MANUAL CHANGES TO IT WILL GET OVERWRITTEN!
*/
/**
* A host definition. You can create your own configuration files
* in the conf.d directory (e.g. one per host). By default all *.conf
* files in this directory are included.
*
*/
object Host "<%= @object_hostname %>" {
<%#- If any of the @ parameters are undefined, don't print anything for them: -%>
<%- if @template_to_import -%>
<%#- Otherwise, include the parameter: -%>
import "<%= @template_to_import -%>"
<%- end -%>
<%- if @display_name -%>
display_name = "<%= @display_name -%>"
<%- end -%>
<%- 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 -%>
}

View file

@ -0,0 +1,28 @@
/**
* WARNING: This hostgroup definition is automatically generated by Puppet.
* ANY MANUAL CHANGES TO IT WILL GET OVERWRITTEN!
*/
/**
* A hostgroup definition. You can create your own configuration files
* in the conf.d directory (e.g. one per host). By default all *.conf
* files in this directory are included.
*
*/
object HostGroup "<%= @object_hostgroup_name %>" {
<%#- If any of the @ parameters are undefined, don't print anything for them: -%>
<%- if @template_to_import -%>
<%#- Otherwise, include the parameter: -%>
import "<%= @template_to_import -%>"
<%- end -%>
<%- if @display_name -%>
display_name = "<%= @display_name -%>"
<%- end -%>
<%- if @groups.length != 0 -%>
groups = [ <%- @groups.each do |group| -%> "<%= group %>", <%- end -%>]
<%- end -%>
<%- if @assign_where -%>
assign where "<%= @assign_where -%>"
<%- end -%>
}