Add-on: Using data input field in graph title

Addons for Cacti and discussion about those addons

Moderators: Developers, Moderators

Post Reply
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Add-on: Using data input field in graph title

Post by noname »

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: http://forums.cacti.net/viewtopic.php?f=2&t=6612

So I've tried implementing that.

How to use
1) Place 'addon_data_input_field.php' at 'cacti/lib/' directory
addon_data_input_field.zip
(1.35 KiB) Downloaded 673 times
2) Modify get_graph_title() in 'cacti/lib/functions.php' as follows:

Code: Select all

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:
|host_description| - Advanced Ping
after:
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
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: Add-on: Using data input field in graph title

Post by gandalf »

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.
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: Add-on: Using data input field in graph title

Post by noname »

Thanks gandalf!
I'll do so with pleasure. (^-^/
http://bugs.cacti.net/view.php?id=1996
matthys
Posts: 9
Joined: Tue Oct 28, 2008 1:50 pm

Re: Add-on: Using data input field in graph title

Post by matthys »

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
User avatar
TheWitness
Developer
Posts: 16897
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Add-on: Using data input field in graph title

Post by TheWitness »

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 dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: Add-on: Using data input field in graph title

Post by noname »

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
ispavailability
Posts: 25
Joined: Sun Nov 20, 2011 8:45 pm

Re: Add-on: Using data input field in graph title

Post by ispavailability »

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.
matthys70
Posts: 8
Joined: Thu Jan 05, 2012 12:03 pm

Re: Add-on: Using data input field in graph title

Post by matthys70 »

Has it been implemented in 0.8.7i or not? Bit confusion if you ask me...
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: Add-on: Using data input field in graph title

Post by noname »

>> 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
Wirthmueller
Cacti User
Posts: 58
Joined: Wed Mar 02, 2011 9:02 am

Re: Add-on: Using data input field in graph title

Post by Wirthmueller »

This is quit an old thread - but maybe someone could help.

What would now be the variables I would need to populate the comment line:

Code: Select all

 Advanced Ping - from |host_hostname| to |input_hostname| (attempts=|input_attempts|, protocol=|input_protocol|)
Wirthmueller
Cacti User
Posts: 58
Joined: Wed Mar 02, 2011 9:02 am

Re: Add-on: Using data input field in graph title

Post by Wirthmueller »

Figured it out:

Code: Select all

|input_attempts| |input_protocol| packets every 300 seconds from |host_hostname| to |input_hostname|
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest