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 rsyslog 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 bash |
---|
26 | # |
---|
27 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
28 | |
---|
29 | Configure rsyslog to save all router logs in one file for monitoring purposes. |
---|
30 | |
---|
31 | Edit `/etc/rsyslog.d/30-routerlogs.conf`, |
---|
32 | |
---|
33 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
34 | # editor /etc/rsyslog.d/30-routerlogs.conf |
---|
35 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
36 | |
---|
37 | ... and find the line |
---|
38 | |
---|
39 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
40 | local0.* -?RouterLogs |
---|
41 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
42 | |
---|
43 | ... and add the following new line immediately after this: |
---|
44 | |
---|
45 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
46 | local0.* /var/log/network/everything |
---|
47 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
48 | |
---|
49 | (but before the line which says '& ~'). So what you should end up with is: |
---|
50 | |
---|
51 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
52 | $template RouterLogs,"/var/log/network/%$YEAR%/%$MONTH%/%$DAY%/%HOSTNAME%-%$HOUR%.log" |
---|
53 | local0.* -?RouterLogs |
---|
54 | local0.* /var/log/network/everything |
---|
55 | & ~ |
---|
56 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
57 | |
---|
58 | This will enable logging of ALL messages matching the local0 facility to a |
---|
59 | single file, so that we can run a monitoring script on the messages. |
---|
60 | |
---|
61 | Be sure to save and exit from the file. |
---|
62 | |
---|
63 | Now restart rsyslog so that is sees the new configuration: |
---|
64 | |
---|
65 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
66 | # service rsyslog restart |
---|
67 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
68 | |
---|
69 | |
---|
70 | ## Log rotation |
---|
71 | |
---|
72 | Create a daily automated script to truncate the log file so it doesn't |
---|
73 | grow too big (COPY and PASTE): |
---|
74 | |
---|
75 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
76 | # editor /etc/logrotate.d/everything |
---|
77 | |
---|
78 | /var/log/network/everything { |
---|
79 | daily |
---|
80 | copytruncate |
---|
81 | rotate 1 |
---|
82 | postrotate |
---|
83 | /etc/init.d/tenshi restart |
---|
84 | endscript |
---|
85 | } |
---|
86 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
87 | |
---|
88 | Then save and exit from the file. |
---|
89 | |
---|
90 | |
---|
91 | ## Install tenshi |
---|
92 | |
---|
93 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
94 | # apt-get install tenshi |
---|
95 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
96 | |
---|
97 | |
---|
98 | ## Configure tenshi |
---|
99 | |
---|
100 | Configure Tenshi to send you alarms when the routers are configured (COPY |
---|
101 | and PASTE): |
---|
102 | |
---|
103 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
104 | # editor /etc/tenshi/includes-available/network |
---|
105 | |
---|
106 | set logfile /var/log/network/everything |
---|
107 | set queue network_alarms tenshi@localhost sysadm@localhost [*/1 * * * *] Log check |
---|
108 | |
---|
109 | group_host rtr |
---|
110 | network_alarms SYS-5-CONFIG_I |
---|
111 | network_alarms PRIV_AUTH_PASS |
---|
112 | network_alarms LINK |
---|
113 | group_end |
---|
114 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
115 | |
---|
116 | Then save and exit from the file. |
---|
117 | |
---|
118 | Create a symlink so that Tenshi loads your new file (COPY and PASTE): |
---|
119 | |
---|
120 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
121 | # ln -s /etc/tenshi/includes-available/network /etc/tenshi/includes-active |
---|
122 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
123 | |
---|
124 | Finally restart Tenshi: |
---|
125 | |
---|
126 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
127 | # service tenshi restart |
---|
128 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
129 | |
---|
130 | |
---|
131 | ## Testing Tenshi |
---|
132 | |
---|
133 | Log in to your router, and run some "config" commands (example below): |
---|
134 | |
---|
135 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
136 | $ ssh cisco@rtrX [where "X" is your router number] |
---|
137 | rtrX> enable |
---|
138 | Password: <password> |
---|
139 | rtrX# config terminal |
---|
140 | rtrX(config)# int FastEthernet0/0 |
---|
141 | rtrX(config-if)# description Description Change for FastEthernet0/0 for Tenshi |
---|
142 | rtrX(config-if)# ctrl-z |
---|
143 | rtrX# write memory |
---|
144 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
145 | |
---|
146 | Don't exit from the router yet. Just as in the previous rsyslog exercises, |
---|
147 | attempt to shutdown / no shutdown loopback interface: |
---|
148 | |
---|
149 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
150 | rtrX# conf t |
---|
151 | rtrX(config)# interface Loopback 999 |
---|
152 | rtrX(config-if)# shutdown |
---|
153 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
154 | |
---|
155 | wait a few seconds |
---|
156 | |
---|
157 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
158 | rtrX(config-if)# no shutdown |
---|
159 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
160 | |
---|
161 | Then exit, and save the config ("write mem"): |
---|
162 | |
---|
163 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
164 | rtrX(config-if)# ctrl-z (same as exit, exit twice) |
---|
165 | rtrX# write memory |
---|
166 | rtr1# exit |
---|
167 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
168 | |
---|
169 | Verify that you are receiving emails to the sysadm user from Tenshi. |
---|
170 | A quick check is to look in the mail directory: |
---|
171 | |
---|
172 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
173 | $ ls -l /var/mail |
---|
174 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
175 | |
---|
176 | * Note: Tenshi checks /var/log/network/everything once a minute, so you may |
---|
177 | have to wait up to a minute for the email to arrive to the sysadm user. |
---|
178 | |
---|
179 | Make sure you are logged in as sysadm (not root). Either open a new session |
---|
180 | to your virtual machine, or exit from the root user (exit). Then do: |
---|
181 | |
---|
182 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
183 | $ mutt |
---|
184 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
185 | |
---|
186 | Scroll `up/down` to select a message from "tenshi@localhost", then press |
---|
187 | `ENTER` to view it, and `q` to quit and 'q' again to quit mutt. |
---|
188 | |
---|
189 | If mails are not arriving, then check the following: |
---|
190 | |
---|
191 | * Are logs arriving in the file `/var/log/network/everything`? |
---|
192 | |
---|
193 | $ tail /var/log/network/everything |
---|
194 | |
---|
195 | * Do these logs show a hostname like 'rtr5'? Remember that the way we have |
---|
196 | configured tenshi, it only looks at hostnames matching the pattern 'rtr' |
---|
197 | |
---|
198 | * Check your tenshi configuration file. Restart tenshi if you change it. |
---|
199 | |
---|
200 | * If you are still stuck ask an instructor or a neighbor for help. |
---|
201 | |
---|
202 | |
---|
203 | ## Optional: Add a new Tenshi rule |
---|
204 | |
---|
205 | See if you can figure out how to add a rule to Tenshi so that an email is |
---|
206 | sent if someone enters an incorrect enable password on your router. |
---|
207 | |
---|
208 | Hints: |
---|
209 | |
---|
210 | * "PRIV_AUTH_FAIL" is the Cisco IOS log message in such cases. |
---|
211 | * To test your new rule log in to your router, type "enable" and then enter |
---|
212 | an incorrect enable password. |
---|