Cacti / cacti

Cacti ™
http://www.cacti.net
GNU General Public License v2.0
1.65k stars 406 forks source link

Spaces lost in command line when importing Data Input Method #989

Closed eschoeller closed 7 years ago

eschoeller commented 7 years ago

I have created a data input method shown here: screenshot_20170918_010603 <path_php_binary> -q <path_cacti>/scripts/query_apc_rack_pdu.php <query> <hostname> <snmp_community> <snmp_version> <snmp_port> <snmp_timeout> "<snmp_username>" "<snmp_password>" "<snmp_auth_protocol>" "<snmp_priv_passphrase>" "<snmp_priv_protocol>"

I then export it as part of a device template, and re-import it into another instance. Here is what it looks like now: screenshot_20170918_010405 <path_php_binary> -q <path_cacti>/scripts/query_apc_rack_pdu.php <query> <hostname> <snmp_community> <snmp_version> <snmp_port> <snmp_timeout>"<snmp_username>" "<snmp_password>" "<snmp_auth_protocol>" "<snmp_priv_passphrase>" "<snmp_priv_protocol>"

And in my logs I saw this: ERROR: Empty result [192.168.1.3]: '/usr/local/php/bin/php -q /cacti/cacti-1.1.24-prod/scripts/query_apc_rack_pdu.php 'PhaseStatusApparentPower' '192.168.1.3' 'something' '2' '161' '1500'"''" "''" "''" "''" "''"'

This seems to be a very minor nuance but I have a mixture of arguments double quoted and not. There is a space before the first argument that is double quoted (snmp_username), separating it from the previous one (snmp_timeout). When the Data Input Method is imported, this space is removed - and of course the command no longer works.

cigamit commented 7 years ago

I think on this one, you can remove the double quotes on around the tags on your data input method since we do this automatically now. After that, are you still seeing the issue?

Also, expand your text-area above and see if there is a carriage return or line feed in the data input method. That would lead to the issue you mention.

cigamit commented 7 years ago

Are the spaces lost on the export or the import?

eschoeller commented 7 years ago

Here is what it looks like after the export: <input_string>&lt;path_php_binary&gt; -q &lt;path_cacti&gt;/scripts/query_apc_rack_pdu.php &lt;query&gt; &lt;hostname&gt; &lt;snmp_community&gt; &lt;snmp_version&gt; &lt;snmp_port&gt; &lt;snmp_timeout&gt; &quot;&lt;snmp_username&gt;&quot; &quot;&lt;snmp_password&gt;&quot; &quot;&lt;snmp_auth_protocol&gt;&quot; &quot;&lt;snmp_priv_passphrase&gt;&quot; &quot;&lt;snmp_priv_protocol&gt;&quot;</input_string>

So it looks like this is OK, meaning the space is lost upon import

cigamit commented 7 years ago

That's what I needed to know. I don't have much time right now for a lot of hunting and pecking. So, any work you all can do to facilitate things is a blessing.

cigamit commented 7 years ago

Doing the research this morning, the problem is due to the XML parser that comes with PHP. It strips the spaces after the special characters. I'm going to resolve this for 1.1.26 forward by base64_encoding the input_string instead and detecting it on the import side and decoding. This is the only good way to handle this permanently. I'm also going to be adding a little hack to resolve issues (or attempt to) for people with old templates.

Either way, what was in place before had no hope of working.

cigamit commented 7 years ago

Resolved. My prior comments still are relevant for this issue.