|
|
| Author |
Message |
aboling
Joined: 09 Nov 2007 Posts: 8
|
Posted: Fri May 02, 2008 5:19 pm Post subject: Writing for PHP script server with empty arguments |
|
|
I'm a little new to scripting for cacti, though scripting itself I have a decent amount of experience with. I'm trying to modify a template that someone else wrote so that it supports my SNMPv3 configuration in 0.8.7.
Original:
| Code: |
function ss_f5tmm_mem($hostname, $snmp_community, $snmp_version, $snmp_port, $sn
mp_timeout, $snmpv3_auth_username, $snmpv3_auth_password) {
|
Changed to:
| Code: |
function ss_f5tmm_mem($hostname, $snmp_community, $snmp_version, $snmp_port
, $snmp_timeout, $snmpv3_auth_username, $snmpv3_auth_password, $snmpv3_auth_prot
ocol, $snmpv3_priv_passphrase, $snmpv3_priv_protocol, $snmpv3_context = "", $ret
ries = 0) {
|
I then modified the data input method to pass in the new parameters:
| Code: |
<path_cacti>/scripts/ss_f5-bigip-tmm-memory.php ss_f5tmm_mem <hostname> <snmp_community> <snmp_version> <snmp_port> <snmp_timeout> <snmp_auth_username> <snmp_auth_password> <snmp_auth_proto> <snmp_priv_password> <snmp_priv_proto> <snmp_context>
|
Looks fine at a glance, but what happens when we're dealing with a V3 only host that has no community string?
05/02/2008 06:06:05 PM - CMDPHP: Poller[0] Host[206] DS[2872] SERVER: /export/cacti.imanheim.com/htdocs/scripts/ss_f5-bigip-tmm-memory.php ss_f5tmm_mem 10.XX.XX.XX 3 161 500 (v3user) (authpass) (authproto) (privpass) (privproto) , output: sysStatMemoryTotal:NaN sysStatMemoryUsed:NaN
Note the lack of a placeholder for the "community" value immediately after the IP address. As a result all arguments get shifted and the script naturally fails. How do I account for this? I ran the script server by hand and tried passing in those arguments with quotes around them, but in the case of values like "v3user" the quotes are read literally.
Any advice at all would be greatly appreciated. I couldn't find anything documenting this particular problem. |
|
| Back to top |
|
 |
TheWitness Developer
Joined: 14 May 2002 Posts: 9146 Location: MI, USA
|
Posted: Tue May 06, 2008 2:59 pm Post subject: |
|
|
Interesting. In your XML do the following. Put double quotes around the arguments. For example "<snmp_community>". That also sounds like a bug to me.
Oh, and I do it with colons in the current deployment <snmp_community>:<snmp_version>:<blah>:<blah>
Followed by an $myarray = explode(":", $variables). This is what I would suggest.
Regards,
TheWitness |
|
| Back to top |
|
 |
aboling
Joined: 09 Nov 2007 Posts: 8
|
Posted: Thu Jun 05, 2008 5:25 pm Post subject: |
|
|
| Great suggestion on exploding around the colons. I rewrote the PHP script to do it that way and changed the XML accordingly, and it's worked great since. Thanks a bunch! |
|
| Back to top |
|
 |
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|