php script to php_script_server script (with Data Queries)

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

Moderators: Developers, Moderators

Post Reply
msylvain
Posts: 9
Joined: Wed Jan 23, 2008 3:30 am

php script to php_script_server script (with Data Queries)

Post by msylvain »

Hello,

For some reason (speed and efficiency especially), i am trying to transform an xml file and its php script from Data Queries based on the standard "Get Script Data (Indexed)" data input method to an other Data input method which allow polling to be run by the php script_server.php script.

I've read carefully this post describe something similar to what i'm trying to do.

Here is th diff b

Code: Select all

3c3,5
<       <script_path>|path_php_binary| -q |path_cacti|/scripts/plop.php</script_path>
---
>       <script_path>|path_cacti|/scripts/ss_plop.php</script_path>
>       <script_function>ss_plop</script_function>
>       <script_server>php</script_server>
42,55c44,57

I have tried to run my script via the php script_server this way :

Code: Select all

cd /usr/share/cacti
php script_server.php 
scripts/ss_plop.php ss_plop ... ... ...
and this works.

I have had a look at the "Poller Cache Items", and i see things like that :

Code: Select all

Script: /usr/share/cacti/scripts/ss_plop.php 10.11.12.13 1 get someName 1
but i think i should see :

Code: Select all

Script Server: /usr/share/cacti/scripts/ss_plop.php ss_plop 10.11.12.13 1 get someName 1
The only thing which works is in the device section : when i associate my data query to a device, i can see that the status is "success", and the number of items en rows are OK.

I have also read some code in the lib/utility.php file (especially the update_poller_cache function, wich fill in the poller_item table) and tried to replay some sql request, like this one (the resulat is stored in the data_input variable) :

Code: Select all

select
	data_input.id,
	data_input.type_id,
	data_template_data.id as data_template_data_id,
	data_template_data.data_template_id,
	data_template_data.active
from (data_template_data,data_input)
where data_template_data.data_input_id=data_input.id
	and data_template_data.local_data_id=1606;
the result is :

Code: Select all

+----+---------+-----------------------+------------------+--------+
| id | type_id | data_template_data_id | data_template_id | active |
+----+---------+-----------------------+------------------+--------+
| 11 |       4 |                  1671 |               49 | on     |
+----+---------+-----------------------+------------------+--------+
According to the constant definition :

Code: Select all

grep '"DATA_INPUT_TYPE_' ../include/config_constants.php
define("DATA_INPUT_TYPE_SCRIPT", 1);
define("DATA_INPUT_TYPE_SNMP", 2);
define("DATA_INPUT_TYPE_SNMP_QUERY", 3);
define("DATA_INPUT_TYPE_SCRIPT_QUERY", 4);
define("DATA_INPUT_TYPE_PHP_SCRIPT_SERVER", 5);
define("DATA_INPUT_TYPE_QUERY_SCRIPT_SERVER", 6);
it means that my query is a script query....

Anyway, i'm not sure all what i wrote is clear, but if someone understand me, i would be very happy to get some help...

thanks !
User avatar
BSOD2600
Cacti Moderator
Posts: 12171
Joined: Sat May 08, 2004 12:44 pm
Location: USA

Re: php script to php_script_server script (with Data Querie

Post by BSOD2600 »

msylvain wrote:but i think i should see :

Code: Select all

Script Server: /usr/share/cacti/scripts/ss_plop.php ss_plop 10.11.12.13 1 get someName 1
Correct. In your Data Input Methods, you specified to use the Script - Script Server (PHP), instead of Script/Command, right?

Also, you really should read through the guide(s) on the documentation site.

With your cacti logging level set to debug, do you see your ss_ script getting executed? Is it returning data?
msylvain
Posts: 9
Joined: Wed Jan 23, 2008 3:30 am

Post by msylvain »

BSOD2600 wrote: Correct. In your Data Input Methods, you specified to use the Script - Script Server (PHP), instead of Script/Command, right?
i was a "script query" data input method.
with my new xml file andmy php script_server enabled script, the data query works (in the device page) with a "script query - script server" data input method, but the polling doesn't work (i got unknow values, as explained later).
if i use a "Script Server(PHP)" data input method, i get nothing on the device page, in the status column (zero item, zero row).

I im trying to do something similar to the example "SNMP - Get Mounted Partitions" Data Queries, which data input method is "Get Script Server Data (Indexed)", aka "Script Query - Script Server" with 3 input and 1 output
BSOD2600 wrote: Also, you really should read through the guide(s) on the documentation site.
I'm not sure i can says i've read eveything, but i can say that i already read a lot. I can also say that it's my first post, but i have been using cacti for more than 6 month at work, and i am quite used with it now.

BSOD2600 wrote: With your cacti logging level set to debug, do you see your ss_ script getting executed? Is it returning data?
No, it only returns "Unknow", because cmd.php try to run :

Code: Select all

/usr/share/cacti/scripts/ss_plop.php ...
without runing it via "php" or "php -q" or "php script_server.php", sor it returns junk.
msylvain
Posts: 9
Joined: Wed Jan 23, 2008 3:30 am

Post by msylvain »

After reading the code from data_query.php:run_data_query(), the data query type should be 4 or 6, that is to say :
- the standard "Get Script Data (Indexed)" (4)]
- the standard "Get Script Server Data (Indexed)" (6)
if the data input type is something else, the verbose data query end up with "unknown type = X"

I think the problem is in the xml file. I may make a mistake in the way i ask cacti to do polling via the script_server.php script...
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests