How to move a branch from one tree to another ?
Moderators: Developers, Moderators
How to move a branch from one tree to another ?
Hello,
I have created 3 trees and have a few branches in the 3 trees (with sub nodes, graphs)
I would like to move (or copy) , a few branches from one tree to another ; and also to place a node from the second level of a tree to the first level of this tree.
I have read the command 'add-tree.php', but I think, it's only to add a new node, graph, device and not also to do a copy.
Is there a solution, because, to delete each item of the branch (with the red cross) and to add again in the other tree takes long time.
Thanks
Cacti : 0.8.7.b
OS : windows server 2003
I have created 3 trees and have a few branches in the 3 trees (with sub nodes, graphs)
I would like to move (or copy) , a few branches from one tree to another ; and also to place a node from the second level of a tree to the first level of this tree.
I have read the command 'add-tree.php', but I think, it's only to add a new node, graph, device and not also to do a copy.
Is there a solution, because, to delete each item of the branch (with the red cross) and to add again in the other tree takes long time.
Thanks
Cacti : 0.8.7.b
OS : windows server 2003
Re: How to move a branch from one tree to another ?
General question, moving.
There is not a way to move tree's around currently.Dom... wrote:I would like to move (or copy) , a few branches from one tree to another ;
You should be able to add a host/graph from anything to any level of a Tree (i.e. root or node).Dom... wrote:and also to place a node from the second level of a tree to the first level of this tree.
| Scripts: Monitor processes | RFC1213 MIB | DOCSIS Stats | Dell PowerEdge | Speedfan | APC UPS | DOCSIS CMTS | 3ware | Motorola Canopy |
| Guides: Windows Install | [HOWTO] Debug Windows NTFS permission problems |
| Tools: Windows All-in-one Installer |
- gandalf
- Developer
- Posts: 22383
- Joined: Thu Dec 02, 2004 2:46 am
- Location: Muenster, Germany
- Contact:
Are you talking about "tables" when talking about "files"? Surely it would be able to add a sorting feature for trees, and you may provide code if possible. But I'm quite sure it will at least require a db change (for the sorting option)Dom... wrote:in the database cacti, there are a few files about the graph trees, is it posssible to edit some files
Reinhard
If you have some tool like phpMysql it is possible to move tree items between trees quite easily by editing database records directly.
You can update the graph_tree_id in the graph_tree_items table to move graph items to another tree, and then you must use the web UI to rearrange items within the new tree.
Note that this will mess up ordering in the new tree but you could overcome this if you understood and editted the order key field (which I don't, but I guess the schema explains this)
e.g.
update `graph_tree_items` set `graph_tree_id` = 42 WHERE `graph_tree_id` = 30
I have never needed to copy items, I guess it would be possible.
You can update the graph_tree_id in the graph_tree_items table to move graph items to another tree, and then you must use the web UI to rearrange items within the new tree.
Note that this will mess up ordering in the new tree but you could overcome this if you understood and editted the order key field (which I don't, but I guess the schema explains this)
e.g.
update `graph_tree_items` set `graph_tree_id` = 42 WHERE `graph_tree_id` = 30
I have never needed to copy items, I guess it would be possible.
[url=http://www.welham.net/]Steve W[/url]
I revisited this today and came up with a way of moving graph trees around. This method requires some serious hacking about in the database but does allow you to move stuff between top-level graph trees without needing to recreate the graph tree.
Of course once you have graph_tree items in a common top-level tree it is really easy to move them about using the UI.
BE WARNED - YOU COULD REALLY MESS UP YOUR DATABASE SO DO SOME TEST RUNS FIRST ON A TEST SERVER AND BACKUP YOUR DATABASE.
The SQL to move an entire top-level graph tree "A" into a sub tree "Z.S" below top-level graph tree "Z" is as follows:
I did it as follows:
1) Create a new sub tree (tree header object) Z.S in the destination tree Z. Make sure it's empty of child items.
2) Fire up phpMyAdmin
3) In phpMyAdmin, browse to the graph_tree table and locate the id for the source tree (A-tree-id) and the destination tree (B-tree-id)
4) In phpMyAdmin, run the following SQL query to browse the graph_tree_item table in a nicer fashion:
You need to identify the order_key prefix for your newly created header item Z.S. This will be something like 001 for the first header, 002 for the second etc.
Note how the hierarchy works:
- The 1st second level header under the 1st first level header will be 001001
- The 4th third level header under the above will be 001001004 etc etc
Once you have derived the prefix you can run the update statement. So to move everything in tree 12 to tree 16 header 002 you would run:
Similarly to move everything in tree 19 into tree 42 header 001003
This saved me a bunch of time moving about 500 graph items, but it has potential to be quite dangerous so be warned!
Of course once you have graph_tree items in a common top-level tree it is really easy to move them about using the UI.
BE WARNED - YOU COULD REALLY MESS UP YOUR DATABASE SO DO SOME TEST RUNS FIRST ON A TEST SERVER AND BACKUP YOUR DATABASE.
The SQL to move an entire top-level graph tree "A" into a sub tree "Z.S" below top-level graph tree "Z" is as follows:
Code: Select all
UPDATE `graph_tree_items` SET graph_tree_id = 'Z-tree-id',
`order_key` = concat("Z.S-order_key_prefix",left(order_key,length(order_key)-Z.S-order_key_prefix_length)) WHERE `graph_tree_id` = A-tree-id;
1) Create a new sub tree (tree header object) Z.S in the destination tree Z. Make sure it's empty of child items.
2) Fire up phpMyAdmin
3) In phpMyAdmin, browse to the graph_tree table and locate the id for the source tree (A-tree-id) and the destination tree (B-tree-id)
4) In phpMyAdmin, run the following SQL query to browse the graph_tree_item table in a nicer fashion:
Code: Select all
select graph_tree.name N, G.order_key, G.title, host1.hostname, host2.hostname, graph_templates.name, G.*
from graph_tree_items G
left join host AS host1 on host1.id=G.host_id
left join graph_tree on graph_tree.id=G.graph_tree_id
left join graph_local on graph_local.id=G.local_graph_id
left join host AS host2 on host2.id=graph_local.host_id
left join graph_templates on graph_templates.id=graph_local.graph_template_id
order by N,G.order_key
LIMIT 0, 600
Note how the hierarchy works:
- The 1st second level header under the 1st first level header will be 001001
- The 4th third level header under the above will be 001001004 etc etc
Once you have derived the prefix you can run the update statement. So to move everything in tree 12 to tree 16 header 002 you would run:
Code: Select all
UPDATE `graph_tree_items` SET graph_tree_id = '16',
`order_key` = concat("002",left(order_key,length(order_key)-3)) WHERE `graph_tree_id` = 12;
Code: Select all
UPDATE `graph_tree_items` SET graph_tree_id = '42',
`order_key` = concat("001003",left(order_key,length(order_key)-6)) WHERE `graph_tree_id` = 19;
[url=http://www.welham.net/]Steve W[/url]
Who is online
Users browsing this forum: No registered users and 1 guest