Puppet检查nagios资源是否存在

Puppet检查nagios资源是否存在,puppet,Puppet,我有一个puppet 3.8.5环境,其中包含一个模块,该模块以相同的方式在3台服务器上安装应用程序 在模块中,我有以下类 class app::monitoring { include nrpe include nagios::export @@nagios_contactgroup:{ 'APP': ensure => present, alias => 'APP Deve

我有一个puppet 3.8.5环境,其中包含一个模块,该模块以相同的方式在3台服务器上安装应用程序

在模块中,我有以下类

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                         => 'user1@somewhere.com',
  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',
    }
  }
正如预期的那样,当puppet在每台服务器上运行时,所有这些都正常工作,但当puppet在Nagios服务器上运行时,由于重复条目错误而失败。 是否有办法更改代码,以便在后续服务器上运行时不会出现重复的资源错误

目前,我正在手动创建

  • nagios_联络小组
  • nagios_联系人,以及
  • nagios_司令部
/etc/nagios/objects中的条目,以便将它们有效地硬编码到nagios中。
我希望能够在没有人为干预的情况下完全重建nagios。

您必须确保使用
@
导出的资源具有唯一的名称,以便在nagios服务器上收集资源时,不会获得重复的资源


请参阅。

我们遇到了相同的问题,并提出了一个解决方案-围绕
nagios_命令
和其他函数的包装:

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\u check
资源,但它们都有不同的名称,并且实际的
nagios\u命令只创建一次。

正确,这适用于@nagios\u服务之类的服务,但不适用于@nagios\u命令。您将使用同一命令3次,但使用的名称不同。