Hi all,
I've created some scripts to compliment the add_device.php and together they can all be used to create graphs, plug the graphs into a tree, and assign permissions etc.
I changed the original add_device.php (posted above) so that it outputs the new device ID/Host ID which can then be captured and used to add graphs to that host. If the added device already exists, then it outputs the existing host/device ID instead so as to avoid duplicates.
Likewise, the add_graphs.php outputs the graph-id so that it can be used to add it to a tree, or to assign permissions etc.
Usage for each of the scripts are documented either within each script or if you run it with no parameters. I've successfully used these scripts to automatically add the graphs for over 2500 interfaces (the company I work for, Synetrix, manage a metropolitan-area network for all the schools in London) and to plug them into various trees, each of which have various access rights depending on the user.
The most complex script is the add_graphs.php:
To add a graph of Interface Traffic, you need to know the following in advance:
* The Host ID (I parse it from the output of add_graph.php)
use --list-hosts to see a list of them
* The Graph Template ID (I note these via the front-end and mostly use the same ones)
use --list-graph-templates to see a list of them
* The SNMP Query ID - I use "SNMP - Interface Statistics" which is ID '1' on my system
use --list-snmp-queries to see a list of them
* The SNMP Query Type ID - I use "In/Out Bits (64-bit Counters)" - ID '14' on my system
use --snmp-query-id 1 --list-query-types to see a list of them
* The SNMP Field name that you want to use to identify the interface on the host
(I use 'ifIndex' on my system, but you can use 'ifAlias' or 'ifDescr' too)
use --host-id [ID] --list-snmp-fields to see a list of them
* The SNMP Value that that you want to use to identify the interface on the host
If you use an SNMP field name of 'ifIndex' then the SNMP Value is the index number
of the interface that you want to graph.
Once you have the above info, you can add a graph by running:
Code:
./add_graphs.php --graph-type ds --graph-template-id 2 --host-id [ID] --snmp-query-id 1 --snmp-query-type-id 14 --snmp-field ifIndex --snmp-value 1
The above command would add a graph of interface 1 on the host-ID specified.
It would also output the graphi-ID that it created, and also the RRA ID.
To add this graph to a tree, you can create/get the ID of the tree using:
Code:
./add_tree.php --type tree --name 'Tree Name' --sort-method a
(Outputs the Tree ID)
To then create a sub-node in this tree, use:
Code:
./add_tree.php --type node --node-type header --tree-ID [TREE ID] --parent-node 0 --name 'Node Name'
Outputs the node ID
To then add the graph to the node in that we just created, run:
Code:
./add_tree.php --type node --node-type graph --tree-id [TREE ID] --parent-node [NODE ID] --graph-id [ID] --rra-id [RRA ID]
Outputs the graph node ID
The graph-ID and RRA ID are output from the add_graphs.php script.
To add permissions to the graph ID created, you can use the add_perms.php:
Code:
./add_perms.php --user-id [USER ID] --item-type graph --item-id [GRAPH ID]
To add permissions to the tree, you can use the following:
Code:
./add_perms.php --user-id [USER ID] --item-type tree --item-id [TREE ID]
Unzip the files into your cacti directory (don't worry they have built-in protection against being run by the web-server).
All scripts are smart enough not to add duplicates, but instead to just return the ID's of the existing things in the databases so that they can be used for other operations.
Also, this is the first thing I've ever coded in php, so feedback is would be welcome!!!
Regards
Bradley Kite
(Attachment removed - see post below)