How to add an NRPE command for Nagios Core

Some Nagios Core checks need information that only exists on the monitored Linux host, such as local disk usage, process state, or a site-specific script result. NRPE handles that handoff by letting the monitoring server request a named command while the monitored host runs the actual plugin.

Place the new NRPE entry on the monitored host, not in the main Nagios Core object files. The NRPE daemon reads definitions from /etc/nagios/nrpe.cfg and included drop-in files, then maps a request such as check_disk_root to one fixed plugin command line.

Keep routine NRPE commands fixed and avoid client-supplied arguments unless a specific check needs them. A completed change should let the monitoring server run check_nrpe against the new command name, validate the Nagios Core service object, and record the returned plugin output as a normal active service check.

Steps to add an NRPE command for Nagios Core:

  1. Confirm that NRPE loads drop-in files and allows the monitoring server.
    $ sudo cat /etc/nagios/nrpe.cfg
    ##### snipped #####
    allowed_hosts=127.0.0.1,::1,monitor.example.net
    dont_blame_nrpe=0
    include=/etc/nagios/nrpe_local.cfg
    include_dir=/etc/nagios/nrpe.d/
    ##### snipped #####

    Use the allowed_hosts value that matches the real Nagios Core server address. A fixed command does not require dont_blame_nrpe=1.

  2. Run the plugin manually on the monitored host.
    $ /usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /
    DISK OK - free space: / 104957MiB (91.7% inode=98%);| /=9980346368B;101195133747;113844525465;0;126493917184

    Use the plugin path from the monitored host. Debian and Ubuntu package installs place standard monitoring plugins under /usr/lib/nagios/plugins.
    Related: How to run a Nagios plugin manually

  3. Create a drop-in file for the new NRPE command.
    $ sudoedit /etc/nagios/nrpe.d/check_disk_root.cfg
  4. Add the fixed command definition.
    command[check_disk_root]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /

    The name inside command[...] is the command name that check_nrpe requests from the monitoring server.

    Do not expose unrestricted shell commands through NRPE. Fixed plugin arguments reduce the risk created by remote command argument processing.

  5. Restart the NRPE service on the monitored host.
    $ sudo systemctl restart nagios-nrpe-server

    Debian and Ubuntu package installs use the nagios-nrpe-server service name. Source installs or other distributions may use nrpe instead.

  6. Run the new NRPE command from the Nagios Core server.
    $ /usr/lib/nagios/plugins/check_nrpe -H web01.example.net -c check_disk_root
    DISK OK - free space: / 104957MiB (91.7% inode=98%);| /=9980346368B;101195133747;113844525465;0;126493917184

    A successful response proves that the monitoring server can reach the NRPE daemon and that the command name maps to the intended plugin result.

  7. Create or edit the Nagios Core service object for the monitored host.
    $ sudoedit /etc/nagios4/conf.d/web01-nrpe-disk.cfg

    The host object for web01.example.net must already exist. Add the host first when Nagios Core does not know that host yet.
    Related: How to add a host in Nagios Core

  8. Add the service definition that calls the NRPE command.
    define service {
        use                     generic-service
        host_name               web01.example.net
        service_description     Disk Usage
        check_command           check_nrpe!check_disk_root
    }

    Debian and Ubuntu packages provide the check_nrpe command object through /etc/nagios-plugins/config/check_nrpe.cfg. Source installs may need a matching command definition before this service parses.
    Related: How to define a Nagios Core check command
    Related: How to add a service check in Nagios Core

  9. Test the Nagios Core configuration.
    $ sudo nagios4 -v /etc/nagios4/nagios.cfg
    Nagios Core 4.4.6
    ##### snipped #####
    Reading configuration data...
       Read main config file okay...
       Read object config files okay...
    ##### snipped #####
    Total Warnings: 0
    Total Errors:   0
    
    Things look okay - No serious problems were detected during the pre-flight check

    Fix every reported object, command, template, or path error before reloading Nagios Core.
    Related: How to validate the Nagios Core configuration

  10. Reload Nagios Core after validation reports zero errors.
    $ sudo systemctl reload nagios4

    Ubuntu and Debian package installs use the nagios4 unit. Use the service name or source-install control method for the local installation.
    Related: How to manage the Nagios Core system service

  11. Confirm that the service records the NRPE plugin output after an active check runs.
    $ sudo cat /var/lib/nagios4/status.dat
    ##### snipped #####
    servicestatus {
    	host_name=web01.example.net
    	service_description=Disk Usage
    	check_command=check_nrpe!check_disk_root
    	has_been_checked=1
    	current_state=0
    	plugin_output=DISK OK - free space: / 104957MiB (91.7% inode=98%):
    ##### snipped #####

    Use the Services view or reschedule the active check if the service remains pending after the reload.
    Related: How to reschedule an active check in Nagios Core