Agenda: exercises-log-management-tenshi.txt

File exercises-log-management-tenshi.txt, 7.3 KB (added by sysadmin, 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 rsyslog configuration
20
21If you have not already done so, log in to your virtual machine and become
22the root user:
23
24~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25$ sudo bash
26#
27~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28
29Configure rsyslog to save all router logs in one file for monitoring purposes.
30
31Edit `/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~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40local0.*        -?RouterLogs
41~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42
43... and add the following new line immediately after this:
44
45~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46local0.*        /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"
53local0.*        -?RouterLogs
54local0.*        /var/log/network/everything
55& ~
56~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57
58This will enable logging of ALL messages matching the local0 facility to a
59single file, so that we can run a monitoring script on the messages.
60
61Be sure to save and exit from the file.
62
63Now restart rsyslog so that is sees the new configuration:
64
65~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66# service rsyslog restart
67~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68
69
70## Log rotation
71
72Create a daily automated script to truncate the log file so it doesn't
73grow 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
88Then 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
100Configure Tenshi to send you alarms when the routers are configured (COPY
101and PASTE):
102
103~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104# editor /etc/tenshi/includes-available/network
105
106set logfile /var/log/network/everything
107set queue network_alarms tenshi@localhost sysadm@localhost [*/1 * * * *] Log check
108
109group_host rtr
110network_alarms SYS-5-CONFIG_I
111network_alarms PRIV_AUTH_PASS
112network_alarms LINK
113group_end
114~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
115
116Then save and exit from the file.
117
118Create 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
124Finally restart Tenshi:
125
126~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
127# service tenshi restart
128~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
129
130
131## Testing Tenshi
132
133Log in to your router, and run some "config" commands (example below):
134
135~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
136$ ssh cisco@rtrX                [where "X" is your router number]
137rtrX> enable
138Password: <password>
139rtrX# config terminal
140rtrX(config)# int FastEthernet0/0
141rtrX(config-if)# description Description Change for FastEthernet0/0 for Tenshi
142rtrX(config-if)# ctrl-z
143rtrX# write memory
144~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
145
146Don't exit from the router yet. Just as in the previous rsyslog exercises,
147attempt to shutdown / no shutdown loopback interface:
148
149~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
150rtrX# conf t
151rtrX(config)# interface Loopback 999
152rtrX(config-if)# shutdown
153~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
154
155wait a few seconds
156
157~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
158rtrX(config-if)# no shutdown
159~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
160
161Then exit, and save the config ("write mem"):
162
163~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
164rtrX(config-if)# ctrl-z                                 (same as exit, exit twice)
165rtrX# write memory
166rtr1# exit
167~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
168
169Verify that you are receiving emails to the sysadm user from Tenshi.
170A 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
179Make sure you are logged in as sysadm (not root). Either open a new session
180to your virtual machine, or exit from the root user (exit). Then do:
181
182~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
183$ mutt
184~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
185
186Scroll `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
189If 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
196configured 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
205See if you can figure out how to add a rule to Tenshi so that an email is
206sent if someone enters an incorrect enable password on your router.
207
208Hints:
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.