1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
---|
2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
---|
3 | <head> |
---|
4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
---|
5 | <meta http-equiv="Content-Style-Type" content="text/css" /> |
---|
6 | <meta name="generator" content="pandoc" /> |
---|
7 | <title>Log Management Part 2: Using Tenshi</title> |
---|
8 | <style type="text/css">code{white-space: pre;}</style> |
---|
9 | <link rel="stylesheet" href="../../style.css" type="text/css" /> |
---|
10 | </head> |
---|
11 | <body> |
---|
12 | <div id="header"> |
---|
13 | <h1 class="title">Log Management Part 2: Using Tenshi</h1> |
---|
14 | </div> |
---|
15 | <div id="TOC"> |
---|
16 | <ul> |
---|
17 | <li><a href="#notes"><span class="toc-section-number">1</span> Notes</a></li> |
---|
18 | <li><a href="#exercises"><span class="toc-section-number">2</span> Exercises</a><ul> |
---|
19 | <li><a href="#update-syslog-ng-configuration"><span class="toc-section-number">2.1</span> Update syslog-ng configuration</a></li> |
---|
20 | <li><a href="#log-rotation"><span class="toc-section-number">2.2</span> Log rotation</a></li> |
---|
21 | <li><a href="#install-tenshi"><span class="toc-section-number">2.3</span> Install tenshi</a></li> |
---|
22 | <li><a href="#configure-tenshi"><span class="toc-section-number">2.4</span> Configure tenshi</a></li> |
---|
23 | <li><a href="#testing-tenshi"><span class="toc-section-number">2.5</span> Testing Tenshi</a></li> |
---|
24 | <li><a href="#optional-add-a-new-tenshi-rule"><span class="toc-section-number">2.6</span> Optional: Add a new Tenshi rule</a></li> |
---|
25 | </ul></li> |
---|
26 | </ul> |
---|
27 | </div> |
---|
28 | <h1 id="notes"><a href="#notes"><span class="header-section-number">1</span> Notes</a></h1> |
---|
29 | <ul> |
---|
30 | <li>Commands preceded with "$" imply that you should execute the command as a general user - not as root.</li> |
---|
31 | <li>Commands preceded with "#" imply that you should be working as root.</li> |
---|
32 | <li>Commands with more specific command lines (e.g. "rtrX>" or "mysql>") imply that you are executing commands on remote equipment, or within another program.</li> |
---|
33 | </ul> |
---|
34 | <h1 id="exercises"><a href="#exercises"><span class="header-section-number">2</span> Exercises</a></h1> |
---|
35 | <p>First make sure that your routers are configured to send logs to your PC (this should have been done in the previous exercise).</p> |
---|
36 | <h2 id="update-syslog-ng-configuration"><a href="#update-syslog-ng-configuration"><span class="header-section-number">2.1</span> Update syslog-ng configuration</a></h2> |
---|
37 | <p>If you have not already done so, log in to your virtual machine and become the root user:</p> |
---|
38 | <pre><code>$ sudo -s |
---|
39 | #</code></pre> |
---|
40 | <p>Configure syslog-ng to save all router logs in one file for monitoring purposes.</p> |
---|
41 | <p>Edit <code>/etc/syslog-ng/conf.d/10-network.conf</code>,</p> |
---|
42 | <pre><code># cd /etc/syslog-ng/conf.d/ |
---|
43 | # editor 10-network.conf</code></pre> |
---|
44 | <p>... and add this just below the line that starts with "template":</p> |
---|
45 | <pre><code>file("/var/log/network/everything", owner(root) group(root) perm(0644));</code></pre> |
---|
46 | <p>In the end, the contents of the file should look like:</p> |
---|
47 | <pre><code>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 | };</code></pre> |
---|
63 | <p>This will enable logging of ALL messages matching the local0 facility to a single file, so that we can run a monitoring script on the messages.</p> |
---|
64 | <p>Be sure to save and exit from the file.</p> |
---|
65 | <p>Now restart syslog-ng so that is sees the new configuration:</p> |
---|
66 | <pre><code># service syslog-ng restart</code></pre> |
---|
67 | <h2 id="log-rotation"><a href="#log-rotation"><span class="header-section-number">2.2</span> Log rotation</a></h2> |
---|
68 | <p>Create a daily automated script to truncate the log file so it doesn't grow too big (COPY and PASTE):</p> |
---|
69 | <pre><code># editor /etc/logrotate.d/everything</code></pre> |
---|
70 | <p>Add the following to this file:</p> |
---|
71 | <pre><code>/var/log/network/everything { |
---|
72 | daily |
---|
73 | copytruncate |
---|
74 | rotate 1 |
---|
75 | postrotate |
---|
76 | /etc/init.d/tenshi restart |
---|
77 | endscript |
---|
78 | }</code></pre> |
---|
79 | <p>Then save and exit from the file.</p> |
---|
80 | <h2 id="install-tenshi"><a href="#install-tenshi"><span class="header-section-number">2.3</span> Install tenshi</a></h2> |
---|
81 | <pre><code># apt-get install tenshi</code></pre> |
---|
82 | <h2 id="configure-tenshi"><a href="#configure-tenshi"><span class="header-section-number">2.4</span> Configure tenshi</a></h2> |
---|
83 | <p>Configure Tenshi to send you alarms when the routers are configured (COPY and PASTE this text):</p> |
---|
84 | <pre><code># editor /etc/tenshi/includes-available/network</code></pre> |
---|
85 | <p>Add the following to this file:</p> |
---|
86 | <pre><code>set logfile /var/log/network/everything |
---|
87 | set queue network_alarms tenshi@localhost sysadm@localhost [*/1 * * * *] Log check |
---|
88 | |
---|
89 | group_host 10.10 |
---|
90 | network_alarms SYS-5-CONFIG_I |
---|
91 | network_alarms PRIV_AUTH_PASS |
---|
92 | network_alarms LINK |
---|
93 | group_end</code></pre> |
---|
94 | <p>Then save and exit from the file.</p> |
---|
95 | <p>Create a symlink so that Tenshi loads your new file (COPY and PASTE):</p> |
---|
96 | <pre><code># ln -s /etc/tenshi/includes-available/network /etc/tenshi/includes-active</code></pre> |
---|
97 | <p>Finally restart Tenshi:</p> |
---|
98 | <pre><code># service tenshi restart</code></pre> |
---|
99 | <p>You may see the following warning message:</p> |
---|
100 | <pre><code>"[WARNING] /var/log/network/everything: no such file"</code></pre> |
---|
101 | <p>don't worry, this is fine. The file "everything" will be created once an initial log message is received.</p> |
---|
102 | <h2 id="testing-tenshi"><a href="#testing-tenshi"><span class="header-section-number">2.5</span> Testing Tenshi</a></h2> |
---|
103 | <p>Log in to your router, and run some "config" commands (example below):</p> |
---|
104 | <pre><code>$ ssh cisco@rtrX [where "X" is your router number] |
---|
105 | rtrX> enable |
---|
106 | Password: <password> |
---|
107 | rtrX# config terminal |
---|
108 | rtrX(config)# int FastEthernet0/0 |
---|
109 | rtrX(config-if)# description Description Change for FastEthernet0/0 for Tenshi |
---|
110 | rtrX(config-if)# ctrl-z (same as exit, exit twice) |
---|
111 | rtrX# write memory</code></pre> |
---|
112 | <p>Don't exit from the router yet. Just as in the previous syslog-ng exercises, attempt to shutdown / no shutdown loopback interface:</p> |
---|
113 | <pre><code>rtrX# conf t |
---|
114 | rtrX(config)# interface Loopback 999 |
---|
115 | rtrX(config-if)# shutdown</code></pre> |
---|
116 | <p>wait a few seconds</p> |
---|
117 | <pre><code>rtrX(config-if)# no shutdown</code></pre> |
---|
118 | <p>Then exit, and save the config ("write mem"):</p> |
---|
119 | <pre><code>rtrX(config-if)# ctrl-z (same as exit, exit twice) |
---|
120 | rtrX# write memory |
---|
121 | rtrX# exit</code></pre> |
---|
122 | <p>Verify that you are receiving emails to the sysadm user from Tenshi. A quick check is to look in the mail directory:</p> |
---|
123 | <pre><code>$ ls -l /var/mail</code></pre> |
---|
124 | <ul> |
---|
125 | <li>Note: Tenshi checks /var/log/network/everything once a minute, so you may have to wait up to a minute for the email to arrive to the sysadm user.</li> |
---|
126 | </ul> |
---|
127 | <p>Make sure you are logged in as sysadm (not root). Either open a new session to your virtual machine, or exit from the root user (exit). Then do:</p> |
---|
128 | <pre><code>$ mutt</code></pre> |
---|
129 | <p>Scroll <code>up/down</code> to select a message from "tenshi@localhost", then press <code>ENTER</code> to view it, and <code>q</code> to quit and 'q' again to quit mutt.</p> |
---|
130 | <p>If mails are not arriving, then check the following:</p> |
---|
131 | <ul> |
---|
132 | <li><p>Are logs arriving in the file <code>/var/log/network/everything</code>?</p> |
---|
133 | <pre><code>$ tail /var/log/network/everything</code></pre></li> |
---|
134 | <li><p>Do these logs show a hostname like 'rtr5', or possibly an IP like 10.10.5.254 ? Remember that the way we have configured tenshi, it only looks at hostnames or IP addresses matching the pattern 'rtr' or '10.10' (depending on how you configured tenshi).</p></li> |
---|
135 | <li><p>Check your tenshi configuration file. Restart tenshi if you change it.</p></li> |
---|
136 | <li><p>If you are still stuck ask an instructor or a neighbor for help.</p></li> |
---|
137 | </ul> |
---|
138 | <h2 id="optional-add-a-new-tenshi-rule"><a href="#optional-add-a-new-tenshi-rule"><span class="header-section-number">2.6</span> Optional: Add a new Tenshi rule</a></h2> |
---|
139 | <p>See if you can figure out how to add a rule to Tenshi so that an email is sent if someone enters an incorrect enable password on your router.</p> |
---|
140 | <p>Hints:</p> |
---|
141 | <ul> |
---|
142 | <li>"PRIV_AUTH_FAIL" is the Cisco IOS log message in such cases.</li> |
---|
143 | <li>To test your new rule log in to your router, type "enable" and then enter an incorrect enable password.</li> |
---|
144 | <li>You will need to restart the Tenshi service once you have made your configuration changes.</li> |
---|
145 | </ul> |
---|
146 | </body> |
---|
147 | </html> |
---|