Writing for PHP script server with empty arguments

Discussions on developing plugins for the Cacti Plugin Architecture

Moderators: Developers, Moderators

Post Reply
aboling
Posts: 8
Joined: Fri Nov 09, 2007 7:52 pm

Writing for PHP script server with empty arguments

Post by aboling »

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: Select all

function ss_f5tmm_mem($hostname, $snmp_community, $snmp_version, $snmp_port, $sn
mp_timeout, $snmpv3_auth_username, $snmpv3_auth_password) {
Changed to:

Code: Select all

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: Select all

<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. :D I couldn't find anything documenting this particular problem.
User avatar
TheWitness
Developer
Posts: 17047
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Post by TheWitness »

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
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
aboling
Posts: 8
Joined: Fri Nov 09, 2007 7:52 pm

Post by aboling »

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!
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests