5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'manifests/check.pp', line 5
define nagios::check (
$executable,
# $parameters = hiera("nagios::check::${title}::parameters", undef),
$description = hiera("nagios::check::${title}::description", $title),
$nrpe_options = hiera("nagios::check::${title}::nrpe_options", '-t 15'),
$ensure = hiera("nagios::check::${title}::ensure", 'present'),
# $servicegroups = hiera("nagios::check::${title}::description",[]),
$check_period = hiera("nagios::check::${title}::check_period",undef),
$contact_groups = hiera("nagios::check::${title}::contact_groups",undef),
$max_check_attempts = hiera("nagios::check::${title}::max_check_attempts",undef),
$notification_period = hiera("nagios::check::${title}::notification_period",undef),
$use = hiera("nagios::check::${title}::use",undef),
) {
# We need to take default values from the nagios::client config
class { '::nagios::client': }
# Some constants that don't deserve to be parameters
$host_name = $nagios::client::host_name
$server = $nagios::client::server
# Review parameters to see if there is a better default (from nagios::client)
$final_check_period = $check_period ? {
undef => $nagios::client::service_check_period,
default => $check_period,
}
$final_contact_groups = $contact_groups ? {
undef => $nagios::client::service_contact_groups,
default => $contact_groups,
}
$final_max_check_attempts = $max_check_attempts ? {
undef => $nagios::client::service_max_check_attempts,
default => $max_check_attempts,
}
$final_notification_period = $notification_period ? {
undef => $nagios::client::service_notification_period,
default => $notification_period,
}
$final_use = $use ? {
undef => $nagios::client::service_use,
default => $use,
}
# Enable NRPE to execute it
file { "${nagios::params::nrpe_cfg_dir}/nrpe-check-${title}.cfg":
ensure => $ensure,
owner => 'root',
group => $nagios::client::nrpe_group,
mode => '0640',
content => "command[check_${title}]=${executable}\n",
notify => Service[$nagios::params::nrpe_service],
}
# Export the precious resource with all modified parameters
@@nagios_service { "check_${title}_${host_name}":
ensure => $ensure,
host_name => $host_name,
check_command => "check_${title}",
servicegroups => $servicegroups, # lint:ignore:variable_scope
service_description => $description,
check_period => $final_check_period,
contact_groups => $final_contact_groups,
max_check_attempts => $final_max_check_attempts,
notification_period => $final_notification_period,
use => $final_use,
# Support an arrays of tags for multiple nagios servers
tag => regsubst($server,'^(.+)$','nagios-\1'),
}
# Default line for nrpe invoke (used in the nagios_command)
$nrpe = "\$USER1\$/check_nrpe -H \$HOSTADDRESS\$ ${nrpe_options}"
# # NRPE parameters are a security risk, better disabled
# $command_parameters = $parameters? {
# undef => '',
# default => "-a $parameters",
# }
@@nagios_command { "check_${title}":
# command_line => "${nrpe} -c check_${title} $command_parameters",
command_line => "${nrpe} -c check_${title}",
tag => regsubst($server,'^(.+)$','nagios-\1'),
}
}
|