Skip to content

Commit 0a545b0

Browse files
committed
Convert all default checks to classes at last
This is a major change which should not break default checks, but will break any overrides set from Puppet manifests. Some of these now need to be set from hieradata.
1 parent 9ceedb9 commit 0a545b0

31 files changed

+432
-537
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Convert all relevant checks to classes, improving hiera override support.
12
* Add parameter to disable the default checks (#64, @rwf14f).
23
* Update ntp_time check to better handle defaults.
34
* Add server *_timeout parameters (#65, @zxjinn).

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ have my head hurt each time I have to make modificiations to it... but it is
1616
worth it, as it allows having monitoring automatically enabled by default
1717
on all nodes as well as for all standard services detected on them.
1818

19+
## Upgrading
20+
21+
Version 2 of the module has updated all default checks to become classes, in
22+
order to work better with hiera's class parameters automatic lookup. The
23+
drawback is that overrides which were set from manifests possibly need to be
24+
moved to hieradata.
25+
26+
When upgrading from version 1, if you see checks changing arguments or getting
27+
added or removed, look at the check's parameters and migrate your exsting
28+
overrides, typically :
29+
30+
```yaml
31+
# Override the critical value for check foo
32+
nagios::check::foo::args: '-c 10%'
33+
# Disable the bar check completely
34+
nagios::check::bar::ensure: 'absent'
35+
```
36+
1937
## Requirements
2038
2139
* Stored configurations enabled on the puppetmaster (mandatory)

TODO.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
* Clean up remaining check/*.pp definitions
2-
* Update all nrpe check/*.pp to use nagios::client::nrpe_plugin (sudo, pkg).
1+
* Update mysql_health to use nagios-plugins-contrib package on Debian.
2+
* Clean up mysql_health and postgres checks
33
* Create all tests
44
* Create wrappers for other nagios_* types to have the service reload?
55

manifests/check/conntrack.pp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,10 @@
99
$max_check_attempts = $::nagios::client::service_max_check_attempts,
1010
$notification_period = $::nagios::client::service_notification_period,
1111
$use = $::nagios::client::service_use,
12-
) {
12+
) inherits ::nagios::client {
1313

14-
# Service specific script
15-
file { "${nagios::client::plugin_dir}/check_conntrack":
16-
ensure => $ensure,
17-
owner => 'root',
18-
group => 'root',
19-
mode => '0755',
20-
content => template('nagios/plugins/check_conntrack'),
14+
nagios::client::nrpe_plugin { 'check_conntrack':
15+
ensure => $ensure,
2116
}
2217

2318
nagios::client::nrpe_file { 'check_conntrack':

manifests/check/couchbase.pp

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,42 @@
1-
define nagios::check::couchbase (
1+
class nagios::check::couchbase (
22
$ensure = undef,
3-
$args = undef,
3+
$args = '',
44
$couchbase_data_file_name = '/tmp/couchbase_data_file_name',
55
$couchbase_cbstats = '/opt/couchbase/bin/cbstats',
66
$couchbase_host = '127.0.0.1',
77
$couchbase_port = '11211',
8-
) {
8+
$check_title = $::nagios::client::host_name,
9+
$servicegroups = undef,
10+
$check_period = $::nagios::client::service_check_period,
11+
$contact_groups = $::nagios::client::service_contact_groups,
12+
$first_notification_delay = $::nagios::client::first_notification_delay,
13+
$max_check_attempts = $::nagios::client::service_max_check_attempts,
14+
$notification_period = $::nagios::client::service_notification_period,
15+
$use = $::nagios::client::service_use,
16+
) inherits ::nagios::client {
917

10-
# Generic overrides
11-
if $::nagios_check_couchbase_check_period != undef {
12-
Nagios_service { check_period => $::nagios_check_couchbase_check_period }
13-
}
14-
if $::nagios_check_couchbase_notification_period != undef {
15-
Nagios_service { notification_period => $::nagios_check_couchbase_notification_period }
16-
}
17-
18-
# Service specific overrides
19-
if $::nagios_check_couchbase_args != undef {
20-
$fullargs = $::nagios_check_couchbase_args
21-
} else {
22-
$fullargs = $args
23-
}
24-
25-
file { "${nagios::client::plugin_dir}/check_couchbase":
26-
ensure => $ensure,
27-
owner => 'root',
28-
group => 'root',
29-
mode => '0755',
30-
content => template('nagios/plugins/check_couchbase.erb'),
18+
nagios::client::nrpe_plugin { 'check_couchbase':
19+
ensure => $ensure,
20+
# We use all of the $couchbase_* parameters inside the template
21+
erb => true,
3122
}
3223

3324
nagios::client::nrpe_file { 'check_couchbase':
3425
ensure => $ensure,
35-
args => $fullargs,
26+
args => $args,
3627
}
3728

38-
nagios::service { "check_couchbase_${title}":
39-
ensure => $ensure,
40-
check_command => 'check_nrpe_couchbase',
41-
service_description => 'couchbase',
42-
#servicegroups => 'couchbase',
29+
nagios::service { "check_couchbase_${check_title}":
30+
ensure => $ensure,
31+
check_command => 'check_nrpe_couchbase',
32+
service_description => 'couchbase',
33+
servicegroups => $servicegroups,
34+
check_period => $check_period,
35+
contact_groups => $contact_groups,
36+
first_notification_delay => $first_notification_delay,
37+
notification_period => $notification_period,
38+
max_check_attempts => $max_check_attempts,
39+
use => $use,
4340
}
4441

4542
}
46-

manifests/check/cpu.pp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class nagios::check::cpu (
22
$ensure = undef,
3-
$args = '-w 10 -c 5',
3+
$args = '',
44
$check_title = $::nagios::client::host_name,
55
$servicegroups = undef,
66
$check_period = $::nagios::client::service_check_period,
@@ -9,20 +9,20 @@
99
$max_check_attempts = $::nagios::client::service_max_check_attempts,
1010
$notification_period = $::nagios::client::service_notification_period,
1111
$use = $::nagios::client::service_use,
12-
) {
12+
) inherits ::nagios::client {
1313

14-
# Service specific script
15-
file { "${nagios::client::plugin_dir}/check_cpu":
16-
ensure => $ensure,
17-
owner => 'root',
18-
group => 'root',
19-
mode => '0755',
20-
content => template('nagios/plugins/check_cpu'),
14+
nagios::client::nrpe_plugin { 'check_cpu':
15+
ensure => $ensure,
2116
}
2217

18+
# Include defaults if no overrides in $args
19+
if $args !~ /-w/ { $arg_w = '-w 10 ' } else { $arg_w = '' }
20+
if $args !~ /-c/ { $arg_c = '-c 5 ' } else { $arg_c = '' }
21+
$fullargs = strip("${arg_w}${arg_c}${args}")
22+
2323
nagios::client::nrpe_file { 'check_cpu':
2424
ensure => $ensure,
25-
args => $args,
25+
args => $fullargs,
2626
}
2727

2828
nagios::service { "check_cpu_${check_title}":
@@ -39,4 +39,3 @@
3939
}
4040

4141
}
42-

manifests/check/dir_status.pp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
define nagios::check::dir_status (
2+
$ensure = $::nagios_check_dir_status_ensure,
23
$args,
3-
$servicegroups = $::nagios_check_dir_status_servicegroups,
4-
$check_period = $::nagios_check_dir_status_check_period,
5-
$max_check_attempts = $::nagios_check_dir_status_max_check_attempts,
6-
$notification_period = $::nagios_check_dir_status_notification_period,
7-
$use = $::nagios_check_dir_status_use,
8-
$ensure = $::nagios_check_dir_status_ensure,
4+
$servicegroups = $::nagios_check_dir_status_servicegroups,
5+
$check_period = $::nagios_check_dir_status_check_period,
6+
$contact_groups = $::nagios::client::service_contact_groups,
7+
$first_notification_delay = $::nagios::client::first_notification_delay,
8+
$max_check_attempts = $::nagios_check_dir_status_max_check_attempts,
9+
$notification_period = $::nagios_check_dir_status_notification_period,
10+
$use = $::nagios::client::service_use,
911
) {
1012

1113
if $ensure != 'absent' {
@@ -19,15 +21,16 @@
1921
}
2022

2123
nagios::service { "check_dir_status_${title}_${::nagios::client::host_name}":
22-
ensure => $ensure,
23-
check_command => "check_nrpe_dir_status_${title}",
24-
service_description => "dir_status_${title}",
25-
servicegroups => $servicegroups,
26-
check_period => $check_period,
27-
max_check_attempts => $max_check_attempts,
28-
notification_period => $notification_period,
29-
use => $use,
24+
ensure => $ensure,
25+
check_command => "check_nrpe_dir_status_${title}",
26+
service_description => "dir_status_${title}",
27+
servicegroups => $servicegroups,
28+
check_period => $check_period,
29+
contact_groups => $contact_groups,
30+
first_notification_delay => $first_notification_delay,
31+
max_check_attempts => $max_check_attempts,
32+
notification_period => $notification_period,
33+
use => $use,
3034
}
3135

3236
}
33-

manifests/check/disk.pp

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,46 @@
1-
define nagios::check::disk (
2-
$ensure = $::nagios_check_disk_ensure,
3-
# We want to be able to manipulate the arguments in 3 parts :
4-
# original_args : useful default set for all nodes
5-
# args : the main warning and critical values
6-
# extra_args : optional additional arguments
7-
$original_args = $::nagios_check_disk_original_args,
8-
$args = $::nagios_check_disk_args,
9-
$extra_args = $::nagios_check_disk_extra_args,
10-
$servicegroups = $::nagios_check_disk_servicegroups,
11-
$check_period = $::nagios_check_disk_check_period,
12-
$max_check_attempts = $::nagios_check_disk_max_check_attempts,
13-
$notification_period = $::nagios_check_disk_notification_period,
14-
$use = $::nagios_check_disk_use,
15-
) {
1+
class nagios::check::disk (
2+
$ensure = undef,
3+
$args = '',
4+
# -l : Do not check network mounts, local (and checked) elsewhere
5+
# binfmt_misc : Denied by default, not useful to monitor
6+
# rpc_pipefs : Denied by default, not useful to monitor
7+
# cgroup : Denied by default, not useful to monitor
8+
$original_args = '-l -X binfmt_misc -X rpc_pipefs -X cgroup',
9+
$check_title = $::nagios::client::host_name,
10+
$servicegroups = undef,
11+
$check_period = $::nagios::client::service_check_period,
12+
$contact_groups = $::nagios::client::service_contact_groups,
13+
$first_notification_delay = $::nagios::client::first_notification_delay,
14+
$max_check_attempts = $::nagios::client::service_max_check_attempts,
15+
$notification_period = $::nagios::client::service_notification_period,
16+
$use = $::nagios::client::service_use,
17+
) inherits ::nagios::client {
1618

1719
if $ensure != 'absent' {
1820
Package <| tag == 'nagios-plugins-disk' |>
1921
}
2022

21-
$final_original_args = $original_args ? {
22-
# -l : Don't check network mounts, local (and checked) elsewhere
23-
# binfmt_misc : Denied by default, not useful to monitor
24-
# rpc_pipefs : Denied by default, not useful to monitor
25-
# cgroup : Denied by default, not useful to monitor
26-
undef => '-l -X binfmt_misc -X rpc_pipefs -X cgroup',
27-
default => $original_args,
28-
}
29-
$final_args = $args ? {
30-
undef => ' -w 5% -c 2%',
31-
default => " ${args}",
32-
}
33-
$final_extra_args = $extra_args ? {
34-
undef => '',
35-
default => " ${extra_args}",
36-
}
23+
# Include defaults if no overrides in $args
24+
if $args !~ /-w/ { $arg_w = '-w 5% ' } else { $arg_w = '' }
25+
if $args !~ /-c/ { $arg_c = '-c 2% ' } else { $arg_c = '' }
26+
$fullargs = strip("${original_args} ${arg_w}${arg_c}${args}")
27+
3728
nagios::client::nrpe_file { 'check_disk':
3829
ensure => $ensure,
39-
args => "${final_original_args}${final_args}${final_extra_args}",
30+
args => $fullargs,
4031
}
4132

42-
nagios::service { "check_disk_${title}":
43-
ensure => $ensure,
44-
check_command => 'check_nrpe_disk',
45-
service_description => 'disk',
46-
servicegroups => $servicegroups,
47-
check_period => $check_period,
48-
max_check_attempts => $max_check_attempts,
49-
notification_period => $notification_period,
50-
use => $use,
33+
nagios::service { "check_disk_${check_title}":
34+
ensure => $ensure,
35+
check_command => 'check_nrpe_disk',
36+
service_description => 'disk',
37+
servicegroups => $servicegroups,
38+
check_period => $check_period,
39+
contact_groups => $contact_groups,
40+
first_notification_delay => $first_notification_delay,
41+
notification_period => $notification_period,
42+
max_check_attempts => $max_check_attempts,
43+
use => $use,
5144
}
5245

5346
}
54-

manifests/check/hpsa.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
$max_check_attempts = $::nagios::client::service_max_check_attempts,
1111
$notification_period = $::nagios::client::service_notification_period,
1212
$use = $::nagios::client::service_use,
13-
) {
13+
) inherits ::nagios::client {
1414

1515
nagios::client::nrpe_plugin { 'check_hpsa':
1616
ensure => $ensure,

manifests/check/http.pp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
define nagios::check::http (
2+
$ensure = $::nagios_check_http_ensure,
23
$args,
3-
$servicegroups = $::nagios_check_http_servicegroups,
4-
$check_period = $::nagios_check_http_check_period,
5-
$max_check_attempts = $::nagios_check_http_max_check_attempts,
6-
$notification_period = $::nagios_check_http_notification_period,
7-
$use = $::nagios_check_http_use,
8-
$ensure = $::nagios_check_http_ensure,
4+
$servicegroups = $::nagios_check_http_servicegroups,
5+
$check_period = $::nagios_check_http_check_period,
6+
$contact_groups = $::nagios::client::service_contact_groups,
7+
$first_notification_delay = $::nagios::client::first_notification_delay,
8+
$max_check_attempts = $::nagios_check_http_max_check_attempts,
9+
$notification_period = $::nagios_check_http_notification_period,
10+
$use = $::nagios::client::service_use,
911
) {
1012

1113
if $ensure != 'absent' {
@@ -22,12 +24,13 @@
2224
ensure => $ensure,
2325
check_command => "check_nrpe_http_${title}",
2426
service_description => "http_${title}",
25-
servicegroups => $servicegroups,
26-
check_period => $check_period,
27-
max_check_attempts => $max_check_attempts,
28-
notification_period => $notification_period,
29-
use => $use,
27+
servicegroups => $servicegroups,
28+
check_period => $check_period,
29+
contact_groups => $contact_groups,
30+
first_notification_delay => $first_notification_delay,
31+
max_check_attempts => $max_check_attempts,
32+
notification_period => $notification_period,
33+
use => $use,
3034
}
3135

3236
}
33-

0 commit comments

Comments
 (0)