# devops / monitoring / nrpe
Monitor Slaves & Set Alerts via NRPE
NRPE (Nagios Remote Plugin Executor) allows the central Nagios Master server to securely monitor system resources on remote Linux servers. Learn to link your slaves and configure instant email alerts for failures.
The Master-Slave Setup
By itself, the Nagios Master can only ping remote servers. To monitor internal metrics like CPU load or Root Disk space on a slave server, the Master must communicate with the NRPE daemon installed on that slave.
The Integration Flow
- 1. Slave Config
Whitelisting the Master server's IP address within the Slave's
nrpe.cfgfile. - 2. Master Config
Defining the Host and mapping the required Services within a new
slave.cfgfile on the Master. - 3. Notification
Defining contacts and routing alert emails through a Mail Transfer Agent.
Configure NRPE Daemon (Slave Server)
You must explicitly authorize the Nagios Master to talk to your Slave server. This is a crucial security layer to prevent unauthorized nodes from polling your system data.
The allowed_hosts Directive
By default, NRPE only accepts connections from 127.0.0.1. You must comma-separate the IP address of your central Nagios Master server in this list.
Define the Slave & Services (Master Server)
define host { use linux-server host_name Slave-Server-01 alias My Remote Linux Host address <Slave_IP_Address> max_check_attempts 5 check_period 24x7 notification_interval 30 notification_period 24x7 contact_groups admins register 1 } # Check CPU Load define service { use generic-service host_name Slave-Server-01 service_description CPU Load check_command check_nrpe!check_load } # Check Current Users define service { use generic-service host_name Slave-Server-01 service_description Current Users check_command check_nrpe!check_users }
The check_nrpe! Command
Notice the check_command block. check_nrpe sends the network request from the Master to the Slave. The string following the exclamation mark (e.g., check_load or check_disk) tells the remote Slave which local script to execute.
Configure Email Notifications
Nagios utilizes a Mail Transfer Agent (like Postfix or Sendmail) to route failure alerts. First, verify your server can send mail via the terminal, then define the user contact within Nagios.
define contact { contact_name shanmugananthan use generic-contact alias shan email shan@example.com service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r,f,s host_notification_options d,u,r,f,s service_notification_commands notify-service-by-email host_notification_commands notify-host-by-email } # Add user to the Admins group define contactgroup { contactgroup_name admins alias Nagios Administrators members nagiosadmin,shanmugananthan }