NRPE和$ USER1 $variables

我有所有我的远程Linux机器上运行的NRPE守护进程。 我有几个configuration,我试图在我的nrpe.cfg标准化path。 更改通过Puppet部署。

我想使用下面的语法:

command[mycommand]=$USER1$/check_tcp .. etc. 

$ USER1 $variables在我的NRPE设置中不可用。 我可以为所有变体编写Puppet模板,但是我更愿意通过本地方法来pipe理这个模板。 有什么可以做的吗? 如果没有任何人有一个示例Puppetconfiguration,将解决这个问题?

我可以为所有变体编写Puppet模板,但是我更愿意通过本地方法来pipe理这个模板。

$USERn$是Nagios的标准macros。 它们在resource.cfg文件中定义:

 # Sets $USER1$ to be the path to the plugins $USER1$=/usr/local/nagios/libexec # Sets $USER2$ to be the path to event handlers #$USER2$=/usr/local/nagios/libexec/eventhandlers 

这个文件包含在主configuration中:

 # This is an optional resource file that contains $USERx$ macro # definitions. Multiple resource files can be specified by using # multiple resource_file definitions. The CGIs will not attempt to # read the contents of resource files, so information that is resource_file=/usr/local/nagios/etc/resource.cfg 

AFAIK, 你不能在远程主机上使用NRPE

我把一个自定义的事实放在一起来解决我的需求。 我也尝试了一个应用拱形的小开关,但它不是跨平台的。

LIB / facter / nrpe.rb

 file = File.open("/etc/nagios/resource.cfg" , "r" ) while ( line = file.gets ) if /^\$USER1\$=(.*)/ =~ line matched="#{$1}" end end file.close Facter.add("nrpe") do setcode do matched end end 

以下是一些自定义事实,以及我们用于处理nrpe的清单代码。 确保木偶确保服务设置为在启动时启动,并正在运行。 由于我们运行Fedora 15,使用较旧版本的puppet,所以要注意一些puppet版本无法处理Fedora 15的systemd。

nrpe_plugin_directory.rb

 Facter.add("nrpe_plugin_directory") do setcode do %x{dirs="/usr/lib/nagios/plugins /usr/lib64/nagios/plugins /usr/local/nagios/libexec"; for dir in $dirs; do [[ -e $dir ]] && [[ ! -L $dir ]] && { echo $dir; exit; }; done}.chomp end end 

nrpe_cfg_file.rb

 Facter.add("nrpe_cfg_file") do setcode do %x{files="/etc/nagios/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg /usr/local/nagios/nrpe.cfg"; for file in $files; do [[ -f $file ]] && { echo $file; exit; }; done}.chomp end end 

清单代码:

  file{"/nagios/plugins": ensure => "symlink", target => "${nrpe_plugin_directory}", force => 'true', } file{"$nrpe_plugin_directory": source => "/..../plugins", ensure => "directory", recurse => "true", ignore => ".svn", } case $nrpe_cfg_file { undef: { } default:{ file{"/nagios/nrpe.cfg": ensure => "symlink", target => "${nrpe_cfg_file}", require => File["/nagios"], } file{"$nrpe_cfg_file": source => "/..../nrpe.cfg", } # .............. } 

在模块/ nagios / target / params.pp中:

 class nagios::target::params { case $operatingsystem { redhat,centos: { $nagios_plugin_dir = $architecture ? { x86_64 => "/usr/lib64/nagios/plugins/", i386 => "/usr/lib/nagios/plugins/", } } solaris: { $nagios_plugin_dir = '/opt/csw/libexec/nagios-plugins/' } } } 

在modules / nagios / templates / custom-checks.cfg中

 ... command[check_ram]=<%= scope.lookupvar('nagios::target::params::nagios_plugin_dir') %>check_mem.pl -C -w<%= ramwarn %> -c<%= ramcrit %> -f command[check_puppet]=<%= scope.lookupvar('nagios::target::params::nagios_plugin_dir') %>check_puppet.rb -w 1800 -c 3600 ... 

在模块/ nagios / target.pp中:

 include nagios::target::params file { "/etc/nrpe.d/50-custom-checks.cfg": ensure => present, notify => Service["nrpe"], require => Package['nrpe'], content => template("${module_name}/custom-checks.cfg.erb"), }