Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have NRPE daemons running on all of my remote Linux boxes. I have a couple configurations in place and I'm trying to standardize the paths in my nrpe.cfg. The changes are deployed via Puppet.

I would like to use the following syntax:

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

The $USER1$ variable is not available in my NRPE setup. I could write Puppet templates for all the variants but I would much prefer to manage this through a native method. Is there anything available to do so? If not does anyone have a sample Puppet config that will address this?

share|improve this question

I could write Puppet templates for all the variants but I would much prefer to manage this through a native method.

$USERn$ is a standard macro for Nagios. They are defined in the resource.cfg file:

# Sets $USER1$ to be the path to the plugins

# Sets $USER2$ to be the path to event handlers

and this file is included in the main 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

AFAIK, you cannot use it on the remote host, with NRPE.

share|improve this answer
That's what I figured. I was hoping there was some buried way that the remote NRPE daemon could read the remote resource.cfg file that is installed with the nagios-plugin package. Thanks for the input. – Tim Brigham Dec 1 '11 at 14:50
up vote 1 down vote accepted

I put together a custom Fact that addresses my needs. I also tried a small switch that would apply the arch but it wasn't cross platform.


file ="/etc/nagios/resource.cfg" , "r" )
while ( line = file.gets )
  if  /^\$USER1\$=(.*)/ =~ line
Facter.add("nrpe") do
  setcode do
share|improve this answer
At my work, we use a custom facts to know where the plugins dir is, and where the cfg is. We also created /nagios, and a symlink /nagios/nrpe.cfg to the actual config file, and /nagios/plugins to the actual plugin dir. Then all commands use /nagios/plugins/... – becomingwisest Nov 30 '11 at 20:03
That sounds appealing. Could you share the custom fact definition here? – Tim Brigham Nov 30 '11 at 20:24

Here are some of the custom facts, and manifest code we use for handling nrpe. Be sure that puppet ensures the service is setup to start at boot, and is running. Since we run Fedora 15, with an older version of puppet, be aware that some versions of puppet can't handle Fedora 15's systemd.


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


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

Manifest code:

                            ensure => "symlink",
                            target => "${nrpe_plugin_directory}",
                            force => 'true',

                            source => "/..../plugins",
                            ensure => "directory",
                            recurse => "true",
                            ignore => ".svn",
                    case $nrpe_cfg_file {
                            undef: { }
                                            ensure => "symlink",
                                            target => "${nrpe_cfg_file}",
                                            require => File["/nagios"],
                                            source => "/..../nrpe.cfg",
            # ..............
share|improve this answer

In modules/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/'

In modules/nagios/templates/custom-checks.cfg

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

In modules/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"),
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.