{"id":47269,"date":"2017-03-29T15:57:56","date_gmt":"2017-03-29T10:27:56","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=47269"},"modified":"2017-03-30T09:42:47","modified_gmt":"2017-03-30T04:12:47","slug":"how-to-create-plugin-in-nagios-using-bash-script","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/how-to-create-plugin-in-nagios-using-bash-script\/","title":{"rendered":"How to Create Plugin in Nagios Using Bash Script?"},"content":{"rendered":"<p><b>Nagios<\/b> is an open source computer software application that monitors\u00a0systems, networks, and infrastructure. With <a href=\"http:\/\/www.tothenew.com\/blog\/using-nagios-core-and-nrpe-to-monitor-remote-linux-hosts\/\">Nagios<\/a>, we can monitor host and configure alerts on the services for servers, switches, applications. It sends alert messages to relevant people through emails when things go wrong and then sends another alert message when things get rectified.<\/p>\n<p>In this post, we will make our custom plugin <a title=\"Foolproof Your Bash Script\" href=\"http:\/\/www.tothenew.com\/blog\/foolproof-your-bash-script-some-best-practices\/\">using bash script<\/a> which is executed on every client machine using nrpe.<\/p>\n<p>First, install the Nagios-plugin and NRPE on the client servers<\/p>\n<p>[js]<br \/>\napt-get install -y nagios-plugins nagios-nrpe-server<br \/>\n[\/js]<\/p>\n<p>Furthermore, assume that we want to <a href=\"http:\/\/www.tothenew.com\/blog\/elasticsearch-plugins-for-monitoring-and-management-of-cluster-nodes\/\">monitor the memory of the server<\/a>. In order to achieve this, write a bash script memory.sh in the directory\u00a0<strong>\/usr\/lib\/Nagios\/plugins\/<\/strong> as shown below<\/p>\n<p>[js]<br \/>\n#!\/bin\/bash<br \/>\nfree -m | awk &#8216;NR==2{printf &quot;%.2f%%\\t\\t&quot;, $3*100\/$2 }&#8217;<br \/>\n[\/js]<\/p>\n<p>Now add the script file in the nrpe configuration file (\/etc\/Nagios\/nrpe.cfg) on the client VPS as shown below<\/p>\n<p>[js]<br \/>\ncommand[memory_bash]=\/usr\/lib\/nagios\/plugins\/memory.sh -w 85 -c 90<br \/>\n[\/js]<\/p>\n<p>Now on the Nagios-core server add the below command to Nagios checks in the commands.cfg file in \/etc\/nagios3\/ directory.<\/p>\n<p>[js]<br \/>\ndefine command{<br \/>\n       command_name     memory_bash<br \/>\n       command_line     $USER1$\/check_nrpe -H $HOSTADDRESS$ -c memory_bash<br \/>\n}<br \/>\n[\/js]<\/p>\n<p>Moving further, define a service in the configuration file to monitor the host as shown below:<\/p>\n<p>[js]<br \/>\ndefine service {<br \/>\n        use                             generic-service<br \/>\n        host_name                       i-085675f30c08376a3<br \/>\n        service_description             Custom memory checker In Bash<br \/>\n        check_command                   memory_bash<br \/>\n        }<br \/>\n[\/js]<\/p>\n<p>Now restart the nrpe server and nagios3 service as below<\/p>\n<p>[js]<br \/>\nservice nagios3 restart             ( on the nagios-core)<br \/>\nservice nagios-nrpe-server restart  ( on the client server)<br \/>\n[\/js]<\/p>\n<p>That&#8217;s it! Your Nagios UI will be able to check the results now. Hope this blog was helpful and you will yourself be able to create Plugin in Nagios using Bash Script.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nagios is an open source computer software application that monitors\u00a0systems, networks, and infrastructure. With Nagios, we can monitor host and configure alerts on the services for servers, switches, applications. It sends alert messages to relevant people through emails when things go wrong and then sends another alert message when things get rectified. In this post, [&hellip;]<\/p>\n","protected":false},"author":969,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":11},"categories":[4308,2348,1],"tags":[519,1500,4514,327],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/47269"}],"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\/969"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=47269"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/47269\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=47269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=47269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=47269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}