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 | |
---|
16 | First 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 | |
---|
21 | If you have not already done so, log in to your virtual machine and become |
---|
22 | the root user: |
---|
23 | |
---|
24 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
25 | $ sudo -s |
---|
26 | # |
---|
27 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
28 | |
---|
29 | Configure syslog-ng to save all router logs in one file for monitoring purposes. |
---|
30 | |
---|
31 | Edit `/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 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
41 | file("/var/log/network/everything", owner(root) group(root) perm(0644)); |
---|
42 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
43 | |
---|
44 | In the end, the contents of the file should look like: |
---|
45 | |
---|
46 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
47 | filter f_routers { facility(local0); }; |
---|
48 | |
---|
49 | log { |
---|
50 | source(s_src); |
---|
51 | filter(f_routers); |
---|
52 | destination(routers); |
---|
53 | }; |
---|
54 | |
---|
55 | destination 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 | |
---|
65 | This will enable logging of ALL messages matching the local0 facility to a |
---|
66 | single file, so that we can run a monitoring script on the messages. |
---|
67 | |
---|
68 | Be sure to save and exit from the file. |
---|
69 | |
---|
70 | Now restart syslog-ng so that is sees the new configuration: |
---|
71 | |
---|
72 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
73 | # service syslog-ng restart |
---|
74 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
75 | |
---|
76 | |
---|
77 | ## Log rotation |
---|
78 | |
---|
79 | Create a daily automated script to truncate the log file so it doesn't |
---|
80 | grow 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 | |
---|
95 | Then 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 | |
---|
107 | Configure Tenshi to send you alarms when the routers are configured (COPY |
---|
108 | and PASTE): |
---|
109 | |
---|
110 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
111 | # editor /etc/tenshi/includes-available/network |
---|
112 | |
---|
113 | set logfile /var/log/network/everything |
---|
114 | set queue network_alarms tenshi@localhost sysadm@localhost [*/1 * * * *] Log check |
---|
115 | |
---|
116 | group_host 10.10 |
---|
117 | network_alarms SYS-5-CONFIG_I |
---|
118 | network_alarms PRIV_AUTH_PASS |
---|
119 | network_alarms LINK |
---|
120 | group_end |
---|
121 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
122 | |
---|
123 | Then save and exit from the file. |
---|
124 | |
---|
125 | Create 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 | |
---|
131 | Finally restart Tenshi: |
---|
132 | |
---|
133 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
134 | # service tenshi restart |
---|
135 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
136 | |
---|
137 | |
---|
138 | ## Testing Tenshi |
---|
139 | |
---|
140 | Log in to your router, and run some "config" commands (example below): |
---|
141 | |
---|
142 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
143 | $ ssh cisco@rtrX [where "X" is your router number] |
---|
144 | rtrX> enable |
---|
145 | Password: <password> |
---|
146 | rtrX# config terminal |
---|
147 | rtrX(config)# int FastEthernet0/0 |
---|
148 | rtrX(config-if)# description Description Change for FastEthernet0/0 for Tenshi |
---|
149 | rtrX(config-if)# ctrl-z |
---|
150 | rtrX# write memory |
---|
151 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
152 | |
---|
153 | Don't exit from the router yet. Just as in the previous syslog-ng exercises, |
---|
154 | attempt to shutdown / no shutdown loopback interface: |
---|
155 | |
---|
156 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
157 | rtrX# conf t |
---|
158 | rtrX(config)# interface Loopback 999 |
---|
159 | rtrX(config-if)# shutdown |
---|
160 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
161 | |
---|
162 | wait a few seconds |
---|
163 | |
---|
164 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
165 | rtrX(config-if)# no shutdown |
---|
166 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
167 | |
---|
168 | Then exit, and save the config ("write mem"): |
---|
169 | |
---|
170 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
171 | rtrX(config-if)# ctrl-z (same as exit, exit twice) |
---|
172 | rtrX# write memory |
---|
173 | rtr1# exit |
---|
174 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
175 | |
---|
176 | Verify that you are receiving emails to the sysadm user from Tenshi. |
---|
177 | A 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 | |
---|
186 | Make sure you are logged in as sysadm (not root). Either open a new session |
---|
187 | to your virtual machine, or exit from the root user (exit). Then do: |
---|
188 | |
---|
189 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
190 | $ mutt |
---|
191 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
192 | |
---|
193 | Scroll `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 | |
---|
196 | If 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 |
---|
203 | 10.10.5.254 ? Remember that the way we have configured tenshi, it only looks |
---|
204 | at hostnames or IP addresses matching the pattern 'rtr' or '10.10' (depending |
---|
205 | on 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 | |
---|
214 | See if you can figure out how to add a rule to Tenshi so that an email is |
---|
215 | sent if someone enters an incorrect enable password on your router. |
---|
216 | |
---|
217 | Hints: |
---|
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. |
---|