Track1Agenda: exercises-log-management-tenshi.page

File exercises-log-management-tenshi.page, 7.2 KB (added by b.candler, 6 years ago)
Line 
1% Log Management Part 2: Using Tenshi
2%
3% Network Monitoring & Management
4
5# Notes
6
7* Commands preceded with "$" imply that you should execute the command as
8  a general user - not as root.
9* Commands preceded with "#" imply that you should be working as root.
10* Commands with more specific command lines (e.g. "RTR-GW>" or "mysql>")
11  imply that you are executing commands on remote equipment, or within
12  another program.
13
14# Exercises
15
16First make sure that your routers are configured to send logs to your PC
17(this should have been done in the previous exercise).
18
19## Update syslog-ng configuration
20
21If you have not already done so, log in to your virtual machine and become
22the root user:
23
24~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25$ sudo -s
26#
27~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28
29Configure syslog-ng to save all router logs in one file for monitoring purposes.
30
31Edit `/etc/syslog-ng/conf.d/10-network.conf`,
32
33~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34# cd /etc/syslog-ng/conf.d/
35# editor 10-network.conf
36~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37
38... and add this before the last closing brace ( }; ):
39
40~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41file("/var/log/network/everything", owner(root) group(root) perm(0644));
42~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43
44In the end, the contents of the file should look like:
45
46~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47filter f_routers { facility(local0); };
48
49log {
50        source(s_src);
51        filter(f_routers);
52        destination(routers);
53};
54
55destination routers {
56  file("/var/log/network/$YEAR/$MONTH/$DAY/$HOST-$YEAR-$MONTH-$DAY-$HOUR.log"
57  owner(root) group(root) perm(0644) dir_perm(0755) create_dirs(yes)
58  template("$YEAR $DATE $HOST $MSG\n"));
59
60  file("/var/log/network/everything", owner(root) group(root) perm(0644));
61
62};
63~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
64
65This will enable logging of ALL messages matching the local0 facility to a
66single file, so that we can run a monitoring script on the messages.
67
68Be sure to save and exit from the file.
69
70Now restart syslog-ng so that is sees the new configuration:
71
72~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73# service syslog-ng restart
74~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75
76
77## Log rotation
78
79Create a daily automated script to truncate the log file so it doesn't
80grow too big (COPY and PASTE):
81
82~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83# editor /etc/logrotate.d/everything
84
85/var/log/network/everything {
86  daily
87  copytruncate
88  rotate 1
89  postrotate
90        /etc/init.d/tenshi restart
91  endscript
92}
93~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
94
95Then save and exit from the file.
96
97
98## Install tenshi
99
100~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101# apt-get install tenshi
102~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
103
104
105## Configure tenshi
106
107Configure Tenshi to send you alarms when the routers are configured (COPY
108and PASTE):
109
110~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
111# editor /etc/tenshi/includes-available/network
112
113set logfile /var/log/network/everything
114set queue network_alarms tenshi@localhost sysadm@localhost [*/1 * * * *] Log check
115
116group_host 10.10
117network_alarms SYS-5-CONFIG_I
118network_alarms PRIV_AUTH_PASS
119network_alarms LINK
120group_end
121~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
122
123Then save and exit from the file.
124
125Create a symlink so that Tenshi loads your new file (COPY and PASTE):
126       
127~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
128# ln -s /etc/tenshi/includes-available/network /etc/tenshi/includes-active
129~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
130
131Finally restart Tenshi:
132
133~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
134# service tenshi restart
135~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
136
137
138## Testing Tenshi
139
140Log in to your router, and run some "config" commands (example below):
141
142~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
143$ ssh cisco@rtrX                [where "X" is your router number]
144rtrX> enable
145Password: <password>
146rtrX# config terminal
147rtrX(config)# int FastEthernet0/0
148rtrX(config-if)# description Description Change for FastEthernet0/0 for Tenshi
149rtrX(config-if)# ctrl-z
150rtrX# write memory
151~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
152
153Don't exit from the router yet. Just as in the previous syslog-ng exercises,
154attempt to shutdown / no shutdown loopback interface:
155
156~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
157rtrX# conf t
158rtrX(config)# interface Loopback 999
159rtrX(config-if)# shutdown
160~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
161
162wait a few seconds
163
164~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
165rtrX(config-if)# no shutdown
166~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
167
168Then exit, and save the config ("write mem"):
169
170~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
171rtrX(config-if)# ctrl-z                                 (same as exit, exit twice)
172rtrX# write memory
173rtr1# exit
174~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
175
176Verify that you are receiving emails to the sysadm user from Tenshi.
177A quick check is to look in the mail directory:
178
179~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
180$ ls -l /var/mail
181~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
182
183* Note: Tenshi checks /var/log/network/everything once a minute, so you may
184  have to wait up to a minute for the email to arrive to the sysadm user.
185
186Make sure you are logged in as sysadm (not root). Either open a new session
187to your virtual machine, or exit from the root user (exit). Then do:
188
189~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190$ mutt
191~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
192
193Scroll `up/down` to select a message from "tenshi@localhost", then press
194`ENTER` to view it, and `q` to quit and 'q' again to quit mutt.
195
196If mails are not arriving, then check the following:
197
198* Are logs arriving in the file `/var/log/network/everything`?
199
200        $ tail /var/log/network/everything
201
202* Do these logs show a hostname like 'rtr5', or possibly an IP like
20310.10.5.254 ? Remember that the way we have configured tenshi, it only looks
204at hostnames or IP addresses matching the pattern 'rtr' or '10.10' (depending
205on how you configured tenshi).
206
207* Check your tenshi configuration file. Restart tenshi if you change it.
208
209* If you are still stuck ask an instructor or a neighbor for help.
210
211
212## Optional: Add a new Tenshi rule
213
214See if you can figure out how to add a rule to Tenshi so that an email is
215sent if someone enters an incorrect enable password on your router.
216
217Hints:
218
219* "PRIV_AUTH_FAIL" is the Cisco IOS log message in such cases.
220* To test your new rule log in to your router, type "enable" and then enter
221  an incorrect enable password.