Passing parameters to a query script

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
slack
Posts: 17
Joined: Thu May 18, 2006 12:52 pm

Passing parameters to a query script

Post by slack »

How do I pass parameters to a data query script? I see an arg_prepend field in some of the xml files that are part of the default cacti install, but it's not documented.
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: Passing parameters to a query script

Post by gandalf »

slack wrote:How do I pass parameters to a data query script? I see an arg_prepend field in some of the xml files that are part of the default cacti install, but it's not documented.
|arg_prepend| is used to provide some input parms to a data query. Use the host variables defined in the cacti docs
Reinhard
slack
Posts: 17
Joined: Thu May 18, 2006 12:52 pm

Post by slack »

That faq doesn't address this, but thanks.

I need to pass custom variables, not the standard host variables. Is there a way? I can do this with a data input method, why not with a data query?
slack
Posts: 17
Joined: Thu May 18, 2006 12:52 pm

Post by slack »

Ok, making progress here and thought I'd post to help anybody else who might be interested...

Anything in arg_prepend will be passed to the script before the query commands. Thus I can create an XML file for each switch if I need to, which is less than easy to manage, but still doable.

Another idea is to fake it with the existing host variables...but this might be hard to remember down the line.
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

I already spent time on this and am quite sure, that this is not doable with current cacti. Up to now, I've found no example, that really NEEDED this. So I would be interested in your example. If it points out a missing feature ....
Reinhard
slack
Posts: 17
Joined: Thu May 18, 2006 12:52 pm

Post by slack »

Here is my xml file for the data query:

Code: Select all

<interface>
        <name>Get Netgear Smart Switch Stats</name>
        <script_path>|path_cacti|/scripts/smartswitch.php</script_path>
        <arg_prepend>FS526T xxx.xxx.xxx.xxx apassword false</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>ssPortID</index_order>
        <index_order_type>alphabetic</index_order_type>
        <index_title_format>|chosen_order_field|</index_title_format>

        <fields>
                <ssPortID>
                        <name>Port Number</name>
                        <direction>input</direction>
                        <query_name>id</query_name>
                </ssPortID>
                <ssRX>
                        <name>RX</name>
                        <direction>output</direction>
                        <query_name>RX</query_name>
                </ssRX>
                <ssTX>
                        <name>TX</name>
                        <direction>output</direction>
                        <query_name>TX</query_name>
                </ssTX>
                <ssRXError>
                        <name>RX Error</name>
                        <direction>output</direction>
                        <query_name>RXError</query_name>
                </ssRXError>
                <ssTXError>
                        <name>TX Error</name>
                        <direction>output</direction>
                        <query_name>TXError</query_name>
                </ssTXError>
        </fields>
</interface>
So when the poller does its thing, it calls the script like this:

/usr/share/cacti/site/scripts/smartswitch.php FS526T xxx.xxx.xxx.xxx apassword false get TX p25


The first parameter to the script is the switch model number. This is necessary because each smart switch model has a little bit different output, and thus the expressions used to parse the output vary. The second parameter is the IP or host name, which I could of course specify via cacti. The third parameter is the password for the switch, which is not the same as an SNMP password, because this switch doesn't talk SNMP at all....it's the password for the web interface. The fourth parameter is a boolean to enable/disable verbose output from the script for debugging. The remaining parameters are cacti's query itself.


This is actually working for me right now. I'm able to graph RX/TX and errors for all 26 ports on this switch. HOWEVER, I have to hardcode the special script parameters into the XML file. With a data input method I have the choice to specify parameters dynamically, which would be a nice feature for data queries.

The only show-stopper problem I'm having, and this has nothing to do with cacti, is that the management interfaces for these smart switches is really horrible, and crashes easily, requiring a hard restart of the switch. If things don't stabilize then all of my work might have been for nothing.
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Ok, now I understand better. Your request makes sense to me, but I don't know a better solution to this. You may post a Feature Request to the forum referring to this post
Reinhard
ar27
Posts: 1
Joined: Fri Sep 15, 2006 8:38 am

Post by ar27 »

slack

Can you give me an idea of how you used this xml file to get your data graphed. A sample of your php script, screenshots, data file that the script reads, anything that will help me piece together the whole picture.

Thanks
AR
reizend
Posts: 1
Joined: Tue Dec 26, 2006 11:06 am

Passing parameters to a query script

Post by reizend »

vi |path_cacti|/include/config_form.php
change: "method" => "hidden", to: "method" => "textbox",
in "snmp_username" => array( and "snmp_password" => array(
You'll get two new vars |host_snmp_username| and |host_snmp_password| once cacti still use snmp v1 and v2c.
Toddles18
Posts: 22
Joined: Fri Feb 20, 2009 1:28 pm

Re: Passing parameters to a query script

Post by Toddles18 »

A trick to get what you need without modifying stock cacti code.

http://forums.cacti.net/viewtopic.php?f=6&t=55704
Technical Support
General Information
Date Wed, 02 Mar 2016 13:35:32 -0500
Cacti Version 0.8.8f
Cacti OS win32
SNMP Version NET-SNMP version: 5.5
RRDTool Version RRDTool 1.4.x
Hosts 4
Graphs 34
Data Sources Script - Script Server (PHP): 16
Script Query - Script Server: 18
Total: 34
Poller Information
Interval 60
Type cmd.php
Items Action[2]: 72
Total: 72
Concurrent Processes 8
Max Threads 4
PHP Servers 4
Script Timeout 25
Max OID 10
Last Run Statistics Time:12.0814 Method:cmd.php Processes:8 Threads:N/A Hosts:5 HostsPerProcess:1 DataSources:72 RRDsProcessed:30
PHP Information
PHP Version 5.5.20
PHP OS WINNT
PHP uname Windows NT MIHQDBMONITOR01 6.3 build 9200 (Windows Server 2012 R2 Standard Edition) AMD64
PHP SNMP Installed
max_execution_time 60
memory_limit 512M
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests