Cacti (home)ForumsRepositoryDocumentation
Cacti: offical forums and support
It is currently Fri Oct 31, 2014 6:31 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Add-on: Using data input field in graph title
PostPosted: Fri May 20, 2011 3:34 am 
Offline
Cacti Guru User

Joined: Thu Aug 05, 2010 2:04 am
Posts: 1573
Location: Japan
Some users (and me) wanted to use "|query_xxxx|" from datasource in graph title,
but this feature is limited to datasources that used Data Queries, not for Data Input Method.
See also: get param passed to an script

So I've tried implementing that.

How to use
1) Place 'addon_data_input_field.php' at 'cacti/lib/' directory
Attachment:
addon_data_input_field.zip [1.35 KiB]
Downloaded 303 times

2) Modify get_graph_title() in 'cacti/lib/functions.php' as follows:
Code:
function get_graph_title($local_graph_id) {
+       global $config;
+       include_once($config["library_path"] . "/addon_data_input_field.php");

        $graph = db_fetch_row("select
                graph_local.host_id,
                graph_local.snmp_query_id,
                graph_local.snmp_index,
                graph_templates_graph.title
                from (graph_templates_graph,graph_local)
                where graph_templates_graph.local_graph_id=graph_local.id
                and graph_local.id=$local_graph_id");

        if ((strstr($graph["title"], "|")) && (!empty($graph["host_id"]))) {
+               $graph["title"] = substitute_data_input_field($graph["title"], $graph["host_id"], $local_graph_id);
                return expand_title($graph["host_id"], $graph["snmp_query_id"], $graph["snmp_index"], $graph["title"]);
        }else{
                return $graph["title"];
        }
}


Sample case - Advanced Ping Template
Input fields of this Data Input Method is as follows:
Image

And here is my datasource.
Image

Then I set title like this in graph template.
Image
before:
Quote:
|host_description| - Advanced Ping
after:
Quote:
Advanced Ping - from |host_hostname| to |input_hostname| (attempts=|input_attempts|, protocol=|input_protocol|)

Result is...
Image
(Please ignore about packet loss :P)

If the changes won't be applied immediately (like this),
Image
perform "Reapply Suggested Names" to the graph.

NOTICE:
- I'm using on Cacti 0.8.7g + official patch + PA2.9
- I made this mainly for Advanced Ping, not enough tested with other templates
(e.g. a graph that is related with multiple rrd file which is made by Data Input Method)
- The changes won't be applied when the device is down
- I'm not sure whether if this will work properly (or not) when the multiple input fields with the same name existed in same datasource
(e.g. aggregated graph?)


Logic
It needed to determine "what datasources are used in this graph"..
(Does anyone know easier method for that?)

I tried this way:
1) determine what graph template is used in its graph
2) determine what data (output) field is used in its graph template
(collect field which has "Data Source" type in "Graph Item Inputs")
3) determine what datasource has its field (= what datasource is used for its graph)
4) if data input id and data template id which used in its datasource are known, then retrieve data input fields from its datasource

// Sorry my English


Top
 Profile  
 
 Post subject: Re: Add-on: Using data input field in graph title
PostPosted: Sun May 22, 2011 10:20 am 
Offline
Developer
User avatar

Joined: Thu Dec 02, 2004 2:46 am
Posts: 22461
Location: Muenster, Germany
That looks fine.
Please open a bug report and attach all resources there. This ensures, that we will implement this (whenever we find time)
R.

_________________
Official Cacti Documentation
Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
 Post subject: Re: Add-on: Using data input field in graph title
PostPosted: Mon May 23, 2011 12:22 am 
Offline
Cacti Guru User

Joined: Thu Aug 05, 2010 2:04 am
Posts: 1573
Location: Japan
Thanks gandalf!
I'll do so with pleasure. (^-^/
http://bugs.cacti.net/view.php?id=1996


Top
 Profile  
 
 Post subject: Re: Add-on: Using data input field in graph title
PostPosted: Thu May 26, 2011 3:31 pm 
Offline

Joined: Tue Oct 28, 2008 1:50 pm
Posts: 9
Great .. I now also use it for the Advanced Ping as displayed above.

Hope to see this option in the next release of Cacti. :-)

Great job, thanks

Matthijs


Top
 Profile  
 
 Post subject: Re: Add-on: Using data input field in graph title
PostPosted: Thu Jun 16, 2011 11:12 am 
Offline
Developer
User avatar

Joined: Tue May 14, 2002 5:08 pm
Posts: 14862
Location: MI, USA
This was already 99.9% implemented in 0.8.7h, but we left off the title_cache part of this. Being voted on now. If you look at SVN under branches/0.8.7/lib/variables.php, you will see the function already written.

TheWitness

_________________
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of MacTrack, Boost, CLog, SpikeKill, Platform RTM, DSStats, maintainer of Spine, lot's of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
Gandalfs Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
 Post subject: Re: Add-on: Using data input field in graph title
PostPosted: Mon Jun 27, 2011 3:02 am 
Offline
Cacti Guru User

Joined: Thu Aug 05, 2010 2:04 am
Posts: 1573
Location: Japan
TheWitness wrote:
This was already 99.9% implemented in 0.8.7h, but we left off the title_cache part of this. Being voted on now. If you look at SVN under branches/0.8.7/lib/variables.php, you will see the function already written.

Sorry for late response, I've looked into new code in SVN.

"title_cache" (actual title of graph to be shown) seems to be updated,
- when performed "Reapply Suggested Names"
- when added new graph
- when saved graph template
- when saved device settings (?)

And "name_cache" (actual name of datasource to be shown) is also updated by similar logic.

I think this is sufficient to update title/name.


BTW,
3 substituting features (|host_xxxx|, |snmp_xxxx|, |input_xxxx|) are integrated in one function (rrd_substitute_host_query_data) now,
that's wonderful. :)

// Sorry my English


Top
 Profile  
 
 Post subject: Re: Add-on: Using data input field in graph title
PostPosted: Sun Nov 20, 2011 8:49 pm 
Offline

Joined: Sun Nov 20, 2011 8:45 pm
Posts: 25
Any idea when this will be implemented in the releases?
Haven't found the end implementation in SVN code yet.

Because we really need it I've implemented it by hand in the code.

Thanks.


Top
 Profile  
 
 Post subject: Re: Add-on: Using data input field in graph title
PostPosted: Tue Jan 10, 2012 2:28 pm 
Offline

Joined: Thu Jan 05, 2012 12:03 pm
Posts: 2
Has it been implemented in 0.8.7i or not? Bit confusion if you ask me...


Top
 Profile  
 
 Post subject: Re: Add-on: Using data input field in graph title
PostPosted: Tue Jan 10, 2012 9:02 pm 
Offline
Cacti Guru User

Joined: Thu Aug 05, 2010 2:04 am
Posts: 1573
Location: Japan
>> Has it been implemented in 0.8.7i or not?

Yes, it works in Cacti 0.8.7i.
And now, besides graph title, it seems available at some other graph elements (e.g. graph legend, COMMENT).

Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group