我有一个包含一个安装在以相同的方式3级的服务器的应用程序的模块的傀儡3.8.5环境。
在模块我有下面的类
class app::monitoring {
include nrpe
include nagios::export
@@nagios_contactgroup:{ 'APP':
ensure => present,
alias => 'APP Developer',
members => 'user1, user2',
target => '/etc/nagios/conf.d/contacts.cfg',
}
@@nagios_contact {'user1':
ensure => present,
alias => 'user1',
email => '[email protected]',
service_notification_period => 'workhours',
host_notification_period => 'workhours',
service_notification_commands => 'notify-service-by-email',
host_notification_commands => 'notify-service-by-email',
target => '/etc/nagios/conf.d/contacts.cfg',
}
@@nagios_service { 'check_app_http_${fqdn}':
ensure => present,
use => "local-service',
host_name => $fqdn,
service_description => 'Check App - port 8000',
check_command => 'check_http_app!8000',
notifications_enabled => '1',
target => '/etc/nagios/conf.d/service.cfg',
}
@@nagios_command {"check_http_app":
ensure => present,
command_line => '/usr/lib64/nagios/plugins/check_http -H $HOSTADDRESS$ -p $ARG1$',
target => '/etc/nagios/conf.d/commands.cfg',
}
}
正如预期的正确所有的作品,当木偶在每台服务器上运行,但失败并重复输入错误当傀儡的Nagios服务器上运行。有没有办法改变的代码,这样,如果/当这是在随后的服务器上运行,我没有得到一个重复的资源错误?
目前,我手动创建
在/ etc / nagios的/对象的条目,使他们有效地被硬编码到Nagios的。我宁愿要能够完全重建的nagios无需人工干预的能力。
我们遇到了同样的问题,有一个解决办法想出了 - 周围nagios_command
等功能的包装:
define ournagios::nagios_command (
$nagios_title,
... # all other built-in parameters
){
# some custom code for changing parameters
# Note that any resource creation here must be
# wrapped with `if ! defined()`
if ! defined(Nagios_command["$nagios_title"]) {
nagios_command { $nagios_title:
command_name => $command_name,
ensure => $ensure,
command_line => $command_line,
group => $group,
mode => $mode,
owner => $owner,
poller_tag => $poller_tag,
provider => $provider,
target => $_target,
use => $use,
}
}
}
我们用这样的:
@@ournagios::nagios_command { "check_dns-${::hostname}":
nagios_title => "check_dns",
command_line => '$USER1$/check_dns -s \'$HOSTADDRESS$\' -H \'$ARG1$\' -a \'$ARG2$\' -w \'$ARG3$\' -c \'$ARG4$\'',
}
多ournagios::nagios_check
资源被创建,但他们都有不同的名称和实际nagios_command
只创建一次。
你必须确保你有@@
出口资源具有唯一的名称,这样,当它们在Nagios的服务器上收集你没有得到重复的资源。