Agenda: exercises-nagios-IV-VIII-medium.htm

File exercises-nagios-IV-VIII-medium.htm, 20.5 KB (added by admin, 5 years ago)
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5  <meta http-equiv="Content-Style-Type" content="text/css" />
6  <meta name="generator" content="pandoc" />
7  <title>Nagios Installation and Configuration</title>
8  <style type="text/css">code{white-space: pre;}</style>
9  <link rel="stylesheet" href="../../style.css" type="text/css" />
10</head>
11<body>
12<div id="header">
13<h1 class="title">Nagios Installation and Configuration</h1>
14</div>
15<div id="TOC">
16<ul>
17<li><a href="#introduction"><span class="toc-section-number">1</span> Introduction</a><ul>
18<li><a href="#goals"><span class="toc-section-number">1.1</span> Goals</a></li>
19<li><a href="#notes"><span class="toc-section-number">1.2</span> Notes</a></li>
20</ul></li>
21<li><a href="#exercises"><span class="toc-section-number">2</span> Exercises</a></li>
22<li><a href="#part-iv---adding-parent-relationships"><span class="toc-section-number">3</span> PART IV - Adding Parent Relationships</a><ul>
23<li><a href="#adding-parents-to-switches.cfg"><span class="toc-section-number">3.1</span> 1. Adding Parents to switches.cfg</a></li>
24<li><a href="#adding-parents-to-routers.cfg"><span class="toc-section-number">3.2</span> 2. Adding Parents to routers.cfg</a></li>
25<li><a href="#adding-parents-to-pcs.cfg"><span class="toc-section-number">3.3</span> 3. Adding Parents to pcs.cfg</a></li>
26<li><a href="#restart-nagios-and-see-the-updated-status-map"><span class="toc-section-number">3.4</span> 4. Restart Nagios and See the Updated Status Map</a></li>
27</ul></li>
28<li><a href="#part-v---create-more-host-groups"><span class="toc-section-number">4</span> PART V - Create More Host Groups</a><ul>
29<li><a href="#prep"><span class="toc-section-number">4.1</span> 0. Prep</a></li>
30<li><a href="#update-etcnagios3conf.dhostgroups_nagios2.cfg"><span class="toc-section-number">4.2</span> 1. Update /etc/nagios3/conf.d/hostgroups_nagios2.cfg</a></li>
31<li><a href="#go-back-to-the-web-interface-and-look-at-your-new-host-groups-in-nagios."><span class="toc-section-number">4.3</span> 2. Go back to the web interface and look at your new Host Groups in Nagios.</a></li>
32</ul></li>
33<li><a href="#part-vi---extended-host-information-making-your-graphs-pretty"><span class="toc-section-number">5</span> PART VI - Extended Host Information (&quot;making your graphs pretty&quot;)</a><ul>
34<li><a href="#update-extinfo_nagios2.cfg"><span class="toc-section-number">5.1</span> 1. Update extinfo_nagios2.cfg</a></li>
35</ul></li>
36<li><a href="#part-vii---create-service-groups"><span class="toc-section-number">6</span> PART VII - Create Service Groups</a><ul>
37<li><a href="#create-service-groups-for-ssh-and-http-for-each-set-of-pcs."><span class="toc-section-number">6.1</span> 1. Create service groups for ssh and http for each set of pcs.</a></li>
38</ul></li>
39<li><a href="#part-viii---configure-guest-access-to-the-nagios-web-interface"><span class="toc-section-number">7</span> PART VIII - Configure Guest Access to the Nagios Web Interface</a><ul>
40<li><a href="#you-will-edit-the-file-etcnagios3cgi.cfg-to-give-read-only-guest-user-access-to-the-nagios-web-interface."><span class="toc-section-number">7.1</span> 1. You will edit the file /etc/nagios3/cgi.cfg to give read-only guest user access to the Nagios web interface.</a></li>
41<li><a href="#enable-external-commands-in-nagios.cfg"><span class="toc-section-number">7.2</span> 2. Enable External commands in nagios.cfg</a></li>
42</ul></li>
43</ul>
44</div>
45<h1 id="introduction"><a href="#introduction"><span class="header-section-number">1</span> Introduction</a></h1>
46<h2 id="goals"><a href="#goals"><span class="header-section-number">1.1</span> Goals</a></h2>
47<ul>
48<li>Install and configure Nagios</li>
49</ul>
50<h2 id="notes"><a href="#notes"><span class="header-section-number">1.2</span> Notes</a></h2>
51<ul>
52<li>Commands preceded with &quot;$&quot; imply that you should execute the command as a general user - not as root.</li>
53<li>Commands preceded with &quot;#&quot; imply that you should be working as root.</li>
54<li>Commands with more specific command lines (e.g. &quot;rtrX&gt;&quot; or &quot;mysql&gt;&quot;) imply that you are executing commands on remote equipment, or within another program.</li>
55</ul>
56<h1 id="exercises"><a href="#exercises"><span class="header-section-number">2</span> Exercises</a></h1>
57<h1 id="part-iv---adding-parent-relationships"><a href="#part-iv---adding-parent-relationships"><span class="header-section-number">3</span> PART IV - Adding Parent Relationships</a></h1>
58<p>Each item is a child of either a switch or a router in our classroom, EXCEPT for your gateway router (rtrX) and the other members of your group. We are now going to add a &quot;parents&quot; statement for each device we have configured.</p>
59<p>If you are unsure of the parent relationships you can look at our classroom Network Diagram. Remember, the parent relationships are from the point of view of your Nagios instance running on your pc.</p>
60<h2 id="adding-parents-to-switches.cfg"><a href="#adding-parents-to-switches.cfg"><span class="header-section-number">3.1</span> 1. Adding Parents to switches.cfg</a></h2>
61<pre><code>$ cd /etc/nagios3/conf.d
62$ sudo editor switches.cfg</code></pre>
63<p>Update the entry:</p>
64<pre><code>define host {
65    use         generic-host
66    host_name   sw
67    alias       Backbone Switch
68    address     10.10.0.253
69}</code></pre>
70<p>to be</p>
71<pre><code>define host {
72    use         generic-host
73    host_name   sw
74    alias       Backbone Switch
75    address     10.10.0.253
76    parents rtrX
77}</code></pre>
78<p>Where &quot;rtrX&quot; is the gateway router for your group. I.E., for group 1 you would use &quot;rtr1&quot;, for group 2, &quot;rtr2&quot; and so forth.</p>
79<p>Save and exit from the file.</p>
80<h2 id="adding-parents-to-routers.cfg"><a href="#adding-parents-to-routers.cfg"><span class="header-section-number">3.2</span> 2. Adding Parents to routers.cfg</a></h2>
81<pre><code>$ sudo editor routers.cfg</code></pre>
82<p>For each entry we will add a &quot;parents&quot; line. So, for the gw definition at the top of the file this should now look like:</p>
83<pre><code>define host {
84    use         generic-host
85    host_name   gw
86    alias       Classrooom Gateway Router
87    address     10.10.0.254
88    parents     sw
89}</code></pre>
90<p>For all the remaining rtrX entries you should, also, add a line that says:</p>
91<pre><code>    parents sw</code></pre>
92<p>EXCEPT For the rtrX entry for your group. There should be NO PARENTS entry. If you have an entry for &quot;ap1&quot; (classroom wireless access point), then the parents entry is, also, &quot;sw&quot; - same as the other routers.</p>
93<p>So, if you are in group 2, then the entries for groups 1, 2 and 3 would look like:</p>
94<pre><code>define host {
95    use         generic-host
96    host_name   rtr1
97    alias       Group 1 Router
98    address     10.10.1.254
99    parents     sw
100}
101
102define host {
103    use         generic-host
104    host_name   rtr2
105    alias       Group 2 Router
106    address     10.10.2.254
107}
108
109define host {
110    use         generic-host
111    host_name   rtr3
112    alias       Group 3 Router
113    address     10.10.3.254
114    parents     sw
115}</code></pre>
116<p>Update the rest of the file correctly and then save and exit from the file.</p>
117<h2 id="adding-parents-to-pcs.cfg"><a href="#adding-parents-to-pcs.cfg"><span class="header-section-number">3.3</span> 3. Adding Parents to pcs.cfg</a></h2>
118<p>For all the PC entries you should add a &quot;parents&quot; line that has the router for that PC's group. For the noc the parent is the core switch or &quot;sw&quot;</p>
119<pre><code>#
120# Classroom NOC
121#
122
123define host {
124    use         generic-host
125    host_name   noc
126    alias       Workshop NOC machine
127    address     10.10.0.250
128    parents     sw
129}
130
131
132For PCs in Group 1 entries look like:
133
134
135#
136# Group 1
137#
138
139define host {
140    use         generic-host
141    host_name   pc1
142    alias       pc1
143    address     10.10.1.1
144    parents     rtr1
145}
146
147define host {
148    use         generic-host
149    host_name   pc2
150    alias       pc2
151    address     10.10.1.2
152    parents     rtr1
153}
154</code></pre>
155<p>etc</p>
156<p>Do this for all the PCs in the remaining groups. I.E., pc5 in Group 2 has a parents statement of:</p>
157<pre><code>     parents    rtr2</code></pre>
158<p>BUT, FOR THE 4 ENTRIES FOR THE PCS IN YOUR GROUP DO NOT ADD ANY PARENTS STATEMENT! REPEAT - THE PCS IN YOUR GROUP DO NOT HAVE ANY PARENT ENTRY!</p>
159<p>Save and exit from the file.</p>
160<h2 id="restart-nagios-and-see-the-updated-status-map"><a href="#restart-nagios-and-see-the-updated-status-map"><span class="header-section-number">3.4</span> 4. Restart Nagios and See the Updated Status Map</a></h2>
161<pre><code>$ sudo service nagios3 restart</code></pre>
162<p>If you have errors, fix these and try restarting again.</p>
163<p>Open a web browser to http://pcN.ws.nsrc.org/nagios3 and click on the &quot;Map&quot; link on the left. Your map should now look quite different. You should see a map that represents the Nagios world point of view from your machine.</p>
164<h1 id="part-v---create-more-host-groups"><a href="#part-v---create-more-host-groups"><span class="header-section-number">4</span> PART V - Create More Host Groups</a></h1>
165<h2 id="prep"><a href="#prep"><span class="header-section-number">4.1</span> 0. Prep</a></h2>
166<p>In the web view, look at the pages &quot;Hostgroup Overview&quot;, &quot;Hostgroup Summary&quot;, &quot;Hostgroup Grid&quot;. This gives a convenient way to group together hosts which are related (e.g. in the same site, serving the same purpose).</p>
167<h2 id="update-etcnagios3conf.dhostgroups_nagios2.cfg"><a href="#update-etcnagios3conf.dhostgroups_nagios2.cfg"><span class="header-section-number">4.2</span> 1. Update /etc/nagios3/conf.d/hostgroups_nagios2.cfg</a></h2>
168<p>For the following exercises it will be very useful if we have created or update the following hostgroups:</p>
169<pre><code>      debian-servers
170      routers
171      switches</code></pre>
172<p>If you edit the file /etc/nagios3/conf.d/hostgroups_nagios2.cfg you will see an entry for debian-servers that just contains localhost. Update this entry to include all the classroom PCs, including the noc (this assumes that you created a &quot;noc&quot; entry in your pcs.cfg file). Remember to skip your PC entry as it is represented by the localhost entry.</p>
173<pre><code>$ sudo editor /etc/nagios3/conf.d/hostgroups_nagios2.cfg</code></pre>
174<p>Update the entry that says:</p>
175<pre><code># A list of your Debian GNU/Linux servers
176define hostgroup {
177        hostgroup_name  debian-servers
178                alias           Debian GNU/Linux Servers
179                members         localhost
180        }</code></pre>
181<p>So that the &quot;members&quot; parameter contains something like this. Use your classroom network diagram to confirm the exact number of machines and names in your workshop.</p>
182<pre><code>  members    localhost,pc1,pc2,pc3,pc4,pc5,pc6,pc7,pc8,pc9,pc10,pc11,pc12, \
183             pc13,pc14,pc15,pc16,pc17,pc18,pc19,pc20,pc21,pc22,pc23,pc24,pc25,\
184             pc26,pc27,pc28,pc29,pc30,pc31,pc32,pc33,pc34,pc35,pc36</code></pre>
185<p>Be sure that the end of the line has a &quot;&quot; to indicate a new line. Otherwise you will get an error when you go to restart Nagios. Remember that your own PC is &quot;localhost&quot;, so skip your pc entry.</p>
186<p>Once you have done this, add one more host group for our classroom switch(es). If there is more than just one switch (sw.ws.nsrc.org) include this on the members line below, otherwise the entry at the end of the hostgroups_nagios2.cfg file should look like (COPY and PASTE):</p>
187<pre><code># A list of our switches
188define hostgroup {
189        hostgroup_name  switches
190                alias           Classroom Switches
191                members         sw
192        }</code></pre>
193<p>When you are done be sure to verify your work and restart Nagios.</p>
194<h2 id="go-back-to-the-web-interface-and-look-at-your-new-host-groups-in-nagios."><a href="#go-back-to-the-web-interface-and-look-at-your-new-host-groups-in-nagios."><span class="header-section-number">4.3</span> 2. Go back to the web interface and look at your new Host Groups in Nagios.</a></h2>
195<h1 id="part-vi---extended-host-information-making-your-graphs-pretty"><a href="#part-vi---extended-host-information-making-your-graphs-pretty"><span class="header-section-number">5</span> PART VI - Extended Host Information (&quot;making your graphs pretty&quot;)</a></h1>
196<h2 id="update-extinfo_nagios2.cfg"><a href="#update-extinfo_nagios2.cfg"><span class="header-section-number">5.1</span> 1. Update extinfo_nagios2.cfg</a></h2>
197<p>If you would like to use appropriate icons for your defined hosts in Nagios this is where you do this. We have the three types of devices:</p>
198<ul>
199<li>Cisco routers</li>
200<li>Cisco switches</li>
201<li>Ubuntu servers</li>
202</ul>
203<p>There is a fairly large repository of icon images available for you to use located here:</p>
204<pre><code>/usr/share/nagios/htdocs/images/logos/</code></pre>
205<p>these were installed by default as dependent packages of the nagios3 package in Ubuntu. In some cases you can find model-specific icons for your hardware, but to make things simpler we will use the following icons for our hardware:</p>
206<pre><code>/usr/share/nagios/htodcs/images/logos/base/debian.*
207/usr/share/nagios/htdocs/images/logos/cook/router.*
208/usr/share/nagios/htdocs/images/logos/cook/switch.*</code></pre>
209<p>The next step is to edit the file /etc/nagios3/conf.d/extinfo_nagios2.cfg and tell nagios what image you would like to use to represent your devices.</p>
210<pre><code>$ sudo editor /etc/nagios3/conf.d/extinfo_nagios2.cfg</code></pre>
211<p>Here is what an entry for your routers looks like (there is already an entry for debian-servers that will work as is). Note that the router model (3600) is not all that important. The image used represents a router in general.</p>
212<pre><code>define hostextinfo {
213        hostgroup_name   routers
214        icon_image       cook/router.png
215        icon_image_alt   Cisco Routers (7200)
216        vrml_image       router.png
217        statusmap_image  cook/router.gd2
218}</code></pre>
219<p>Note how we can simply use &quot;hostgroup_name routers&quot; as this has already been defined in the file hostgroups_nagios2.cfg. This makes configuring multiple, like items much simpler.</p>
220<p>Now add an entry for your switches. Once you are done check your work and restart Nagios. Take a look at the Status Map in the web interface (Map link on the left). It should be much nicer, with real icons instead of question marks for most items.</p>
221<h1 id="part-vii---create-service-groups"><a href="#part-vii---create-service-groups"><span class="header-section-number">6</span> PART VII - Create Service Groups</a></h1>
222<h2 id="create-service-groups-for-ssh-and-http-for-each-set-of-pcs."><a href="#create-service-groups-for-ssh-and-http-for-each-set-of-pcs."><span class="header-section-number">6.1</span> 1. Create service groups for ssh and http for each set of pcs.</a></h2>
223<p>The idea here is to create three service groups. Each service group will be for a quarter of the classroom. We want to see these PCs grouped together and include status of their ssh and http services. To do this edit and create the file:</p>
224<pre><code>$ cd /etc/nagios3/conf.d            (just to be sure)
225$ sudo editor servicegroups.cfg</code></pre>
226<p>Here is a sample of the service group for group 1:</p>
227<pre><code>define servicegroup {
228    servicegroup_name   group1-services
229    alias           group 1 services
230    members  pc1,SSH,pc1,HTTP,pc2,SSH,pc2,HTTP,pc3,SSH,pc3,HTTP,pc4,SSH,pc4,HTTP
231        }</code></pre>
232<p>Note that if the members line is too long you can use the &quot;&quot; at the end to create a new line of members just below.</p>
233<p>Note that &quot;SSH&quot; and &quot;HTTP&quot; need to be uppercase as this is how the service_description is written in the file /etc/nagios3/conf.d/services_nagios2.cfg</p>
234<p>You should create an entry for other groups of servers too.</p>
235<p>CRITICAL - When you create an entry for your group remember to use &quot;localhost&quot; instead of your &quot;pcN&quot; name since you have only defined your pc as localhost in the file hostgroups_nagios2.cfg.</p>
236<p>Save your changes, verify your work and restart Nagios. Now if you click on the Service Groups menu item in the Nagios web interface you should see this information grouped together.</p>
237<h1 id="part-viii---configure-guest-access-to-the-nagios-web-interface"><a href="#part-viii---configure-guest-access-to-the-nagios-web-interface"><span class="header-section-number">7</span> PART VIII - Configure Guest Access to the Nagios Web Interface</a></h1>
238<h2 id="you-will-edit-the-file-etcnagios3cgi.cfg-to-give-read-only-guest-user-access-to-the-nagios-web-interface."><a href="#you-will-edit-the-file-etcnagios3cgi.cfg-to-give-read-only-guest-user-access-to-the-nagios-web-interface."><span class="header-section-number">7.1</span> 1. You will edit the file /etc/nagios3/cgi.cfg to give read-only guest user access to the Nagios web interface.</a></h2>
239<p>By default Nagios is configured to give full r/w access via the Nagios web interface to the user nagiosadmin. You can change the name of this user, add other users, change how you authenticate users, what users have access to what resources and more via the cgi.cfg file.</p>
240<p>First, lets create a &quot;guest&quot; user and password in the htpasswd.users file.</p>
241<pre><code>$ sudo htpasswd /etc/nagios3/htpasswd.users guest</code></pre>
242<p>You can use any password you want (or none). A password of &quot;guest&quot; is not a bad choice.</p>
243<p>Next, edit the file /etc/nagios3/cgi.cfg and look for what type of access has been given to the nagiosadmin user. By default you will see the following directives (note, there are comments between each directive):</p>
244<pre><code>authorized_for_system_information=nagiosadmin
245authorized_for_configuration_information=nagiosadmin
246authorized_for_system_commands=nagiosadmin
247authorized_for_all_services=nagiosadmin
248authorized_for_all_hosts=nagiosadmin
249authorized_for_all_service_commands=nagiosadmin
250authorized_for_all_host_commands=nagiosadmin</code></pre>
251<p>Now let's tell Nagios to allow the &quot;guest&quot; user some access to information via the web interface. You can choose whatever you would like, but what is pretty typical is this:</p>
252<pre><code>authorized_for_system_information=nagiosadmin,guest
253authorized_for_configuration_information=nagiosadmin,guest
254authorized_for_system_commands=nagiosadmin
255authorized_for_all_services=nagiosadmin,guest
256authorized_for_all_hosts=nagiosadmin,guest
257authorized_for_all_service_commands=nagiosadmin
258authorized_for_all_host_commands=nagiosadmin</code></pre>
259<p>Note we do not give the guest user access to system commands, service commands nor host commands.</p>
260<p>Once you make the changes, save the file cgi.cfg, verify your work and restart Nagios.</p>
261<p>To see if you can log in as the &quot;guest&quot; user you will need to clear the cookies in your web browser or open an alternate web browser if you have one. You will not notice any difference in the web interface. The difference is that a number of items that are available via the web interface (forcing a service/host check, scheduling checks, comments, etc.) will not work for the guest user.</p>
262<h2 id="enable-external-commands-in-nagios.cfg"><a href="#enable-external-commands-in-nagios.cfg"><span class="header-section-number">7.2</span> 2. Enable External commands in nagios.cfg</a></h2>
263<p>This change is required in order to allow users to &quot;Acknowledge&quot; problems with hosts and services in the Web interface. The default file permissions are set up in a secure way to prevent the web interface from updating nagios, so you need to make them slightly more permissive.</p>
264<p>First, edit the file &quot;/etc/nagios3/nagios.cfg&quot;, and change the line:</p>
265<pre><code>    check_external_commands=0</code></pre>
266<p>to</p>
267<pre><code>    check_external_commands=1</code></pre>
268<p>Save the file and exit.</p>
269<p>Then, perform the following commands to change directory permissions and to make the changes permanent:</p>
270<pre><code>$ sudo /etc/init.d/nagios3 stop
271$ sudo dpkg-statoverride --update --add nagios www-data 2710 /var/lib/nagios3/rw
272$ sudo dpkg-statoverride --update --add nagios nagios 751 /var/lib/nagios3
273$ sudo /etc/init.d/nagios3 start</code></pre>
274<p>Once this is done, go to &quot;Problems&quot; &gt; &quot;Services (Unhandled)&quot; and find a service in the red (critical) or yellow (warning) state. Click on the service name. Then under &quot;Service commands&quot; click on &quot;Acknowledge this service problem&quot;.</p>
275<p>The problem should disappear from the list of unhandled problems.</p>
276</body>
277</html>