[SOLVED] Script parameter in graph title

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
User avatar
lcano
Cacti User
Posts: 190
Joined: Thu Oct 09, 2008 5:46 pm
Location: Spain

[SOLVED] Script parameter in graph title

Post by lcano »

Hi

I have a perl script to extract some data from a device. This script needs two input parameters (PARAM1 and PARAM2) to show then around 20 output fields. The situation is similar to the snmp_query for interface traffic (interface.xml) with some input fields and several output fields, but this is not a data query, but a script/command query.

I need to set the graph title with these two parameters, in order not to create a graph template for each graph I have to print. The first parameter (PARAM1) is the name of the device, so no problem with the variable |host_description|. My problem is how to show the second parameter in the title of the graph. With the interfaces, the |query_parameter| directive solves this problem, but I was not able to make it works when it is not a data query, but an script command data input method. :( I tried with |query_parameter2| but no success...

I've been also reading http://www.cacti.net/downloads/docs/html/variables.html but I didn't find any solution for this situation.

Is there any way to do it? If not, could it be any improvement for future releases?

Thanks...
Last edited by lcano on Thu Oct 20, 2011 9:35 am, edited 1 time in total.
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: Script parameter in graph title

Post by noname »

lcano wrote: I need to set the graph title with these two parameters, in order not to create a graph template for each graph I have to print. The first parameter (PARAM1) is the name of the device, so no problem with the variable |host_description|. My problem is how to show the second parameter in the title of the graph. With the interfaces, the |query_parameter| directive solves this problem, but I was not able to make it works when it is not a data query, but an script command data input method. :( I tried with |query_parameter2| but no success...
For Cacti 0.8.7g, try this add-on:
- http://forums.cacti.net/viewtopic.php?f=5&t=42802

Cacti 0.8.7h seems to be implemented that (but by different way).

Code: Select all

feature#0001952: Ability to use input field of a script in graph title
"|input_xxxx|" is working for several graph elements (COMMENT, HRULE, legend, etc.),
but it appears not to work for graph title, even if performed "Reapply Suggested Names".
User avatar
TheWitness
Developer
Posts: 17007
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Script parameter in graph title

Post by TheWitness »

Somehow we missed that. Can you open a bug. No promises this week that a patch will be out. My cup run'ith over.

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: Script parameter in graph title

Post by noname »

Sure.
- http://bugs.cacti.net/view.php?id=2079

Thanks anyway. :)
User avatar
lcano
Cacti User
Posts: 190
Joined: Thu Oct 09, 2008 5:46 pm
Location: Spain

Re: Script parameter in graph title

Post by lcano »

Thank you both,

nonamed, I finally applied your addon and it worked. Until the patch had been developed nonamed's addon works fine. :D :D
User avatar
TheWitness
Developer
Posts: 17007
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: [SOLVED] Script parameter in graph title

Post by TheWitness »

Ok, fixed in SVN now. Much simpler fix there.
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?
User avatar
lcano
Cacti User
Posts: 190
Joined: Thu Oct 09, 2008 5:46 pm
Location: Spain

Re: [SOLVED] Script parameter in graph title

Post by lcano »

TheWitness wrote:Ok, fixed in SVN now. Much simpler fix there.
Thanks TheWitness
dolla
Posts: 19
Joined: Tue Oct 05, 2010 6:11 pm

Re: [SOLVED] Script parameter in graph title

Post by dolla »

It seems the fix in http://bugs.cacti.net/view.php?id=2079 still not working in my 0.8.7h,
I always get errors like this when open any graphs with |input_xxxx| in their titles.
And newly created graphs won't get |input_xxxx| expanded correctly.

errors like below:
=============================error begin===================================
11/08/2011 11:25:50 AM - CMDPHP: Poller[0] ERROR: SQL Cell Failed!, Error:'1064', SQL:"SELECT id FROM data_template_data WHERE local_data_id IN ()"
11/08/2011 11:25:50 AM - CMDPHP: Poller[0] ERROR: SQL Assoc Failed!, Error:'1064', SQL:"SELECT DISTINCT local_data_id FROM data_template_rrd INNER JOIN graph_templates_item ON data_template_rrd.id=graph_templates_item.task_item_id WHERE local_graph_id="
=============================error end===================================

In the end I found in functions.php, need to modify one line and add another line in the code below in bold.
It is because $local_graph_id column is missing in the $graph array here in function get_graph_title.

Sorry I don't know how to format these lines to get nicer looking.
Please help me to validate if this change is correct or not.
At least now I won't get errors when open those graphs and "Reapply Suggested Names" also works.

============================code begin=======================
/* get_graph_title - returns the title of a graph without using the title cache
@arg $local_graph_id - (int) the ID of the graph to get a title for
@returns - the graph title */
function get_graph_title($local_graph_id) {
$graph = db_fetch_row("select
graph_local.host_id,
graph_local.snmp_query_id,
graph_local.snmp_index,
graph_templates_graph.title,
graph_templates_graph.local_graph_id

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_data($graph["title"], $graph, 0);
return expand_title($graph["host_id"], $graph["snmp_query_id"], $graph["snmp_index"], $graph["title"]);
}else{
return $graph["title"];
}
==========================code end=========================
User avatar
TheWitness
Developer
Posts: 17007
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: [SOLVED] Script parameter in graph title

Post by TheWitness »

First, I think there are other problems and that you are misplacing your blame on the query above. In SVN, it looks like the following:

Code: Select all

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=1854;
Which results in:

Code: Select all

mysql> 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=1854;
+---------+---------------+------------+------------------------------------------------------+
| host_id | snmp_query_id | snmp_index | title                                                |
+---------+---------------+------------+------------------------------------------------------+
|      32 |            10 | wget       | |host_description| - |query_appName| - Total Running |
+---------+---------------+------------+------------------------------------------------------+
1 row in set (0.00 sec)
So, local_graph_id is not required. However, it is yet to be seen where that problem actually is. Before you go any further, make sure that you have NOT applied the other patch.
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?
dolla
Posts: 19
Joined: Tue Oct 05, 2010 6:11 pm

Re: [SOLVED] Script parameter in graph title

Post by dolla »

You are right, TheWitness. The get_graph_title in functions.php exists before this replace-parameter-in-graph-title function introduce for sure. So it might be in the variables.php then.

The SQL error i saw, looks like from the function "substitute_data_input_data" in variables.php:

========================code begin, variables.php========================
$local_data_ids = array_rekey(db_fetch_assoc("SELECT DISTINCT local_data_id
FROM data_template_rrd
INNER JOIN graph_templates_item
ON data_template_rrd.id=graph_templates_item.task_item_id
WHERE local_graph_id=" . $graph["local_graph_id"]), "local_data_id", "local_data_id");
========================code end====================================

Here it refers to a $graph array. The function "get_graph_title" in functions.php called the function "substitute_data_input_data". So if not going to modify the get_graph_title function, modify the "substitute_data_input_data" function? I bet it will work too. But sorry I don't have a whole picture of what to modify.

========================code begin, functions.php========================
if ((strstr($graph["title"], "|")) && (!empty($graph["host_id"]))) {
$graph["title"] = substitute_data_input_data($graph["title"], $graph, 0);
return expand_title($graph["host_id"], $graph["snmp_query_id"], $graph["snmp_index"], $graph["title"]);
}else{
return $graph["title"];
}
}
========================code end====================================
User avatar
TheWitness
Developer
Posts: 17007
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: [SOLVED] Script parameter in graph title

Post by TheWitness »

Replate it with the following:

Code: Select all

if (empty($local_data_id)) {
	if (isset($graph['local_graph_id'])) {
		$local_data_ids = array_rekey(db_fetch_assoc("SELECT DISTINCT local_data_id
			FROM data_template_rrd
			INNER JOIN graph_templates_item
			ON data_template_rrd.id=graph_templates_item.task_item_id
			WHERE local_graph_id=" . $graph["local_graph_id"]), "local_data_id", "local_data_id");

		$data_template_data_id = db_fetch_cell("SELECT id FROM data_template_data WHERE local_data_id IN (" . implode(",", $local_data_ids) . ")");
	}else{
		$data_template_data_id = 0;
	}
}else{
	$data_template_data_id = db_fetch_cell("SELECT id FROM data_template_data WHERE local_data_id=$local_data_id");
}
Let me know if that fixes it.
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?
User avatar
TheWitness
Developer
Posts: 17007
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: [SOLVED] Script parameter in graph title

Post by TheWitness »

Here's a second cut.

Code: Select all

if (empty($local_data_id)) {
	if (isset($graph['local_graph_id'])) {
		$local_data_ids = array_rekey(db_fetch_assoc("SELECT DISTINCT local_data_id
			FROM data_template_rrd
			INNER JOIN graph_templates_item
			ON data_template_rrd.id=graph_templates_item.task_item_id
			WHERE local_graph_id=" . $graph["local_graph_id"]), "local_data_id", "local_data_id");

		if (sizeof($local_data_ids)) {
			$data_template_data_id = db_fetch_cell("SELECT id FROM data_template_data WHERE local_data_id IN (" . implode(",", $local_data_ids) . ")");
		}else{
			$data_template_data_id = 0;
		}
	}else{
			$data_template_data_id = 0;
	}
}else{
	$data_template_data_id = db_fetch_cell("SELECT id FROM data_template_data WHERE local_data_id=$local_data_id");
}
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?
dolla
Posts: 19
Joined: Tue Oct 05, 2010 6:11 pm

Re: [SOLVED] Script parameter in graph title

Post by dolla »

Thanks TheWitness, but it doesn't work. And I don't see any SQL errors. I still have to modify the functions.php to work with the new code.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests