Hello all!
I have followed step by step the "Script Query Howto" but I have a problem. .rrd wasn't created.
Basic data gathering is ok:
#/usr/local/bin/perl query_test.pl 10.10.10.1 community index
201
202 ...
#/usr/local/bin/perl query_test.pl 10.10.10.1 community query descr
201:This_is_the_5port
202:This_is_the_5_1port ...
#/usr/local/bin/perl query_test.pl 10.10.10.1 community get txpower 201
2.2 (without \n)
#/usr/local/bin/perl query_test.pl 10.10.10.1 community get rxpower 201
-40 (without \n)
XML:
<interface>
<name>Get power info</name>
<description>SNMP based querier</description>
<script_path>/usr/local/bin/perl |path_cacti|/scripts/query_test.pl</script_path>
<arg_prepend>|host_hostname| |host_snmp_community|</arg_prepend>
<arg_index>index</arg_index>
<arg_query>query</arg_query>
<arg_get>get</arg_get>
<arg_num_indexes>num_indexes</arg_num_indexes>
<output_delimeter>:</output_delimeter>
<index_order>ifDescr</index_order>
<index_order_type>alphabetic</index_order_type>
<index_title_format>|chosen_order_field|</index_title_format>
<fields>
<ifDescr>
<name>Interface description</name>
<direction>input</direction>
<query_name>descr</query_name>
</ifDescr>
<rxpower>
<name>rxpower</name>
<direction>output</direction>
<query_name>rxpower</query_name>
</rxpower>
<txpower>
<name>txpower</name>
<direction>output</direction>
<query_name>txpower</query_name>
</txpower>
</fields>
</interface>
Verbose Query is ok:
Total: 0, Delta: 0, Running data query [31].
Total: 0, Delta: 0, Found type = '4' [Script Query].
Total: 0, Delta: 0, Found data query XML file at '/usr/local/share/cacti/resource/script_queries/test_cn.xml'
Total: 0, Delta: 0, XML file parsed ok.
Total: 0.19, Delta: 0.19, Executing script for num of indexes '/usr/local/bin/perl /usr/local/share/cacti/scripts/query_test.pl 10.10.10.1 community num_indexes'
Total: 0.19, Delta: 0, Found number of indexes: 14
Total: 0.37, Delta: 0.17, Executing script for list of indexes '/usr/local/bin/perl /usr/local/share/cacti/scripts/query_test.pl 10.10.10.1 community index' Index Count: 14
Result for indexes:
Found index: 201
Found index: 202 ...
Executing script query '/usr/local/bin/perl /usr/local/share/cacti/scripts/query_test.pl 10.10.10.1 community query descr'
Found item [ifDescr='This_is_the_5port'] index: 201
Found item [ifDescr='This_is_the_5_1port'] index: 202 ...
It returns all the indexes and descriptions.
I have a similar Script Data Query but for other model (with other OIDs) and everything's ok.
This device is UP. Another graphs are available, e.g SNMP Interface Statistics.
Permissions are the same as for other files in the directory.
Finally, I found it:
select * from host_snmp_query;
+---------+---------------+------------+-----------------+----------------+
| host_id | snmp_query_id | sort_field | title_format | reindex_method |
+---------+---------------+------------+-----------------+----------------+
| 39 | 1 | ifDescr | |query_ifDescr| | 1 | # this record is SNMP Int Stat
| 39 | 31 | | |query_| | 1 | # this record for my failed script data query
I saw a similar issue about |query_| (instead of |query_ifDescr|) and empty sort_field (viewtopic.php?f=2&t=23653) which was solved by changing the permissions.
But in this case it can't be so because, as I told earlier, I have another Script Data query which works fine and uses the same libraries.
Can anybody guess where can be the problem?
I really don't know what it can be.
Thank for any reply and idea.
Script Data Query Issue
Moderators: Developers, Moderators
Re: Script Data Query Issue
Is your query graphed? Sounds like a strange question but I think if the query isn't used in a graph, it isn't polled for data.
If you can, package up all the parts needed to test it, and I'll give it ago against one of my own devices.
What is the scripts purpose? Or are you just trying to understand how things are working?
If you can, package up all the parts needed to test it, and I'll give it ago against one of my own devices.
What is the scripts purpose? Or are you just trying to understand how things are working?
Cacti Developer & Release Manager
The Cacti Group
Director
BV IT Solutions Ltd
+--------------------------------------------------------------------------+
Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
The Cacti Group
Director
BV IT Solutions Ltd
+--------------------------------------------------------------------------+
Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
Re: Script Data Query Issue
Looking at the code in lib/data_query.php, the update_data_query_sort_cache() function performs the following:
This checks the index returned by get_ordered_index_type_list() function to make sure that there is an array of sort indexes. If there is it uses the first field, otherwise it uses a blank string.
Now, here is what I think it is happening. You aren't getting a valid list, so the next part does the replacement incorrectly because you have correctly used the |choosen_sort_field| substitution text
So, as you can imagine, your title format always becomes |query_| if nothing is properly returned. Yet the code then still tries to update the database:
So, I'm now going to look at get_ordered_index_type_list to see if there is a reason it isn't returning the rows expected.
Code: Select all
/* get a list of valid data query types */
$valid_index_types = get_ordered_index_type_list($host_id, $data_query_id);
/* something is probably wrong with the data query */
if (sizeof($valid_index_types) == 0) {
$sort_field = '';
} else {
/* grab the first field off the list */
$sort_field = $valid_index_types[0];
}
Now, here is what I think it is happening. You aren't getting a valid list, so the next part does the replacement incorrectly because you have correctly used the |choosen_sort_field| substitution text
Code: Select all
/* substitute variables */
if (isset($raw_xml['index_title_format'])) {
$title_format = str_replace('|chosen_order_field|', "|query_$sort_field|", $raw_xml['index_title_format']);
} else {
$title_format = "|query_$sort_field|";
}
Code: Select all
/* update the cache */
/* TODO: if both $sort field and $title_format are empty, this yields funny results */
db_execute_prepared('UPDATE host_snmp_query
SET sort_field = ?,
title_format = ?
WHERE host_id = ?
AND snmp_query_id = ?',
array($sort_field, $title_format, $host_id, $data_query_id));
Cacti Developer & Release Manager
The Cacti Group
Director
BV IT Solutions Ltd
+--------------------------------------------------------------------------+
Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
The Cacti Group
Director
BV IT Solutions Ltd
+--------------------------------------------------------------------------+
Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
Re: Script Data Query Issue
Is it possible your XML isn't 100% correct?
Cacti Developer & Release Manager
The Cacti Group
Director
BV IT Solutions Ltd
+--------------------------------------------------------------------------+
Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
The Cacti Group
Director
BV IT Solutions Ltd
+--------------------------------------------------------------------------+
Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
-
- Posts: 2
- Joined: Tue Dec 19, 2017 7:44 am
Re: Script Data Query Issue
Hello, markv!
Scripts purpose is to display Rx & Tx powers of waveserver interfaces.
The problem was that the graphs were not created. .rrd wasn't created too.
As you told, I checked my XML but it was correct.
After, I checked data_query.php displaying most of the intermediate variables for my device while executing. And it helped
I saw one interesting condition in "get_ordered_index_type_list" function:
My script returned an array of descriptions which had dupicates. And because of it everything went wrong.
e.g
201!This_is_the_5port
202!This_is_the_5port
203!This_is_the_5port ...
After some changes script returns unique values:
201!This_is_the_5port
202!This_is_the_5port_2
203!This_is_the_5port_3 ...
And now everything is fine.
Thank you for your help! The problem was solved.
Scripts purpose is to display Rx & Tx powers of waveserver interfaces.
The problem was that the graphs were not created. .rrd wasn't created too.
As you told, I checked my XML but it was correct.
After, I checked data_query.php displaying most of the intermediate variables for my device while executing. And it helped
I saw one interesting condition in "get_ordered_index_type_list" function:
Code: Select all
/* fields that contain duplicate or empty values are not suitable to index off of */
if (!((sizeof($aggregate_field_values) < sizeof($field_values)) || (in_array('', $aggregate_field_values) == true) || (sizeof($aggregate_field_values) == 0)) || ($nonunique)) {
array_push($xml_outputs, $field_name);
}
e.g
201!This_is_the_5port
202!This_is_the_5port
203!This_is_the_5port ...
After some changes script returns unique values:
201!This_is_the_5port
202!This_is_the_5port_2
203!This_is_the_5port_3 ...
And now everything is fine.
Thank you for your help! The problem was solved.
Re: Script Data Query Issue
Interesting to know, glad you are sorted.
Cacti Developer & Release Manager
The Cacti Group
Director
BV IT Solutions Ltd
+--------------------------------------------------------------------------+
Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
The Cacti Group
Director
BV IT Solutions Ltd
+--------------------------------------------------------------------------+
Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
Who is online
Users browsing this forum: No registered users and 2 guests