{"id":24011,"date":"2015-07-31T17:16:38","date_gmt":"2015-07-31T11:46:38","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=24011"},"modified":"2017-03-30T09:41:40","modified_gmt":"2017-03-30T04:11:40","slug":"using-nagios-core-and-nrpe-to-monitor-remote-linux-hosts","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/using-nagios-core-and-nrpe-to-monitor-remote-linux-hosts\/","title":{"rendered":"Using Nagios Core and NRPE to monitor remote linux hosts"},"content":{"rendered":"<p><strong>Prerequisites: <\/strong><\/p>\n<p>This tutorial requires existing Nagios server to be up and running and root privileges for Nagios server and remote Linux host. Please follow <a title=\"Setup Nagios\" href=\"http:\/\/www.tothenew.com\/blog\/getting-started-with-nagios\/\" target=\"_blank\">this<\/a> blog for its setup.<\/p>\n<p>Most of the system administrators write custom shell scripts \u00a0to do basic monitoring and sends email in case services crosses defined thresholds, but those scripts can&#8217;t provide complete insights of the host being monitored. To achieve this you will need to deploy a robust monitoring system that can provide features like Comprehensive Monitoring, Notification System, Reporting, Escalations, Event Handlers for Automation.<\/p>\n<p>I am writing this blog for continuing adding remote Linux hosts for monitoring in the Nagios server using NRPE daemon. This blog doesn&#8217;t include monitoring for Windows host or Network devices.<\/p>\n<p><strong>What is NRPE?<\/strong><\/p>\n<p>NRPE is a Nagios Remote Plugin Executor, it is used for monitoring remote Linux host services like CPU Load, Current Users, Disk Utilization, Swap Utilization, Memory Utilization. For monitoring, remote hosts, we need to install NRPE agent and update &#8216;\/etc\/nagios\/nrpe.cfg&#8217; file to allow access to Nagios server on port 5666. By default communication between Nagios server and NRPE agent is secure and uses the SSL tunnel for communication.<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-24029\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/13_NRPE_Setup.png\" alt=\"13_NRPE_Setup\" width=\"608\" height=\"178\" \/><\/p>\n<p><strong>NRPE Checks<\/strong><br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-24032\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/14_Direct_Indrect_npre_checks.png\" alt=\"14_Direct_Indrect_npre_checks\" width=\"609\" height=\"370\" \/><\/p>\n<p>a. <strong>Direct checks:<\/strong> Nagios server directly checks, remote Linux host for local resources like load, disk, swap usage etc. (as shown above)<\/p>\n<p>b. <strong>Indirect checks:<\/strong> If Nagios server can not access target remote Linux host, then we can install NRPE on other Linux host and use it to check remote services.\u00a0(as shown above)<\/p>\n<p><strong>Install NRPE server on Linux Host and NRPE Plugin on Nagios server<\/strong><\/p>\n<p>1. On Linux Host (Ubuntu)<br \/>\nFirst of all we will list down nagios-nrpe-server packages available, next install nagios-nrpe-server package as shown below and to check details about the package use the dpkg command as shown below:<\/p>\n<p>[js]aptitude search nagios-nrpe-server<br \/>\naptitude install nagios-nrpe-server<br \/>\ndpkg -L nagios-nrpe-server[\/js]<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-24012\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/1_search-nrpe-plugin.png\" alt=\"1_search-nrpe-plugin\" width=\"1029\" height=\"120\" \/><\/p>\n<p>2. On Nagios server (Ubuntu)<br \/>\nAs mentioned above, install nagios-nrpe-plugin on Nagios server, it will install nrpe command on the Nagios server.<\/p>\n<p>[js]aptitude search nagios-nrpe-plugin<br \/>\naptitude install nagios-nrpe-plugin<br \/>\ndpkg -L nagios-nrpe-plugin[\/js]<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-24013\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/2_nrpe-client-on-nagios-server.png\" alt=\"2_nrpe-client-on-nagios-server\" width=\"1029\" height=\"180\" \/><\/p>\n<p>In order to allow access to Nagios server, add a Nagios server IP to the allowed host (line no 81) in nrpe.cfg located in \/etc\/nagios\/nrpe.cfg. After making changes, restart nagios-nrpe-server on remote Linux host to update changes.<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-24014\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/3_modify-nrpe-cfg-nagios-server-ip.png\" alt=\"3_modify-nrpe-cfg-nagios-server-ip\" width=\"1029\" height=\"118\" \/><\/p>\n<p>[js]service nagios-nrpe-server reload[\/js]<\/p>\n<p>To validate changes, manually run check_nrpe command from the Nagios server with an IP of remote Linux host to check the version of NRPE installed on a remote Linux host. Commands to try:<\/p>\n<p>[js]\/usr\/lib\/nagios\/plugins\/check_nrpe -H 10.1.13.249 [\/js]<\/p>\n<p>[js]\/usr\/lib\/nagios\/plugins\/check_nrpe -H 10.1.13.249 -c check_load [\/js]<\/p>\n<h6><span style=\"color: #808080;\"><strong>Note: H argument is for specifying Host and c for specifying command to be executed on remote Linux host<\/strong><\/span><\/h6>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-24015\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/4_ns_manual_nrpe_commands.png\" alt=\"4_ns_manual_nrpe_commands\" width=\"1029\" height=\"65\" \/><\/p>\n<p><strong><span style=\"color: #ff6600;\">Example of NRPE Direct check:<\/span><\/strong><\/p>\n<p>By default nrpe.cfg configurations check disk using check_hda1. In my case drive name is \/dev\/sda1. So copy and paste above line and update command with the correct drive name(in my case \/dev\/sda1) and comment out the old line.<\/p>\n<p>[js] command[check_sda1]=\/usr\/lib\/nagios\/plugins\/check_disk -w 20% -c 10% -p \/dev\/sda1 [\/js]<\/p>\n<h6><span style=\"color: #808080;\"><strong>Note: In the above command arguments w is for warning, c is for critical and p is for partition, we will get warning alert if free space left reaches 20% and critical alert if it reaches 10%.\u00a0<\/strong><\/span><\/h6>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-24646\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/nrpr_cfg_new.png\" alt=\"nrpr_cfg_new\" width=\"1029\" height=\"100\" \/><\/p>\n<p>To execute nrpe commands using check_nrpe_1arg and &#8220;!&#8221; is used for passing arguments and in an argument we are passing check_sda1 (command defined on remote Linux host nrpe.cfg to check disk utilization)<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-24018\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/7_add-nrpe-config-ns-disk-sda.png\" alt=\"7_add-nrpe-config-ns-disk-sda\" width=\"1029\" height=\"125\" \/><\/p>\n<p>After making all the changes, restart Nagios service to make the changes effective.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-24019\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/8_nagios-server-sda1-monitoring.png\" alt=\"8_nagios-server-sda1-monitoring\" width=\"1029\" height=\"100\" \/><\/p>\n<p><strong><span style=\"color: #ff6600;\">Example of NRPE In-direct check:<\/span><\/strong><\/p>\n<p>We can monitor www.google.com URL directly from the Nagios server using check_http, but in order to demonstrate nrpe indirect check I will be monitoring URL from another Linux host as shown below. For this we will update nrpe.cfg on remote Linux host and add new command check_http_indirect.<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-24020\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/9_configure-indirect-http-on-linuxhost.png\" alt=\"9_configure-indirect-http-on-linuxhost\" width=\"1029\" height=\"100\" \/><\/p>\n<p>Once you update nrpe.cfg, try to run the command from terminal to validate we are getting desired output:<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-24021\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/10_check-indirect-check-cmd-linux-host.png\" alt=\"10_check-indirect-check-cmd-linux-host\" width=\"1029\" height=\"100\" \/><\/p>\n<p>After checking manually, add indirect check configuration to the demo.cfg and restart Nagios3 daemon to update changes.<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-24022\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/11_add-indirect-check-to-nagios-server.png\" alt=\"11_add-indirect-check-to-nagios-server\" width=\"1029\" height=\"125\" \/><\/p>\n<p>Based upon the check interval defined, in my case 2 minutes, check Nagios3 GUI for updated statistics:<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-24023\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/12_nagios-gui-check-indirect-check.png\" alt=\"12_nagios-gui-check-indirect-check\" width=\"1029\" height=\"35\" \/><\/p>\n<p>So this is how you can create multiple checks. In coming posts I will demonstrate how to enable custom checks <a href=\"http:\/\/www.tothenew.com\/blog\/how-to-create-plugin-in-nagios-using-bash-script\/\">using Nagios NRPE<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Prerequisites: This tutorial requires existing Nagios server to be up and running and root privileges for Nagios server and remote Linux host. Please follow this blog for its setup. Most of the system administrators write custom shell scripts \u00a0to do basic monitoring and sends email in case services crosses defined thresholds, but those scripts can&#8217;t [&hellip;]<\/p>\n","protected":false},"author":216,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":36},"categories":[1],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/24011"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/216"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=24011"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/24011\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=24011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=24011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=24011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}