{"id":38151,"date":"2016-07-28T11:09:43","date_gmt":"2016-07-28T05:39:43","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=38151"},"modified":"2016-12-22T12:42:04","modified_gmt":"2016-12-22T07:12:04","slug":"tips-for-configuring-nagios-wildcards-and-cfg-dir","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/tips-for-configuring-nagios-wildcards-and-cfg-dir\/","title":{"rendered":"Tips for configuring Nagios: Wildcards and cfg_dir"},"content":{"rendered":"<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-34915\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/05\/Nagios-logo.jpg\" alt=\"Nagios-logo\" width=\"738\" height=\"226\" \/><\/p>\n<p>Nagios is one of the most widely used monitoring tool today. Its open source, customizable , easy to use and highly efficient. While managing a large fleet of servers which includes different category of servers like webservers, db servers, api servers. This gets further more complicated if the number of servers in the fleet keeps on changing frequently.<\/p>\n<p>This article aims at focusing on some useful configuration tips for configuring Nagios monitoring system to save time and configuring host and services.<\/p>\n<p>Before proceeding with this blog further enable regexp in your nagios.cfg by enabling the following current setting:<\/p>\n<p><code>use_regexp_matching=1<\/code><\/p>\n<h3>1. Single entry for including all the configurations.<\/h3>\n<p>By default Nagios uses cfg_file entry in nagios.cfg\u00a0\u00a0 to include the configuration. In a large setup keeping all the configuration in a\u00a0couple of files can cause issues if the no. of hosts and configuration keeps changing frequently. To overcome this add following entry in your nagios.cfg file:<\/p>\n<p><code>cfg_dir=\/path\/to\/a\/directory #e.g. cfg_dir=\/usr\/local\/nagios\/etc\/hosts\/<\/code><\/p>\n<p>Reload your Nagios service. Now any .cfg file place inside hosts folder or on any subfolder\/hierarchical level inside hosts folder will automatically get included in your Nagios setup.<\/p>\n<h3>2. Wildcards<\/h3>\n<p>Let&#8217;s consider a scenario; your AWS fleet is serving example.com. This fleet includes DB servers, API servers, web servers etc.<\/p>\n<p>Create a hostgroup named primary.cfg (you can name the config file as per your wish. Important point to note is the file should end with .cfg):<\/p>\n<p>[js]<br \/>\ndefine hostgroup {<br \/>\nhostgroup_name\u00a0 example.com-servers<br \/>\nalias\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 example.com Servers<br \/>\nmembers\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .*<br \/>\n}<br \/>\n[\/js]<\/p>\n<p>Now, create the sub hostgroups:<\/p>\n<p>[js]<br \/>\ndefine hostgroup {<br \/>\nhostgroup_name\u00a0 example-web-servers<br \/>\nalias\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Example-web Servers<br \/>\nmembers\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .*_webservers<br \/>\n}<\/p>\n<p>define hostgroup {<br \/>\nhostgroup_name\u00a0 example-db-servers<br \/>\nalias\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 example db Servers<br \/>\nmembers\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .*_dbserver<br \/>\n}<br \/>\n[\/js]<\/p>\n<p>Now, create host as below:<\/p>\n<p>[js]<br \/>\ndefine host {<br \/>\nuse\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 generic-host<br \/>\nhost_name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 server-ip_dbserver<br \/>\ncheck_command\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 check-host-alive<br \/>\nalias\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 server-ip_dbserver<br \/>\naddress\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 server-ip<br \/>\ncontact_groups \u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0admins<br \/>\n}<\/p>\n<p>define host {<br \/>\nuse\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 generic-host<br \/>\nhost_name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 server-ip_webserver<br \/>\ncheck_command\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 check-host-alive<br \/>\nalias\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 server-ip_webserver<br \/>\naddress\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 server-ip<br \/>\ncontact_groups \u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0admins<br \/>\n}<br \/>\n[\/js]<\/p>\n<p>After reloading the Nagios service. You will notice all the servers are listed in the primary groups however the webserver hostgroup\u00a0shows only the webserver and DB server hostgroup shows only the DB server. In future, while adding new server, we would only have to consider the format of host_name and hostgroup i.e., server-ip_webserver or server-ip_dbserver and the new server will automatically become member of the respective hostgroups (Nagios service reload is required), hosts are now not required to be added to the members list of respective hostgroup cfg file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nagios is one of the most widely used monitoring tool today. Its open source, customizable , easy to use and highly efficient. While managing a large fleet of servers which includes different category of servers like webservers, db servers, api servers. This gets further more complicated if the number of servers in the fleet keeps [&hellip;]<\/p>\n","protected":false},"author":563,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":45},"categories":[2348,1],"tags":[3797,1500,3798,3799,3796],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/38151"}],"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\/563"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=38151"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/38151\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=38151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=38151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=38151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}