nagios: Allow multiple nrpe services with same check command name but different arguments.

This commit is contained in:
Timo Makinen 2014-12-11 10:08:42 +02:00
parent 9fd72f3147
commit 02574a3a37

View file

@ -491,7 +491,9 @@ class nagios::target::nrpe inherits nagios::target {
# === Parameters # === Parameters
# #
# $name: # $name:
# Check command. # Symbolic name for service check.
# $command:
# Check command (including arguments). Defaults to $name.
# $description: # $description:
# Service description. Defaults to command name without # Service description. Defaults to command name without
# check_ prefix. # check_ prefix.
@ -512,17 +514,25 @@ class nagios::target::nrpe inherits nagios::target {
# } # }
# } # }
# #
define nagios::target::nrpe::service($source=undef, define nagios::target::nrpe::service($command=undef,
$source=undef,
$description=undef, $description=undef,
$package=undef) { $package=undef) {
include nagios::target::nrpe include nagios::target::nrpe
$binary = regsubst($name, '^([^ ]+) .*', '\1') if $command {
$service = regsubst($binary, '^check_(.+)', '\1') $command_real = $command
$binary = regsubst($command_real, '^([^ ]+) .*', '\1')
$config = $name
} else {
$command_real = $name
$binary = regsubst($command_real, '^([^ ]+) .*', '\1')
$config = $binary
}
if !$description { if !$description {
$description = $service $description = regsubst($binary, '^check_(.+)', '\1')
} }
if $source and !defined(File["${nagios::common::libdir}/${binary}"]) { if $source and !defined(File["${nagios::common::libdir}/${binary}"]) {
@ -548,7 +558,7 @@ define nagios::target::nrpe::service($source=undef,
} }
} }
file { "${nagios::target::nrpe::nrpedir}/${binary}.cfg": file { "${nagios::target::nrpe::nrpedir}/${config}.cfg":
ensure => present, ensure => present,
mode => "0644", mode => "0644",
owner => "root", owner => "root",
@ -556,12 +566,12 @@ define nagios::target::nrpe::service($source=undef,
"openbsd" => "wheel", "openbsd" => "wheel",
default => "root", default => "root",
}, },
content => "command[${binary}]=${nagios::common::libdir}/${name}\n", content => "command[${binary}]=${nagios::common::libdir}/${command_real}\n",
require => File["/etc/nrpe.d"], require => File["/etc/nrpe.d"],
notify => Service["nrpe"], notify => Service["nrpe"],
} }
@@nagios::service { "${::homename}_${service}": @@nagios::service { "${::homename}_${config}":
command => "check_nrpe!${binary}", command => "check_nrpe!${binary}",
description => $description, description => $description,
host => $::homename, host => $::homename,