Agenda: cacti-cli-commands.txt

File cacti-cli-commands.txt, 12.0 KB (added by b.candler, 6 years ago)
Line 
1Network Management and Monitoring
2
3Cacti command line tools
4========================
5
6Notes:
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
16As you have noticed, adding devices to Cacti via the user interface can take
17quite 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
24There are plugins to automate this, such as the aptly named "autom8":
25http://docs.cacti.net/plugin:autom8
26
27But if you wanted to add many devices in one pass, you would want to use
28something more efficient.
29
30Luckily, Cacti has command line tools for this:
31
32http://www.cacti.net/downloads/docs/html/scripts.html
33
34The commands provided are:
35
36add_data_query.php
37add_device.php
38add_graphs.php
39add_graph_template.php
40add_perms.php
41add_tree.php
42
43On Ubuntu, these are located under /usr/share/cacti/cli
44
45The three commands we'll be focusing on are:
46
47add_device.php
48add_graphs.php
49add_tree.php
50
51They are individually documented here:
52
53http://www.cacti.net/downloads/docs/html/cli_add_device.html
54http://www.cacti.net/downloads/docs/html/cli_add_graphs.html
55http://www.cacti.net/downloads/docs/html/cli_add_tree.html
56
57The 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
63Below is a walkthrough of adding a device and some graphs using these commands.
64Read through, and proceed to the exercise at the end.
65
66
671. Adding a device
68
69$ sudo ./add_device.php | less
70
71You will see a lot of help output. You can page through it to look at all
72the 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
83We'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
99Valid Host Templates: (id, name)
1000   None
1011   Generic SNMP-enabled Host
1023   ucd/net SNMP Host
1034   Karlnet Wireless Bridge
1045   Cisco Router
1056   Netware 4/5 Server
1067   Windows 2000/XP Host
1078   Local Linux Machine
108
109From the above, we can see that Cisco Router is template id number 5.
110
111Let's build our command line. If we are in group 7, we'd want to add, for
112example, router 7, which has IP address 10.0.7.254 and 10.10.0.7. Let's
113use IP 10.10.7.254 - if you have already created this device in Cacti,
114you 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
119You 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
125Note the device-id "2". This is Cacti's internal reference for this device.
126You don't need to write it down.
127
128Now, verify in the Web UI that the device has indeed been added:
129
130Console -> Management -> Devices
131
132
1332. Adding graphs
134
135This is the most complicated part of the operation, but once you understand
136the steps involved, it will be easier to repeat for other hosts.
137
138First, let's run the add_graphs.php commands without any options to see what
139it expects from us:
140
141$ sudo ./add_graphs.php | less
142
143[...]
144
145Notice the options --host-id, --graph-type, --graph-template-id options.
146
147We already know the host-id from the previous section - if you don't remember
148it, don't worry, we'll get to it below.
149
150Graph type (--graph-type) is is either cg or ds. 'cg' is used for absolute
151values such as gauge readings (CPU temperature, fan speed, ...), while 'ds'
152is used for interface counters etc. (Data Sources). We are using 'ds' type
153graphs for interfaces (--graph-type=ds)
154
155Also pay attention in particular to the "List Options" section, as we will be
156using this quite a bit to find out what SNMP data we want to query:
157
158List 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
168A very useful command is the "--list-hosts" options, that we'll use to see
169which hosts are available, as we'll also need to get the host-id.
170
171Let's use this to fetch the host-id for the host you added in the previous
172section:
173
174$ sudo ./add_graphs.php --list-hosts
175
176Known Hosts: (id, hostname, template, description)
1771   127.0.0.1   8   Localhost
1782   10.10.7.254 5   rtr7.ws.nsrc.org
179
180In this case, the host-id of rtr7 is '2'.
181
182Is this enough to build our command ?  Not yet. We still need to specify the
183following:
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
192To find out which graph templates are available, use the --list-graph-templates
193option:
194
195$ sudo ./add_graphs.php --list-graph-templates
196
197In the output, there are several options we could be interested in:
198
199[...]
200
2012   Interface - Traffic (bits/sec)
20218  Cisco - CPU Usage
20322  Interface - Errors/Discards
20423  Interface - Unicast Packets
20524  Interface - Non-Unicast Packets
20625  Interface - Traffic (bytes/sec)
207
208We're really interested in creating bits/sec graphs at this point, so that's
209graph 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
216Known SNMP Queries:(id, name)
2171   SNMP - Interface Statistics
2182   ucd/net -  Get Monitored Partitions
2193   Karlnet - Wireless Bridge Statistics
2204   Netware - Get Available Volumes
2216   Unix - Get Mounted Partitions
2227   Netware - Get Processor Information
2238   SNMP - Get Mounted Partitions
2249   SNMP - Get Processor Information
225
226Here, 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
231Ok, but what kind of data do we want to graph ? Find out using the
232query types possible for snmp-query-type 1 (SNMP - Interface Statistics):
233
234$ sudo ./add_graphs.php --snmp-query-id=1 --list-query-types
235
236Known SNMP Query Types: (id, name)
2372   In/Out Errors/Discarded Packets
2383   In/Out Non-Unicast Packets
2394   In/Out Unicast Packets
2409   In/Out Bytes (64-bit Counters)
24113  In/Out Bits
24214  In/Out Bits (64-bit Counters)
24316  In/Out Bytes
24420  In/Out Bits with 95th Percentile
24521  In/Out Bits with Total Bandwidth
24622  In/Out Bytes with Total Bandwidth
247
248Let's graph Ib/Out Bits (64-bit Counters) - that is # 14. This is
249option "--snmp-query-type-id"
250
251* Find which interfaces to graph on this host
252
253We need to tell Cacti *which* which interfaces we will be creating
254graphs for on our device, using the two options of the add_graphs.php
255command "--snmp-field" and "--snmp-value"
256
257$ sudo ./add_graphs.php --host-id=2 --list-snmp-fields
258
259Known SNMP Fields for host-id 2: (name)
260ifAlias
261ifDescr
262ifHighSpeed
263ifHwAddr
264ifIndex
265ifIP
266ifName
267ifOperStatus
268ifSpeed
269ifType
270
271We're only really interested in interfaces of type ethernet, therefore we'll
272use the "ifType" SNMP field to narrow down our search.
273
274To find out how to specify the "ethernet" type...:
275
276$ sudo ./add_graphs.php --host-id=2 --snmp-field=ifType --list-snmp-values
277
278Known values for ifType for host 3: (name)
279ethernetCsmacd(6)
280other(1)
281
282ethernet is 'ethernetCsmacd(6)'
283
284Wow!
285
286The 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
292You should see something similar to this:
293
294Graph Added - graph-id: (5) - data-source-ids: (8, 8)
295Graph 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
299Check in the Web UI that the graphs have been create (Devices -> select
300your 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
3063. Add graph items to the tree
307
308The last step is to add these graphs to the Graph Tree.
309
310Check the possible options for this command:
311
312$ sudo ./add_tree.php | less
313
314Note the following options:
315
316--type=[tree|node]
317--node-type=[header|host|graph]
318--tree-id=[ID]
319
320First, let's use the add_tree.php command to see if we have any trees created
321in our Cacti installation:
322
323$ sudo ./add_tree.php --list-trees
324
325Known Trees:
326id  sort method         name
3271   Manual Ordering (No Sorting)    Default Tree
328
329In the above example, we have one tree: Default.
330
331If you need to create a new tree, save some typing and create it directly in
332the Web UI, then run the --list-trees command again:
333
334$ sudo ./add_tree.php --list-trees
335
336Known Trees:
337id  sort method         name
3381   Manual Ordering (No Sorting)    Default Tree
3392   Manual Ordering (No Sorting)    NETMGMT routers
340
341Note: We could have created the tree using add_tree.php. How ?
342
343Let's add all graphs for our device id 2 from earlier - we know that
344the device id is 2, the tree id is 2, we want to add a Graph node (not
345a subtree), and we want all graphs for the device (type = node), not
346just a single graph from that device.
347
348The final command:
349
350$ sudo ./add_tree.php --host-id=2 --tree-id=2 --node-type=host --type=node
351
352Added Node node-id: (8)
353
354Done! Check with the Web UI that the Graphs for the device hav been placed
355in the tree.
356
357* Additional commands
358
359If you want to add interfaces that are 'Up' instead of just interfaces that
360are "ethernet", replace "ifType" with "ifOperStatus" for --snmp-field, and
361replace --snmp-value='ethernetCsmacd(6)' with --snmp-value=Up
362
363Example 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
398or
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