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