1 | Network Management and Monitoring |
---|
2 | |
---|
3 | Cacti command line tools |
---|
4 | ======================== |
---|
5 | |
---|
6 | Notes: |
---|
7 | ------ |
---|
8 | * Commands preceded with "$" imply that you should execute the command as |
---|
9 | a general user - not as root. |
---|
10 | * Commands preceded with "#" imply that you should be working as root. |
---|
11 | * Commands with more specific command lines (e.g. "RTR-GW>" or "mysql>") |
---|
12 | imply that you are executing commands on remote equipment, or within |
---|
13 | another program. |
---|
14 | |
---|
15 | |
---|
16 | As you have noticed, adding devices to Cacti via the user interface can take |
---|
17 | quite some time, as for each device you will have: |
---|
18 | |
---|
19 | - add the device, filling out the description, hostname, SNMP community |
---|
20 | - pick the interfaces or resources to be monitored (graphed) |
---|
21 | - create the graph tree enty |
---|
22 | - add the graphs to the graph tree. |
---|
23 | |
---|
24 | There are plugins to automate this, such as the aptly named "autom8": |
---|
25 | http://docs.cacti.net/plugin:autom8 |
---|
26 | |
---|
27 | But if you wanted to add many devices in one pass, you would want to use |
---|
28 | something more efficient. |
---|
29 | |
---|
30 | Luckily, Cacti has command line tools for this: |
---|
31 | |
---|
32 | http://www.cacti.net/downloads/docs/html/scripts.html |
---|
33 | |
---|
34 | The commands provided are: |
---|
35 | |
---|
36 | add_data_query.php |
---|
37 | add_device.php |
---|
38 | add_graphs.php |
---|
39 | add_graph_template.php |
---|
40 | add_perms.php |
---|
41 | add_tree.php |
---|
42 | |
---|
43 | On Ubuntu, these are located under /usr/share/cacti/cli |
---|
44 | |
---|
45 | The three commands we'll be focusing on are: |
---|
46 | |
---|
47 | add_device.php |
---|
48 | add_graphs.php |
---|
49 | add_tree.php |
---|
50 | |
---|
51 | They are individually documented here: |
---|
52 | |
---|
53 | http://www.cacti.net/downloads/docs/html/cli_add_device.html |
---|
54 | http://www.cacti.net/downloads/docs/html/cli_add_graphs.html |
---|
55 | http://www.cacti.net/downloads/docs/html/cli_add_tree.html |
---|
56 | |
---|
57 | The way it works, is that we will use the three commands in sequence, to: |
---|
58 | |
---|
59 | - Add a device |
---|
60 | - Create graphs for the device we've added |
---|
61 | - Add these graphs to a tree |
---|
62 | |
---|
63 | Below is a walkthrough of adding a device and some graphs using these commands. |
---|
64 | Read through, and proceed to the exercise at the end. |
---|
65 | |
---|
66 | |
---|
67 | 1. Adding a device |
---|
68 | |
---|
69 | $ sudo ./add_device.php | less |
---|
70 | |
---|
71 | You will see a lot of help output. You can page through it to look at all |
---|
72 | the options. So we know what we will put for: |
---|
73 | |
---|
74 | --description => the description of the host, say "backbone router" or |
---|
75 | "rtrX.ws.nsrc.org" - but that is up to you to decide |
---|
76 | --ip => the ip or hostname - we recommend hostname! - of the device |
---|
77 | |
---|
78 | --version => SNMP version (2) |
---|
79 | --comunity => the SNMP community. By default, Cacti will try 'public', |
---|
80 | although you can pre-configure other communities in the |
---|
81 | Cacti user interface |
---|
82 | |
---|
83 | We're missing two informations: |
---|
84 | |
---|
85 | - What availability method (PING or SNMP) to check if the device is "up" ? |
---|
86 | from the options listed in the output of the command, we can see: |
---|
87 | |
---|
88 | --avail pingsnmp, [ping][none, snmp, pingsnmp] |
---|
89 | |
---|
90 | We will use the "snmp" availability test. |
---|
91 | |
---|
92 | - The Template: is it a Cisco, a Linux host, a generic SNMP device ? |
---|
93 | |
---|
94 | For this, we use the --list-host-templates command, which will tell us |
---|
95 | which type of device Template is supported: |
---|
96 | |
---|
97 | $ sudo ./add_device.php --list-host-templates |
---|
98 | |
---|
99 | Valid Host Templates: (id, name) |
---|
100 | 0 None |
---|
101 | 1 Generic SNMP-enabled Host |
---|
102 | 3 ucd/net SNMP Host |
---|
103 | 4 Karlnet Wireless Bridge |
---|
104 | 5 Cisco Router |
---|
105 | 6 Netware 4/5 Server |
---|
106 | 7 Windows 2000/XP Host |
---|
107 | 8 Local Linux Machine |
---|
108 | |
---|
109 | From the above, we can see that Cisco Router is template id number 5. |
---|
110 | |
---|
111 | Let's build our command line. If we are in group 7, we'd want to add, for |
---|
112 | example, router 7, which has IP address 10.0.7.254 and 10.10.0.7. Let's |
---|
113 | use IP 10.10.7.254 - if you have already created this device in Cacti, |
---|
114 | you may want to pick another device. |
---|
115 | |
---|
116 | $ sudo ./add_device.php --description="rtr7.ws.nsrc.org" --ip=10.10.7.254 \ |
---|
117 | --template=5 --avail=snmp --version=2 --community=NetManage |
---|
118 | |
---|
119 | You should see output similar to this: |
---|
120 | |
---|
121 | Adding rtr7.ws.nsrc.org (10.10.7.254) as "Cisco Router" using SNMP v2 with |
---|
122 | community "NetManage" |
---|
123 | Success - new device-id: (2) |
---|
124 | |
---|
125 | Note the device-id "2". This is Cacti's internal reference for this device. |
---|
126 | You don't need to write it down. |
---|
127 | |
---|
128 | Now, verify in the Web UI that the device has indeed been added: |
---|
129 | |
---|
130 | Console -> Management -> Devices |
---|
131 | |
---|
132 | |
---|
133 | 2. Adding graphs |
---|
134 | |
---|
135 | This is the most complicated part of the operation, but once you understand |
---|
136 | the steps involved, it will be easier to repeat for other hosts. |
---|
137 | |
---|
138 | First, let's run the add_graphs.php commands without any options to see what |
---|
139 | it expects from us: |
---|
140 | |
---|
141 | $ sudo ./add_graphs.php | less |
---|
142 | |
---|
143 | [...] |
---|
144 | |
---|
145 | Notice the options --host-id, --graph-type, --graph-template-id options. |
---|
146 | |
---|
147 | We already know the host-id from the previous section - if you don't remember |
---|
148 | it, don't worry, we'll get to it below. |
---|
149 | |
---|
150 | Graph type (--graph-type) is is either cg or ds. 'cg' is used for absolute |
---|
151 | values such as gauge readings (CPU temperature, fan speed, ...), while 'ds' |
---|
152 | is used for interface counters etc. (Data Sources). We are using 'ds' type |
---|
153 | graphs for interfaces (--graph-type=ds) |
---|
154 | |
---|
155 | Also pay attention in particular to the "List Options" section, as we will be |
---|
156 | using this quite a bit to find out what SNMP data we want to query: |
---|
157 | |
---|
158 | List Options: |
---|
159 | |
---|
160 | --list-hosts |
---|
161 | --list-graph-templates [--host-template-id=[ID]] |
---|
162 | --list-input-fields --graph-template-id=[ID] |
---|
163 | --list-snmp-queries |
---|
164 | --list-query-types --snmp-query-id [ID] |
---|
165 | --list-snmp-fields --host-id=[ID] [--snmp-query-id=[ID]] |
---|
166 | --list-snmp-values --host-id=[ID] [--snmp-query-id=[ID]] --snmp-field=[Field] |
---|
167 | |
---|
168 | A very useful command is the "--list-hosts" options, that we'll use to see |
---|
169 | which hosts are available, as we'll also need to get the host-id. |
---|
170 | |
---|
171 | Let's use this to fetch the host-id for the host you added in the previous |
---|
172 | section: |
---|
173 | |
---|
174 | $ sudo ./add_graphs.php --list-hosts |
---|
175 | |
---|
176 | Known Hosts: (id, hostname, template, description) |
---|
177 | 1 127.0.0.1 8 Localhost |
---|
178 | 2 10.10.7.254 5 rtr7.ws.nsrc.org |
---|
179 | |
---|
180 | In this case, the host-id of rtr7 is '2'. |
---|
181 | |
---|
182 | Is this enough to build our command ? Not yet. We still need to specify the |
---|
183 | following: |
---|
184 | |
---|
185 | "graph template id" (--graph-template-id) |
---|
186 | "snmp query id" (--snmp-query-id) |
---|
187 | "snmp field" (--snmp-field) |
---|
188 | "snmp value" (--snmp-value) |
---|
189 | |
---|
190 | * Find the graph template id |
---|
191 | |
---|
192 | To find out which graph templates are available, use the --list-graph-templates |
---|
193 | option: |
---|
194 | |
---|
195 | $ sudo ./add_graphs.php --list-graph-templates |
---|
196 | |
---|
197 | In the output, there are several options we could be interested in: |
---|
198 | |
---|
199 | [...] |
---|
200 | |
---|
201 | 2 Interface - Traffic (bits/sec) |
---|
202 | 18 Cisco - CPU Usage |
---|
203 | 22 Interface - Errors/Discards |
---|
204 | 23 Interface - Unicast Packets |
---|
205 | 24 Interface - Non-Unicast Packets |
---|
206 | 25 Interface - Traffic (bytes/sec) |
---|
207 | |
---|
208 | We're really interested in creating bits/sec graphs at this point, so that's |
---|
209 | graph template no. 2 |
---|
210 | |
---|
211 | |
---|
212 | * Find out what types of SNMP queries are possible: |
---|
213 | |
---|
214 | $ sudo ./add_graphs.php --list-snmp-queries |
---|
215 | |
---|
216 | Known SNMP Queries:(id, name) |
---|
217 | 1 SNMP - Interface Statistics |
---|
218 | 2 ucd/net - Get Monitored Partitions |
---|
219 | 3 Karlnet - Wireless Bridge Statistics |
---|
220 | 4 Netware - Get Available Volumes |
---|
221 | 6 Unix - Get Mounted Partitions |
---|
222 | 7 Netware - Get Processor Information |
---|
223 | 8 SNMP - Get Mounted Partitions |
---|
224 | 9 SNMP - Get Processor Information |
---|
225 | |
---|
226 | Here, we are interested in the SNMP Interface statistics, therefore, |
---|
227 | --snmp-query-id=1 is what we are looking for. |
---|
228 | |
---|
229 | * Find the valid SNMP query type |
---|
230 | |
---|
231 | Ok, but what kind of data do we want to graph ? Find out using the |
---|
232 | query types possible for snmp-query-type 1 (SNMP - Interface Statistics): |
---|
233 | |
---|
234 | $ sudo ./add_graphs.php --snmp-query-id=1 --list-query-types |
---|
235 | |
---|
236 | Known SNMP Query Types: (id, name) |
---|
237 | 2 In/Out Errors/Discarded Packets |
---|
238 | 3 In/Out Non-Unicast Packets |
---|
239 | 4 In/Out Unicast Packets |
---|
240 | 9 In/Out Bytes (64-bit Counters) |
---|
241 | 13 In/Out Bits |
---|
242 | 14 In/Out Bits (64-bit Counters) |
---|
243 | 16 In/Out Bytes |
---|
244 | 20 In/Out Bits with 95th Percentile |
---|
245 | 21 In/Out Bits with Total Bandwidth |
---|
246 | 22 In/Out Bytes with Total Bandwidth |
---|
247 | |
---|
248 | Let's graph Ib/Out Bits (64-bit Counters) - that is # 14. This is |
---|
249 | option "--snmp-query-type-id" |
---|
250 | |
---|
251 | * Find which interfaces to graph on this host |
---|
252 | |
---|
253 | We need to tell Cacti *which* which interfaces we will be creating |
---|
254 | graphs for on our device, using the two options of the add_graphs.php |
---|
255 | command "--snmp-field" and "--snmp-value" |
---|
256 | |
---|
257 | $ sudo ./add_graphs.php --host-id=2 --list-snmp-fields |
---|
258 | |
---|
259 | Known SNMP Fields for host-id 2: (name) |
---|
260 | ifAlias |
---|
261 | ifDescr |
---|
262 | ifHighSpeed |
---|
263 | ifHwAddr |
---|
264 | ifIndex |
---|
265 | ifIP |
---|
266 | ifName |
---|
267 | ifOperStatus |
---|
268 | ifSpeed |
---|
269 | ifType |
---|
270 | |
---|
271 | We're only really interested in interfaces of type ethernet, therefore we'll |
---|
272 | use the "ifType" SNMP field to narrow down our search. |
---|
273 | |
---|
274 | To find out how to specify the "ethernet" type...: |
---|
275 | |
---|
276 | $ sudo ./add_graphs.php --host-id=2 --snmp-field=ifType --list-snmp-values |
---|
277 | |
---|
278 | Known values for ifType for host 3: (name) |
---|
279 | ethernetCsmacd(6) |
---|
280 | other(1) |
---|
281 | |
---|
282 | ethernet is 'ethernetCsmacd(6)' |
---|
283 | |
---|
284 | Wow! |
---|
285 | |
---|
286 | The final command: |
---|
287 | |
---|
288 | $ sudo ./add_graphs.php --host-id=2 --snmp-query-id=1 --snmp-query-type-id=14 \ |
---|
289 | --snmp-field=ifType --snmp-value='ethernetCsmacd(6)' --graph-template-id=2 \ |
---|
290 | --graph-type=ds |
---|
291 | |
---|
292 | You should see something similar to this: |
---|
293 | |
---|
294 | Graph Added - graph-id: (5) - data-source-ids: (8, 8) |
---|
295 | Graph Added - graph-id: (6) - data-source-ids: (9, 9) |
---|
296 | |
---|
297 | ... why two Graphs ? One for each interface if this is your Cisco router. |
---|
298 | |
---|
299 | Check in the Web UI that the graphs have been create (Devices -> select |
---|
300 | your host -> Graph List) |
---|
301 | |
---|
302 | * NOTE: We could have picked another criteria to decide which interfaces |
---|
303 | to graph. For example "Only graph interfaces that are 'up'". To find out |
---|
304 | how, look at the examples at the end of this lab. |
---|
305 | |
---|
306 | 3. Add graph items to the tree |
---|
307 | |
---|
308 | The last step is to add these graphs to the Graph Tree. |
---|
309 | |
---|
310 | Check the possible options for this command: |
---|
311 | |
---|
312 | $ sudo ./add_tree.php | less |
---|
313 | |
---|
314 | Note the following options: |
---|
315 | |
---|
316 | --type=[tree|node] |
---|
317 | --node-type=[header|host|graph] |
---|
318 | --tree-id=[ID] |
---|
319 | |
---|
320 | First, let's use the add_tree.php command to see if we have any trees created |
---|
321 | in our Cacti installation: |
---|
322 | |
---|
323 | $ sudo ./add_tree.php --list-trees |
---|
324 | |
---|
325 | Known Trees: |
---|
326 | id sort method name |
---|
327 | 1 Manual Ordering (No Sorting) Default Tree |
---|
328 | |
---|
329 | In the above example, we have one tree: Default. |
---|
330 | |
---|
331 | If you need to create a new tree, save some typing and create it directly in |
---|
332 | the Web UI, then run the --list-trees command again: |
---|
333 | |
---|
334 | $ sudo ./add_tree.php --list-trees |
---|
335 | |
---|
336 | Known Trees: |
---|
337 | id sort method name |
---|
338 | 1 Manual Ordering (No Sorting) Default Tree |
---|
339 | 2 Manual Ordering (No Sorting) NETMGMT routers |
---|
340 | |
---|
341 | Note: We could have created the tree using add_tree.php. How ? |
---|
342 | |
---|
343 | Let's add all graphs for our device id 2 from earlier - we know that |
---|
344 | the device id is 2, the tree id is 2, we want to add a Graph node (not |
---|
345 | a subtree), and we want all graphs for the device (type = node), not |
---|
346 | just a single graph from that device. |
---|
347 | |
---|
348 | The final command: |
---|
349 | |
---|
350 | $ sudo ./add_tree.php --host-id=2 --tree-id=2 --node-type=host --type=node |
---|
351 | |
---|
352 | Added Node node-id: (8) |
---|
353 | |
---|
354 | Done! Check with the Web UI that the Graphs for the device hav been placed |
---|
355 | in the tree. |
---|
356 | |
---|
357 | * Additional commands |
---|
358 | |
---|
359 | If you want to add interfaces that are 'Up' instead of just interfaces that |
---|
360 | are "ethernet", replace "ifType" with "ifOperStatus" for --snmp-field, and |
---|
361 | replace --snmp-value='ethernetCsmacd(6)' with --snmp-value=Up |
---|
362 | |
---|
363 | Example to add all OperUp interfaces: |
---|
364 | |
---|
365 | ./add_graphs.php --host-id=7 --graph-type=ds --graph-template-id=2 |
---|
366 | --snmp-query-id=1 --snmp-query-type-id=14 --snmp-field=ifOperStatus \ |
---|
367 | --snmp-value=Up |
---|
368 | |
---|
369 | * Summary and more sample commands |
---|
370 | |
---|
371 | $ sudo ./add_graphs.php --list-hosts |
---|
372 | # choose your host ID from the list |
---|
373 | |
---|
374 | $ sudo ./add_graphs.php --list-graph-templates |
---|
375 | # 2 = Interface - Traffic (bits/sec) |
---|
376 | |
---|
377 | $ sudo ./add_graphs.php --list-snmp-queries |
---|
378 | # 1 = SNMP - Interface Statistics |
---|
379 | |
---|
380 | $ sudo ./add_graphs.php --list-query-types --snmp-query-id=1 |
---|
381 | # 14 = In/Out Bits (64-bit Counters) |
---|
382 | |
---|
383 | $ sudo ./add_graphs.php --list-snmp-fields --host-id=2 --snmp-query-id=1 |
---|
384 | # list includes ifType |
---|
385 | |
---|
386 | ### Add all ifs of type ethernetCsmaCd (type 6) ### |
---|
387 | |
---|
388 | $ sudo ./add_graphs.php --list-snmp-values --host-id=2 --snmp-query-id=1 \ |
---|
389 | --snmp-field=ifType |
---|
390 | # Known values for ifType for host 2: (name) |
---|
391 | # ethernetCsmacd(6) |
---|
392 | # other(1) |
---|
393 | |
---|
394 | $ sudo ./add_graphs.php --host-id=2 --graph-type=ds --graph-template-id=2 \ |
---|
395 | --snmp-query-id=1 --snmp-query-type-id=14 --snmp-field=ifType \ |
---|
396 | --snmp-value='ethernetCsmacd(6)' |
---|
397 | |
---|
398 | or |
---|
399 | |
---|
400 | ### Add all OperUp ifs: ### |
---|
401 | |
---|
402 | $ sudo ./add_graphs.php --list-snmp-values --host-id=2 --snmp-query-id=1 \ |
---|
403 | --snmp-field=ifOperStatus |
---|
404 | # Known values for ifOperStatus for host 2: (name) |
---|
405 | # Down |
---|
406 | # Up |
---|
407 | |
---|
408 | $ sudo ./add_graphs.php --host-id=2 --graph-type=ds --graph-template-id=2 \ |
---|
409 | --snmp-query-id=1 --snmp-query-type-id=14 --snmp-field=ifOperStatus \ |
---|
410 | --snmp-value=Up |
---|