Adding Tree Item Type

Anything that you think should be in Cacti.

Moderators: Developers, Moderators

Post Reply
Leddy
Cacti User
Posts: 93
Joined: Sun May 15, 2005 6:55 pm

Adding Tree Item Type

Post by Leddy »

Has anyone considered the possibility of adding a 4th TREE_ITEM_TYPE?

It would be nice to be able to add a "Picture" somewhere in the tree i.e. our company logo on the "[root]"
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Move to Feature Request
Reinhard
Leddy
Cacti User
Posts: 93
Joined: Sun May 15, 2005 6:55 pm

Post by Leddy »

I've done some digging today and made a few changes.

I've added TREE_ITEM_TYPE_LINK and TREE_ITEM_TYPE_PICTURE

After looking at html_tree.php I see that cacti is determing the type based on the following information:

Graph: local_graph_id > 0
Header: title != ""
Host: host_id > 0

It doesn't seem like this structure is condusive to additional types. How about adding a type_id that mirrors the TREE_ITEM_TYPE constants?

I'd be more than happy to discuss this with someone if they are available.
Leddy
Cacti User
Posts: 93
Joined: Sun May 15, 2005 6:55 pm

Post by Leddy »

Bueller, Bueller, anyone alive?

Well I've made a few changes to the graph_tree_items schema to allow new types. I've modified the Graph Tree to reflect the new types.

Next is modifying the display process. Maybe one of the devs will have some interest in this :)
Attachments
tree.JPG
tree.JPG (44.01 KiB) Viewed 5221 times
tree_add.JPG
tree_add.JPG (28.96 KiB) Viewed 5221 times
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Post by Howie »

Leddy wrote:Bueller, Bueller, anyone alive?

Well I've made a few changes to the graph_tree_items schema to allow new types. I've modified the Graph Tree to reflect the new types.

Next is modifying the display process. Maybe one of the devs will have some interest in this :)
I had some interest in this too, but I haven't had any time to look at it. I wanted to add a few new 'base types' (file/document, image, link) like you and also some kind of hook so that plugins can supply content (weathermaps, reports, subset of thresholds etc).

My plan was to take another look once 0.8.7 is out, partly because I should have finished messing with weathermap 0.93 by then too.
Weathermap 0.98a is out! & QuickTree 1.0. Superlinks is over there now (and built-in to Cacti 1.x).
Some Other Cacti tweaks, including strip-graphs, icons and snmp/netflow stuff.
(Let me know if you have UK DevOps or Network Ops opportunities, too!)
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Leddy wrote:Well I've made a few changes to the graph_tree_items schema to allow new types. I've modified the Graph Tree to reflect the new types.

Next is modifying the display process. Maybe one of the devs will have some interest in this :)
You may want to share your code following the procedure at http://www.cacti.net/bugs.php
Reinhard
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Post by Howie »

Just a quick note to say that I'm working on this again. My version adds four new fields to the graph_tree_items table, but does allow plugins to supply new data types - my test case is to have weathermap supply a new map type, plus a couple of small built-in types for images and text chunks. Link would be another good one :-) didn't think of that.

Since I wrote some notes, here they are...

Code: Select all

Files touched so far:  include/global_arrays.php
                       lib/html_tree.php
                       tree.php
                       graph_view.php

Move away from implicit to explicit type id, and using generic fields for the
new types. Type IDs are already defined for the existing types in
global_constants.php

Assumes item_type=0 will never exist.

All new type IDs will be >= 10

update graph_tree_items set item_type=1 where title <> '';
update graph_tree_items set item_type=2 where local_graph_id > 0;
update graph_tree_items set item_type=3 where host_id > 0;

4 New fields in database:

  `item_type` smallint(5) unsigned NOT NULL default '0',
  `item_id` int(16) unsigned NOT NULL default '0',
  `item_options` int(16) unsigned NOT NULL default '0',
  `item_name` varchar(255) NOT NULL,

  item_type: from 10 onwards for new items. 1,2,3 for existing ones.
  item_id: a type-specific unique ID for that instance (e.g. map id, local_graph_id)
  item_options: any display options specific to that type (e.g. rra_id, font-size, thumbnail view)
  item_name: a cached name for the item, so that we don't need to do so many database hits to show
     a list. The existing code uses left joins, but that can't really scale to many types.

Ultimately the existing local_graph_id, rra_id, title and host_id could go
away, but that would leave another place to 'reapply names', unless there's a
nice way to do that in the background at appropriate times.

Plugin should add a new line to tree_item_types[] with a short description
(this appears in the combo box for adding new items, and also in the tree
editing view).  Plugin should then add a row to tree_item_handlers (new array)
with a list of function names to provide the functionality for that type:
  render: actually draws the item into a tree
  edit: prints the type-specific part of the item editing/adding form
  name: returns a string name for use in the tree edit, and the tree itself

Weathermap is the test case. May also 're-implement' the 3 existing ones in the
same style, so tree code is generic.
Weathermap 0.98a is out! & QuickTree 1.0. Superlinks is over there now (and built-in to Cacti 1.x).
Some Other Cacti tweaks, including strip-graphs, icons and snmp/netflow stuff.
(Let me know if you have UK DevOps or Network Ops opportunities, too!)
ghoz
Posts: 4
Joined: Wed Aug 29, 2007 5:49 am

Post by ghoz »

Hi.

I almost finished adding a new graph_tree_type (graph_template) to cacti. I think i've covered almost all parts of code requiring change.

My code is far less generic than yours, so rather than continuing an uphill battle with spagetti code, i'd like to know what is the status on that thing...

fyi, I had changes all over the place...
the following files/functions had to be changed (so you don't miss one ;-) :

add tree_item_type constants :

Code: Select all

	include/global_arrays.php
	include/global_constants.php

change api_tree_item_save :

Code: Select all

	cli/add_tree.php
	graphs.php 
	host.php
	lib/api_automation_tools.php 
	lib/api_tree.php
tree managment

Code: Select all

	lib/html_tree.php (grow_graph_tree, grow_edit_graph_tree, create_dhtml_tree, grow_right_pane_tree)
	lib/tree.php 	(get_tree_item_type)
	tree.php	(form_save, item_edit item_remove)
and i have not touched at the tree exports...


Ghoz
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests