{"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":17,"footnotes":""},"categories":[4308,2348,1],"tags":[519,1500,4514,327],"class_list":["post-47269","post","type-post","status-publish","format-standard","hentry","category-cloud-devops-technology","category-devops-technology","category-technology","tag-bash-script","tag-nagios","tag-nrpe","tag-plugin"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"In this blog, we will show how to create a plugin in Nagios using Bash Script.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Shivam Agrawal\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.tothenew.com\/blog\/how-to-create-plugin-in-nagios-using-bash-script\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"How to Create Plugin in Nagios Using Bash Script? | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"In this blog, we will show how to create a plugin in Nagios using Bash Script.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.tothenew.com\/blog\/how-to-create-plugin-in-nagios-using-bash-script\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"How to Create Plugin in Nagios Using Bash Script? | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"In this blog, we will show how to create a plugin in Nagios using Bash Script.\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/how-to-create-plugin-in-nagios-using-bash-script\\\/#article\",\"name\":\"How to Create Plugin in Nagios Using Bash Script? | TO THE NEW Blog\",\"headline\":\"How to Create Plugin in Nagios Using Bash Script?\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/shivam-agrawal\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2017-03-29T15:57:56+05:30\",\"dateModified\":\"2017-03-30T09:42:47+05:30\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/how-to-create-plugin-in-nagios-using-bash-script\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/how-to-create-plugin-in-nagios-using-bash-script\\\/#webpage\"},\"articleSection\":\"Cloud, DevOps, Technology, bash script, Nagios, NRPE, plugin\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/how-to-create-plugin-in-nagios-using-bash-script\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"position\":2,\"name\":\"Technology\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/how-to-create-plugin-in-nagios-using-bash-script\\\/#listItem\",\"name\":\"How to Create Plugin in Nagios Using Bash Script?\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/how-to-create-plugin-in-nagios-using-bash-script\\\/#listItem\",\"position\":3,\"name\":\"How to Create Plugin in Nagios Using Bash Script?\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/shivam-agrawal\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/shivam-agrawal\\\/\",\"name\":\"Shivam Agrawal\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/how-to-create-plugin-in-nagios-using-bash-script\\\/#authorImage\",\"url\":\"https:\\\/\\\/newersworld-sf-static.tothenew.net\\\/prod\\\/profilePicFolder\\\/736102b9-6ed5-4e53-8aa4-522dbe873897_167-Shivam-Agrawal-PROFILEPICTURE.jpg\",\"width\":96,\"height\":96,\"caption\":\"Shivam Agrawal\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/how-to-create-plugin-in-nagios-using-bash-script\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/how-to-create-plugin-in-nagios-using-bash-script\\\/\",\"name\":\"How to Create Plugin in Nagios Using Bash Script? | TO THE NEW Blog\",\"description\":\"In this blog, we will show how to create a plugin in Nagios using Bash Script.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/how-to-create-plugin-in-nagios-using-bash-script\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/shivam-agrawal\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/shivam-agrawal\\\/#author\"},\"datePublished\":\"2017-03-29T15:57:56+05:30\",\"dateModified\":\"2017-03-30T09:42:47+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"How to Create Plugin in Nagios Using Bash Script? | TO THE NEW Blog","description":"In this blog, we will show how to create a plugin in Nagios using Bash Script.","canonical_url":"https:\/\/www.tothenew.com\/blog\/how-to-create-plugin-in-nagios-using-bash-script\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tothenew.com\/blog\/how-to-create-plugin-in-nagios-using-bash-script\/#article","name":"How to Create Plugin in Nagios Using Bash Script? | TO THE NEW Blog","headline":"How to Create Plugin in Nagios Using Bash Script?","author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/shivam-agrawal\/#author"},"publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"},"datePublished":"2017-03-29T15:57:56+05:30","dateModified":"2017-03-30T09:42:47+05:30","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.tothenew.com\/blog\/how-to-create-plugin-in-nagios-using-bash-script\/#webpage"},"isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/how-to-create-plugin-in-nagios-using-bash-script\/#webpage"},"articleSection":"Cloud, DevOps, Technology, bash script, Nagios, NRPE, plugin"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tothenew.com\/blog\/how-to-create-plugin-in-nagios-using-bash-script\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.tothenew.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","name":"Technology"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","position":2,"name":"Technology","item":"https:\/\/www.tothenew.com\/blog\/category\/technology\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/how-to-create-plugin-in-nagios-using-bash-script\/#listItem","name":"How to Create Plugin in Nagios Using Bash Script?"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/how-to-create-plugin-in-nagios-using-bash-script\/#listItem","position":3,"name":"How to Create Plugin in Nagios Using Bash Script?","previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","name":"Technology"}}]},{"@type":"Organization","@id":"https:\/\/www.tothenew.com\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/www.tothenew.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.tothenew.com\/blog\/author\/shivam-agrawal\/#author","url":"https:\/\/www.tothenew.com\/blog\/author\/shivam-agrawal\/","name":"Shivam Agrawal","image":{"@type":"ImageObject","@id":"https:\/\/www.tothenew.com\/blog\/how-to-create-plugin-in-nagios-using-bash-script\/#authorImage","url":"https:\/\/newersworld-sf-static.tothenew.net\/prod\/profilePicFolder\/736102b9-6ed5-4e53-8aa4-522dbe873897_167-Shivam-Agrawal-PROFILEPICTURE.jpg","width":96,"height":96,"caption":"Shivam Agrawal"}},{"@type":"WebPage","@id":"https:\/\/www.tothenew.com\/blog\/how-to-create-plugin-in-nagios-using-bash-script\/#webpage","url":"https:\/\/www.tothenew.com\/blog\/how-to-create-plugin-in-nagios-using-bash-script\/","name":"How to Create Plugin in Nagios Using Bash Script? | TO THE NEW Blog","description":"In this blog, we will show how to create a plugin in Nagios using Bash Script.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.tothenew.com\/blog\/how-to-create-plugin-in-nagios-using-bash-script\/#breadcrumblist"},"author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/shivam-agrawal\/#author"},"creator":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/shivam-agrawal\/#author"},"datePublished":"2017-03-29T15:57:56+05:30","dateModified":"2017-03-30T09:42:47+05:30"},{"@type":"WebSite","@id":"https:\/\/www.tothenew.com\/blog\/#website","url":"https:\/\/www.tothenew.com\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"How to Create Plugin in Nagios Using Bash Script? | TO THE NEW Blog","og:description":"In this blog, we will show how to create a plugin in Nagios using Bash Script.","og:url":"https:\/\/www.tothenew.com\/blog\/how-to-create-plugin-in-nagios-using-bash-script\/","og:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"How to Create Plugin in Nagios Using Bash Script? | TO THE NEW Blog","twitter:description":"In this blog, we will show how to create a plugin in Nagios using Bash Script.","twitter:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"47269","title":"How to Create Plugin in Nagios Using Bash Script? | #site_title","description":"In this blog, we will show how to create a plugin in Nagios using Bash Script.","keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":"","og_description":"","og_object_type":"blog","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":"","og_article_tags":"","twitter_use_og":false,"twitter_card":"summary","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2021-04-29 12:28:12","updated":"2024-02-29 08:37:25","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\/category\/technology\/\" title=\"Technology\">Technology<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tHow to Create Plugin in Nagios Using Bash Script?\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.tothenew.com\/blog"},{"label":"Technology","link":"https:\/\/www.tothenew.com\/blog\/category\/technology\/"},{"label":"How to Create Plugin in Nagios Using Bash Script?","link":"https:\/\/www.tothenew.com\/blog\/how-to-create-plugin-in-nagios-using-bash-script\/"}],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/47269","targetHints":{"allow":["GET"]}}],"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}]}}