summaryrefslogtreecommitdiff
path: root/kpov_judge/tasks/snmp_agent_uptime/howtos/en/index.html
blob: 19ffe87766e5295af4134e8441a0489f813e23b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <title>snmp_agent_uptime</title>
  </head>
  <body>
  <h1>snmp_agent_uptime</h1>
  <h2>Purpose of the assignment</h2>
    <p>
      ???
    </p>        
  <h2>Quick instructions</h2>
    <p>
      Set up three virtual computers, SimpleArbiter with the disk image
      simpleArbiterDhcp, SNMPServer and SNMPClient. Write a program
      called upminutes. This program should output the uptime of the
      computer in minutes. Set it up on SNMPClient in the home directory
      of the user test with the password test.
    </p>
    <p>
      Make sure that the SNMP server reports it's uptime in seconds
      over SNMP under NET-SNMP-EXTEND-MIB::nsExtendOutput2Table.
    </p>
    <p>
      Write a script called beri.sh that reads the value from the
      OID 1.3.6.1.4.1.8072.1.3.2.4.1.4 on SNMPServer. Set it up on
      SNMPClient in the home directory of the user test.
    </p>
  <h2>Instructions</h2>
  <h3>Set up of VM VirtualBox</h3>
    <ol>
      <li>
        Download the following virtual images (*.vid) from the directory
        with images of virtual computers:
        <ol type="disc">
          <li>
            simpleArbiterDhcp.vdi
          </li>
          <li>
            some-bash-console.vdi – twice, one for SNMPServer
            and second for SNMPClient
          </li>          
        </ol> 
      </li>
      <li>
        VM VirtualBox WARNING! If you want to use one same virtual image
        (some-bash-console.vdi) for two virtual computers
        (SNMPServer and SNMPClient), you must <strong>change UUID</strong>
        of one image.
        <ol type="disc">
          <li>
            Use this command
            <i>vboxmanage internalcommands sethduuid name-of-disk.vdi</i>
            to change UUID (<a href="http://www.giannistsakiris.com/2009/05/06/virtualbox-how-to-change-the-uuid-of-virtual-disk-vdi/">hint</a>). 
          </li>        
        </ol>        
      </li>
      <li>
        Final view of sets VM VirtualBox machines.<br>
        <img src="..\images\01.png" width="800">
      </li>
    </ol>
    
  <h3>Set up of SNMPServer machine</h3>
    <ol>
      <li>
        Install snmpd and snmp packages and tools for inspecting the
        data available over SNMP. 
          <ol type="disc">
            <li>
              command <i>apt-get install snmpd snmp snmp-mibs-downloader</i>
            </li>
          </ol> 
      <li>
        RECOMMENDATION! Before doing any changes to your /etc/snmp/snmpd.conf
        file take a copy of original file.
          <ol type="disc">
            <li>
              command <i>cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig</i>
            </li>
          </ol> 
      </li>
      <li>      
        Set up the snmp server to allow all other computers to access it = edit
        snmpd.conf file.
          <ol type="disc">
            <li>
              command <i>nano /etc/snmp/snmpd.conf</i> 
              (you can use different editor)
            </li>
            <li>
              (un)comment these four lines as below:<br>
              <i># Listen for connections from the local system only<br>
              # agentAddress  udp:127.0.0.1:161<br>     
              # Listen for connections on all interfaces (both IPv4 *and* IPv6)<br>
              agentAddress udp:161,udp6:[::1]:161</i>
            </li>            
          </ol> 
      </li>
      <li>      
       Add a group (community) of computers we deem to be worthy of
       accessing all data. This group will be called students = again edit
       snmpd.conf file. 
          <ol type="disc">
            <li>
              rocommunity students 0.0.0.0/0
            </li>
            <li>
              write correct network address = command <i>ifconfig -a</i>
            </li>                           
          </ol>      
      </li>
      <li>      
        OPTIONAL CONFIGURATION. Lower in the same file you can set the
        location of the computer snmpd is running on and the name
        of the administrator.
          <ol type="disc">
            <li>        
              find under # SYSTEM INFORMATION
            </li>               
          </ol>             
      </li>
      <li>
        Make sure that the SNMP server reports it's uptime in seconds
        over SNMP under NET-SNMP-EXTEND-MIB::nsExtendOutput2Table. 
          <ol type="disc"> 
            <li>            
              create script upseconds containing this and save it where
              you want:<br>
                <i>#!/bin/bash<br>
                uptime=$(&lt;/proc/uptime)<br>
                seconds=${uptime%%.*}<br>
                echo "Uptime in seconds:" $seconds<br>
                exit 0</i>              
            </li>
            <li>
              don't forget to make the script runnable:<br>
              command <i>chmod +x /your_path_to_script/upseconds</i>
            </li>            
            <li>        
              Then edit file <i>snmpd.conf</i> and under # EXTENDING THE AGENT
              comment all three tests and add your line of your code
              with upsecond script. It will look like this:<br>
              <i># extend test1 /bin/echo Hello, world!<br>
              # extend-sh test2 echo Hello, world! ; echo Hi there ; exit 35<br>
              # extend-sh test3 /bin/sh /tmp/shtest<br>
              extend-sh "your_name" "your_path_to_script_upseconds"
              </i>
            </li>               
          </ol>       
      </li>      
      <li>
        You need to restart the snmp services.
          <ol type="disc">
            <li>        
              command <i>/etc/init.d/snmpd restart</i>
            </li>               
          </ol>          
      </li>
      <li>      
        You can test your configuration through localhost.
          <ol type="disc">
            <li>        
              command <i>snmpwalk localhost -c public -v1</i>
            </li>               
          </ol>         
      </li>
      <li>      
        Also test the correct return of server's uptime in seconds SNMP under
        NET-SNMP-EXTEND-MIB::nsExtendOutput2Table.
          <ol type="disc">
            <li>        
              command <i>snmpwalk -c students -v1 IPaddressOfServer
              1.3.6.1.4.1.8072.1.3.2.4.1.2</i>
            </li>
            <li>        
              it should return one strings with "Uptime in seconds: xyz"
            </li>                           
          </ol>         
      </li>                                                     
    </ol>
          
  <h3>Set up of SNMPClient machine</h3>
    <ol>
      <li>
        Install snmpd and snmp packages. 
          <ol type="disc">
            <li>
              command <i>apt-get install snmpd snmp</i>
            </li>
          </ol> 
      <li>
        RECOMMENDATION! Before doing any changes to your /etc/snmp/snmpd.conf
        file take a copy of original file.
          <ol type="disc">
            <li>
              command <i>cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig</i>
            </li>
          </ol> 
      </li>
      <li>      
        Set up the snmp client to allow all other computers to access it = edit
        snmpd.conf file.
          <ol type="disc">
            <li>
              command <i>nano /etc/snmp/snmpd.conf</i> 
              (you can use different editor)
            </li>
            <li>
              (un)comment these four lines as below:<br>
              <i># Listen for connections from the local system only<br>
              # agentAddress  udp:127.0.0.1:161<br>     
              # Listen for connections on all interfaces (both IPv4 *and* IPv6)<br>
              agentAddress udp:161,udp6:[::1]:161</i>
            </li>            
          </ol> 
      </li>
      <li>      
       Add a group (community) of computers we deem to be worthy of
       accessing all data. This group will be called students = again edit
       snmpd.conf file. 
          <ol type="disc">
            <li>
              rocommunity students 0.0.0.0/0
            </li>
            <li>
              write correct network address = command <i>ifconfig -a</i>
            </li>                           
          </ol>      
      </li>
      <li>      
        OPTIONAL CONFIGURATION. Lower in the same file you can set the
        location of the computer snmpd is running on and the name
        of the administrator.
          <ol type="disc">
            <li>        
              find under # SYSTEM INFORMATION
            </li>               
          </ol>             
      </li>
            
      <li>
        You need to restart the snmp services.
          <ol type="disc">
            <li>        
              command <i>/etc/init.d/snmpd restart</i>
            </li>               
          </ol>          
      </li>
      <li>      
        You can test your configuration through localhost.
          <ol type="disc">
            <li>        
              command <i>snmpwalk localhost -c public -v1</i>
            </li>               
          </ol>         
      </li>                  
      <li>Create the user <i>test</i> with password <i>test</i>
        <ol type="disc">
          <li>
            command <i>adduser test</i>
          </li>         
        </ol> 
      </li>
      <li>Login as user <i>test</i> and create program <i>upminutes</i>
        in the home directory. This program should output the uptime of the
        computer in minutes.
        <ol type="disc">
          <li>
            command <i>nano upminutes</i> (you can use different editor)
          </li>
            <li>
            add the source code:<br>
            <i>#!/bin/bash<br>
            uptime=$(&lt;/proc/uptime)<br>
            uptime=${uptime%%.*}<br>
            minutes=$(( uptime / 60 ))<br>
            echo "Uptime in minutes:" $minutes<br>
            exit 0</i>
          </li>
          <li>
            don't forget to make the program runnable:<br>
            command <i>chmod +x /home/test/upminutes</i>
          </li>
          <li>
            test the program (it should output the uptime of the
            computer in minutes)<br>
            command <i>/home/test/upminutes</i>
          </li>
        </ol> 
      </li>
      <li>As user <i>test</i> and create next script called <i>beri.sh</i> that
        reads the value from the OID 1.3.6.1.4.1.8072.1.3.2.4.1.4.
        on SNMPServer. Set it up on SNMPClient in the home directory of the
        user test. 
        <ol type="disc">
          <li>
            command <i>nano beri.sh</i> (you can use different editor)
          </li>
            <li>
            add the source code:<br>
            <i>#!/bin/bash<br>
            snmpwalk -c students -v1 IPaddressOfServer 1.3.6.1.4.1.8072.1.3.2.4.1.4<br>
            exit 0</i>
          </li>
          <li>
            don't forget to make the program runnable:<br>
            command <i>chmod +x /home/test/upminutes</i>
          </li>
        </ol> 
      </li>      
    </ol>
         
  </body>
</html>