Passing parameters to a query script
Moderators: Developers, Moderators
Passing parameters to a query script
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.
| Scripts: Monitor processes | RFC1213 MIB | DOCSIS Stats | Dell PowerEdge | Speedfan | APC UPS | DOCSIS CMTS | 3ware | Motorola Canopy |
| Guides: Windows Install | [HOWTO] Debug Windows NTFS permission problems |
| Tools: Windows All-in-one Installer |
- gandalf
- Developer
- Posts: 22383
- Joined: Thu Dec 02, 2004 2:46 am
- Location: Muenster, Germany
- Contact:
Re: Passing parameters to a query script
|arg_prepend| is used to provide some input parms to a data query. Use the host variables defined in the cacti docsslack 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.
Reinhard
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.
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.
Here is my xml file for the data query:
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.
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>
/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.
Passing parameters to a query script
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.
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.
Re: Passing parameters to a query script
A trick to get what you need without modifying stock cacti code.
http://forums.cacti.net/viewtopic.php?f=6&t=55704
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
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
Who is online
Users browsing this forum: No registered users and 5 guests