[SOLVED] Script parameter in graph title
Moderators: Developers, Moderators
[SOLVED] Script parameter in graph title
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...
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.
Re: Script parameter in graph title
For Cacti 0.8.7g, try this add-on: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...
- 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
but it appears not to work for graph title, even if performed "Reapply Suggested Names".
- TheWitness
- Developer
- Posts: 17007
- Joined: Tue May 14, 2002 5:08 pm
- Location: MI, USA
- Contact:
Re: Script parameter in graph title
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
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?
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?
Re: Script parameter in graph title
Thank you both,
nonamed, I finally applied your addon and it worked. Until the patch had been developed nonamed's addon works fine.
nonamed, I finally applied your addon and it worked. Until the patch had been developed nonamed's addon works fine.
- TheWitness
- Developer
- Posts: 17007
- Joined: Tue May 14, 2002 5:08 pm
- Location: MI, USA
- Contact:
Re: [SOLVED] Script parameter in graph title
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?
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?
Re: [SOLVED] Script parameter in graph title
Thanks TheWitnessTheWitness wrote:Ok, fixed in SVN now. Much simpler fix there.
Re: [SOLVED] Script parameter in graph title
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=========================
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=========================
- TheWitness
- Developer
- Posts: 17007
- Joined: Tue May 14, 2002 5:08 pm
- Location: MI, USA
- Contact:
Re: [SOLVED] Script parameter in graph title
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:
Which results in:
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.
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;
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)
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?
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?
Re: [SOLVED] Script parameter in graph title
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====================================
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====================================
- TheWitness
- Developer
- Posts: 17007
- Joined: Tue May 14, 2002 5:08 pm
- Location: MI, USA
- Contact:
Re: [SOLVED] Script parameter in graph title
Replate it with the following:
Let me know if that fixes it.
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");
}
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?
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?
- TheWitness
- Developer
- Posts: 17007
- Joined: Tue May 14, 2002 5:08 pm
- Location: MI, USA
- Contact:
Re: [SOLVED] Script parameter in graph title
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?
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?
Re: [SOLVED] Script parameter in graph title
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.
Who is online
Users browsing this forum: No registered users and 0 guests