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
#
# $name:
# Check command.
# Symbolic name for service check.
# $command:
# Check command (including arguments). Defaults to $name.
# $description:
# Service description. Defaults to command name without
# 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,
$package=undef) {
include nagios::target::nrpe
$binary = regsubst($name, '^([^ ]+) .*', '\1')
$service = regsubst($binary, '^check_(.+)', '\1')
if $command {
$command_real = $command
$binary = regsubst($command_real, '^([^ ]+) .*', '\1')
$config = $name
} else {
$command_real = $name
$binary = regsubst($command_real, '^([^ ]+) .*', '\1')
$config = $binary
}
if !$description {
$description = $service
$description = regsubst($binary, '^check_(.+)', '\1')
}
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,
mode => "0644",
owner => "root",
@ -556,12 +566,12 @@ define nagios::target::nrpe::service($source=undef,
"openbsd" => "wheel",
default => "root",
},
content => "command[${binary}]=${nagios::common::libdir}/${name}\n",
content => "command[${binary}]=${nagios::common::libdir}/${command_real}\n",
require => File["/etc/nrpe.d"],
notify => Service["nrpe"],
}
@@nagios::service { "${::homename}_${service}":
@@nagios::service { "${::homename}_${config}":
command => "check_nrpe!${binary}",
description => $description,
host => $::homename,