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

File exercises-nagios-IV-VIII-medium.md, 16.8 KB (added by jon, 5 years ago)

Nagios Exercises 2

Line 
1% Nagios Installation and Configuration
2%
3# Introduction
4
5## Goals
6
7* Install and configure Nagios
8
9## Notes
10
11* Commands preceded with "$" imply that you should execute the command as
12  a general user - not as root.
13* Commands preceded with "#" imply that you should be working as root.
14* Commands with more specific command lines (e.g. "rtrX>" or "mysql>")
15  imply that you are executing commands on remote equipment, or within
16  another program.
17
18# Exercises
19
20# PART IV - Adding Parent Relationships
21
22Each item is a child of either a switch or a router in our classroom, EXCEPT for
23your gateway router (rtrX) and the other members of your group. We are now going
24to add a "parents" statement for each device we have configured.
25
26If you are unsure of the parent relationships you can look at our classroom Network
27Diagram. Remember, the parent relationships are from the point of view of your Nagios
28instance running on your pc.
29
30## 1. Adding Parents to switches.cfg
31
32~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33$ cd /etc/nagios3/conf.d
34$ sudo editor switches.cfg
35~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36
37Update the entry:
38
39~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40define host {
41    use         generic-host
42    host_name   sw
43    alias       Backbone Switch
44    address     10.10.0.253
45}
46~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47
48
49to be
50
51
52~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53define host {
54    use         generic-host
55    host_name   sw
56    alias       Backbone Switch
57    address     10.10.0.253
58    parents     rtrX
59}
60~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61
62
63Where "rtrX" is the gateway router for your group. I.E., for group 1 you
64would use "rtr1", for group 2, "rtr2" and so forth.
65
66Save and exit from the file.
67
68
69## 2. Adding Parents to routers.cfg
70
71~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72$ sudo editor routers.cfg
73~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74
75For each entry we will add a "parents" line. So, for the gw definition at
76the top of the file this should now look like:
77
78
79~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
80define host {
81    use         generic-host
82    host_name   gw
83    alias       Classroom Gateway Router
84    address     10.10.0.254
85    parents     sw
86}
87~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
88
89For all the remaining rtrX entries, except for your group, you should a line
90line that says:
91
92~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93    parents     sw
94~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
95
96There should be NO PARENTS entry for your group. If you have an entry for "ap1"
97(classroom wireless access point), then the parents entry is, also, "sw" - same
98as the other routers.
99
100So, if you are in group 2, then the entries for groups 1, 2 and 3 would look like:
101
102~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
103define host {
104    use         generic-host
105    host_name   rtr1
106    alias       Group 1 Router
107    address     10.10.1.254
108    parents     sw
109}
110
111define host {
112    use         generic-host
113    host_name   rtr2
114    alias       Group 2 Router
115    address     10.10.2.254
116}
117
118define host {
119    use         generic-host
120    host_name   rtr3
121    alias       Group 3 Router
122    address     10.10.3.254
123    parents     sw
124}
125~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
126
127
128Update the rest of the file correctly and then save and exit from the file.
129
130
131## 3. Adding Parents to pcs.cfg
132
133For all the PC entries you should add a "parents" line that has the router
134for that PC's group, EXCEPT FOR YOUR GROUP - there should be no parents entry
135for the pcs in your group.
136
137For the noc the parent is the core switch or "sw"
138
139~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
140#
141# Classroom NOC
142#
143
144define host {
145    use         generic-host
146    host_name   noc
147    alias       Workshop NOC machine
148    address     10.10.0.250
149    parents     sw
150}
151
152
153For PCs in Group 1 entries look like:
154
155
156#
157# Group 1
158#
159
160define host {
161    use         generic-host
162    host_name   pc1
163    alias       pc1
164    address     10.10.1.1
165    parents     rtr1
166}
167
168define host {
169    use         generic-host
170    host_name   pc2
171    alias       pc2
172    address     10.10.1.2
173    parents     rtr1
174}
175
176~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
177
178etc
179
180Do this for all the PCs in the remaining groups. I.E., pc5 in Group 2 has
181a parents statement of:
182
183~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
184     parents    rtr2
185~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
186
187Just remember NOT to add a parents line for the PCs in your group.
188
189Save and exit from the file.
190
191
192## 4. Restart Nagios and See the Updated Status Map
193
194~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
195$ sudo service nagios3 restart
196~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
197
198If you have errors, fix these and try restarting again.
199
200Open a web browser to http://pcN.ws.nsrc.org/nagios3 and click on the "Map" link
201on the left. Your map should now look quite different. You should see a map that
202represents the Nagios world point of view from your machine.
203
204
205# PART V - Create More Host Groups
206
207## 0. Prep
208
209In the web view, look at the pages "Hostgroup Overview", "Hostgroup
210Summary", "Hostgroup Grid". This gives a convenient way to group together
211hosts which are related (e.g. in the same site, serving the same purpose).
212
213## 1. Update /etc/nagios3/conf.d/hostgroups_nagios2.cfg
214
215For the following exercises it will be very useful if we have created
216or update the following hostgroups:
217
218~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
219      debian-servers
220      routers
221      switches
222~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
223 
224If you edit the file /etc/nagios3/conf.d/hostgroups_nagios2.cfg you
225will see an entry for debian-servers that just contains localhost.
226Update this entry to include all the classroom PCs, including the
227noc (this assumes that you created a "noc" entry in your pcs.cfg
228file). Remember to skip your PC entry as it is represented by the
229localhost entry.
230
231~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
232$ sudo editor /etc/nagios3/conf.d/hostgroups_nagios2.cfg
233~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
234
235Update the entry that says:
236
237~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
238# A list of your Debian GNU/Linux servers
239define hostgroup {
240        hostgroup_name  debian-servers
241                alias           Debian GNU/Linux Servers
242                members         localhost
243        }
244~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
245     
246So that the "members" parameter contains something like this. Use your
247classroom network diagram to confirm the exact number of machines and names
248in your workshop.
249
250~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
251  members    localhost,pc1,pc2,pc3,pc4,pc5,pc6,pc7,pc8,pc9,pc10,pc11,pc12, \
252             pc13,pc14,pc15,pc16,pc17,pc18,pc19,pc20,pc21,pc22,pc23,pc24,pc25,\
253             pc26,pc27,pc28,pc29,pc30,pc31,pc32,pc33,pc34,pc35,pc36
254~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
255
256Be sure that the end of the line has a "\" to indicate a new line. Otherwise
257you will get an error when you go to restart Nagios. Remember that your own
258PC is "localhost", so skip your pc entry.
259
260Once you have done this, add one more host group for our classroom switch(es).
261If there is more than just one switch (sw.ws.nsrc.org) include this on the
262members line below, otherwise the entry at the end of the hostgroups_nagios2.cfg
263file should look like (COPY and PASTE):
264
265~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       
266# A list of our switches
267define hostgroup {
268        hostgroup_name  switches
269                alias           Classroom Switches
270                members         sw
271        }
272~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
273           
274When you are done be sure to verify your work and restart Nagios.
275 
276## 2. Go back to the web interface and look at your new Host Groups in Nagios.
277
278
279# PART VI - Extended Host Information ("making your graphs pretty")
280
281## 1. Update extinfo_nagios2.cfg
282
283If you would like to use appropriate icons for your defined hosts in
284Nagios this is where you do this. We have the three types of devices:
285
286* Cisco routers
287* Cisco switches
288* Ubuntu servers
289
290There is a fairly large repository of icon images available for you to
291use located here:
292
293~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
294/usr/share/nagios/htdocs/images/logos/
295~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
296
297these were installed by default as dependent packages of the nagios3
298package in Ubuntu. In some cases you can find model-specific icons for
299your hardware, but to make things simpler we will use the following
300icons for our hardware:
301
302~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
303/usr/share/nagios/htodcs/images/logos/base/debian.*
304/usr/share/nagios/htdocs/images/logos/cook/router.*
305/usr/share/nagios/htdocs/images/logos/cook/switch.*
306~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
307
308The next step is to edit the file /etc/nagios3/conf.d/extinfo_nagios2.cfg
309and tell nagios what image you would like to use to represent your devices.
310
311~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
312$ sudo editor /etc/nagios3/conf.d/extinfo_nagios2.cfg
313~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
314
315Here is what an entry for your routers looks like (there is already an entry
316for debian-servers that will work as is). Note that the router model (3600)
317is not all that important. The image used represents a router in general.
318
319~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
320define hostextinfo {
321        hostgroup_name   routers
322        icon_image       cook/router.png
323        icon_image_alt   Cisco Routers (7200)
324        vrml_image       router.png
325        statusmap_image  cook/router.gd2
326}
327~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
328
329Note how we can simply use "hostgroup_name routers" as this has already been
330defined in the file hostgroups_nagios2.cfg. This makes configuring multiple, like
331items much simpler.
332
333Now add an entry for your switches. Once you are done check your work and
334restart Nagios. Take a look at the Status Map in the web interface (Map link
335on the left). It should be much nicer, with real icons instead of question marks
336for most items.
337
338
339# PART VII - Create Service Groups
340
341## 1. Create service groups for ssh and http for each set of pcs.
342
343The idea here is to create three service groups. Each service group will
344be for a quarter of the classroom. We want to see these PCs grouped together
345and include status of their ssh and http services. To do this edit
346and create the file:
347
348~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
349$ cd /etc/nagios3/conf.d                        (just to be sure)
350$ sudo editor servicegroups.cfg
351~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
352
353Here is a sample of the service group for group 1:
354
355~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
356define servicegroup {
357        servicegroup_name       group1-services
358        alias                   group 1 services
359        members  pc1,SSH,pc1,HTTP,pc2,SSH,pc2,HTTP,pc3,SSH,pc3,HTTP,pc4,SSH,pc4,HTTP
360        }
361~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
362
363Note that if the members line is too long you can use the "\" at the end to
364create a new line of members just below.
365       
366Note that "SSH" and "HTTP" need to be uppercase as this is how the service_description is
367written in the file /etc/nagios3/conf.d/services_nagios2.cfg
368         
369You should create an entry for other groups of servers too.
370
371CRITICAL - When you create an entry for your group remember to use "localhost" instead
372of your "pcN" name since you have only defined your pc as localhost in the file
373hostgroups_nagios2.cfg.
374
375Save your changes, verify your work and restart Nagios. Now if you click on the
376Service Groups menu item in the Nagios web interface you should see this information
377grouped together.
378     
379
380# PART VIII - Configure Guest Access to the Nagios Web Interface
381
382## 1. You will edit the file /etc/nagios3/cgi.cfg to give read-only guest user access to the Nagios web interface.
383
384By default Nagios is configured to give full r/w access via the Nagios
385web interface to the user nagiosadmin. You can change the name of this
386user, add other users, change how you authenticate users, what users
387have access to what resources and more via the cgi.cfg file.
388
389First, lets create a "guest" user and password in the htpasswd.users
390file.
391     
392~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
393$ sudo htpasswd /etc/nagios3/htpasswd.users guest
394~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
395
396You can use any password you want (or none). A password of "guest" is
397not a bad choice.
398
399Next, edit the file /etc/nagios3/cgi.cfg and look for what type of access
400has been given to the nagiosadmin user. By default you will see the following
401directives (note, there are comments between each directive):
402
403~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
404authorized_for_system_information=nagiosadmin
405authorized_for_configuration_information=nagiosadmin
406authorized_for_system_commands=nagiosadmin
407authorized_for_all_services=nagiosadmin
408authorized_for_all_hosts=nagiosadmin
409authorized_for_all_service_commands=nagiosadmin
410authorized_for_all_host_commands=nagiosadmin
411~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
412
413Now let's tell Nagios to allow the "guest" user some access to
414information via the web interface. You can choose whatever you would
415like, but what is pretty typical is this:
416
417~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
418authorized_for_system_information=nagiosadmin,guest
419authorized_for_configuration_information=nagiosadmin,guest
420authorized_for_system_commands=nagiosadmin
421authorized_for_all_services=nagiosadmin,guest
422authorized_for_all_hosts=nagiosadmin,guest
423authorized_for_all_service_commands=nagiosadmin
424authorized_for_all_host_commands=nagiosadmin
425~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
426
427Note we do not give the guest user access to system commands, service commands
428nor host commands.
429
430Once you make the changes, save the file cgi.cfg, verify your
431work and restart Nagios.
432
433To see if you can log in as the "guest" user you will need to clear
434the cookies in your web browser or open an alternate web browser if you have one.
435You will not notice any difference in the web interface. The difference is that a
436number of items that are available via the web interface (forcing a service/host
437check, scheduling checks, comments, etc.) will not work for the guest user.
438
439## 2. Enable External commands in nagios.cfg
440
441This change is required in order to allow users to "Acknowledge" problems
442with hosts and services in the Web interface.  The default file permissions
443are set up in a secure way to prevent the web interface from updating
444nagios, so you need to make them slightly more permissive.
445
446First, edit the file "/etc/nagios3/nagios.cfg", and change the line:
447
448~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
449        check_external_commands=0
450~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
451
452to
453
454~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
455        check_external_commands=1
456~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
457
458Save the file and exit.
459
460Then, perform the following commands to change directory permissions and
461to make the changes permanent:
462
463~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
464$ sudo /etc/init.d/nagios3 stop
465$ sudo dpkg-statoverride --update --add nagios www-data 2710 /var/lib/nagios3/rw
466$ sudo dpkg-statoverride --update --add nagios nagios 751 /var/lib/nagios3
467$ sudo /etc/init.d/nagios3 start
468~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
469
470Once this is done, go to "Problems" > "Services (Unhandled)" and find a
471service in the red (critical) or yellow (warning) state. Click on the
472service name. Then under "Service commands" click on "Acknowledge this
473service problem".
474
475The problem should disappear from the list of unhandled problems.
476