Cacti / cacti

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

cacti_snmp_get bad handling of wierd value into snmp_value #288

Closed arno-st closed 7 years ago

arno-st commented 7 years ago

I find a bug, or at least a bad way of handling the snmp-value return by an snmp query. For some reason on some Cisco Switch the snmp field is not usable, and contain an CR or LF, and the function cacti_snmp_get dosen't handle it correctly

You can try doing an snmpwalk to this oid .1.3.6.1.4.1.9.9.23.1.2.1.1.4 It's the CDP query to gather the IP value of the device connected, and sometime you will get: SNMPv2-SMI::enterprises.9.9.23.1.2.1.1.4.10015.8 = Hex-STRING: 0A 55 00 DA SNMPv2-SMI::enterprises.9.9.23.1.2.1.1.4.10016.3 = Hex-STRING: 0A 55 7B 04 SNMPv2-SMI::enterprises.9.9.23.1.2.1.1.4.10017.14 = STRING: " Uz[" SNMPv2-SMI::enterprises.9.9.23.1.2.1.1.4.10018.7 = STRING: " U{ " SNMPv2-SMI::enterprises.9.9.23.1.2.1.1.4.10020.175 = STRING: " Uz`" SNMPv2-SMI::enterprises.9.9.23.1.2.1.1.4.10101.13 = Hex-STRING: 0A 55 00 D6 SNMPv2-SMI::enterprises.9.9.23.1.2.1.1.4.10102.1 = Hex-STRING: 0A 55 00 01

The first field is a CR or LF and it's baldy interpreted by the cacti_snmp_walk the 10017, 10018, 10020 are Cisco phone, you can have the same behavior with Cisco ATA, WiFi access point

I issue the following command: $searchip = cacti_snmp_walk( $seedhost, $snmp_array['snmp_community'], ".1.3.6.1.4.1.9.9.23.1.2.1.1.4", $snmp_array['snmp_version'], $snmp_array['snmp_username'], $snmp_array['snmp_password'], $snmp_array['snmp_auth_protocol'], $snmp_array['snmp_priv_passphrase'], $snmp_array['snmp_priv_protocol'], $snmp_array['snmp_context'] );

$seedhost is the hostname or ip address of a Cisco switch that has the cdp enable and return value. If you have a phone or weird device some IP address ar returned badly,

cigamit commented 7 years ago

Do you have php-snmp installed (paste output of php -m)? Please confirm. If not, please install it and let us know again if there is any change.

arno-st commented 7 years ago

No I do not. [PHP Modules] bcmath bz2 calendar Core ctype curl date dom ereg exif fileinfo filter ftp gd gettext gmp hash iconv json libxml mbstring mhash mysql mysqli openssl pcntl pcre PDO pdo_mysql pdo_sqlite Phar posix readline Reflection session shmop SimpleXML sockets SPL sqlite3 standard sysvmsg sysvsem sysvshm tidy tokenizer wddx xml xmlreader xmlwriter xsl zip zlib

[Zend Modules]

I can't say it works better, now a simple cacti_snmp_get query won't give me any value !! Same query, that was working without php-snmp just by installing is not working anymore

arno-st commented 7 years ago

Well ok I change a bit of my code, just to test the snmpwalk and bad character, so it work well with php-snmp! But then as I said my cactii-smp-get dosen't work anymore, I get null when without php-snmp it works well

cigamit commented 7 years ago

Please show me the entire snmpget command that you are using to get your correct values. The whole string, and what you get when using the php-snmp. Thanks!

cigamit commented 7 years ago

Okay, with php-snmp removed, this should be resolved. However, I'm keeping open so you can provide more information as to why php-snmp does not work in case there is a solution.

arno-st commented 7 years ago

This is the code I use to replace a snmpwalk by a snmp_get, and it's the one ot working: Te $intfindex is the OID of the interface I need to scan, it depend on every switch // look for the IP table $searchip = cacti_snmp_get( $seedhost, $snmp_array['snmp_community'], ".1.3.6.1.4.1.9.9.23.1.2.1.1.4".".".$intfindex, $snmp_array['snmp_version'], $snmp_array['snmp_username'], $snmp_array['snmp_password'], $snmp_array['snmp_auth_protocol'], $snmp_array['snmp_priv_passphrase'], $snmp_array['snmp_priv_protocol'], $snmp_array['snmp_context'] );

And here is CLI example: snmpwalk -v2c -ctelvlsn se-sve-225.recolte.lausanne.ch .1.3.6.1.4.1.9.9.23.1.2.1.1.4 SNMPv2-SMI::enterprises.9.9.23.1.2.1.1.4.10108.6 = STRING: " UyC" SNMPv2-SMI::enterprises.9.9.23.1.2.1.1.4.10109.2 = Hex-STRING: 0A 55 00 E0 SNMPv2-SMI::enterprises.9.9.23.1.2.1.1.4.10110.1 = Hex-STRING: 0A 55 00 01

[root@lslcact01:/usr/share/cacti/plugins/linkdiscovery] # snmpget -v2c -ctelvlsn se-sve-225.recolte.lausanne.ch .1.3.6.1.4.1.9.9.23.1.2.1.1.4.10108.6 SNMPv2-SMI::enterprises.9.9.23.1.2.1.1.4.10108.6 = STRING: " UyC"

arno-st commented 7 years ago

When I do that in the code I just get NULL with snmp_get under php-snmp and I get this when I do without it: string(11) "0A:00:00:1E" the IP address in hex format

cigamit commented 7 years ago

Cacti's snmp_get() function attempts to do all sorts of 'cleanup' assuming that you are attempting to get numeric data, we should introduce a 'cacti_snmp_get_raw()' that does no post processing. This would be much more convenient for plugin developers.

cigamit commented 7 years ago

Function cacti_snmp_get_raw() added.

arno-st commented 7 years ago

Hi Jimmy, Actually with a raw function, you have to know that you are getting special data, but in my case, I didn’t knew I will get a CR/LF at first place. So I will never call for the raw function, because 80% of the time I’m getting numeric value, but once in a while I’m getting junk.

So I was hoping a more in a clean up way to remove special character , and just return what was read (numeric or alpha).

But looking into the code, I saw some clean up on special, character, but not working all the time maybe.

Regards,,

Arno Streuli

On 18 Feb 2017, at 19:46, Jimmy Conner notifications@github.com wrote:

Cacti's snmp_get() function attempts to do all sorts of 'cleanup' assuming that you are attempting to get numeric data, we should introduce a 'cacti_snmp_get_raw()' that does no post processing. This would be much more convenient for plugin developers.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Cacti/cacti/issues/288#issuecomment-280866333, or mute the thread https://github.com/notifications/unsubscribe-auth/AYfro-7kqJUwBgwMWApNVZZ-qqFrE2Rrks5rdzydgaJpZM4L9O8-.

cigamit commented 7 years ago

If you would please create a pull request once you have it figured out, that would be good.

cigamit commented 7 years ago

Going to close. Looking forward to your pull request.

cigamit commented 7 years ago

If you are trying to get a data point that is not numeric or needs special cleanup, you should use the raw function. The normal get function will always try to convert to a numeric value. In the case of Hex Strings, it will attempt to convert hard to a number by converting those hex values to their numeric equivalent. So, the raw function is what you should get if you are trying to get some string or hex value and do the cleanup from there. I don't think I'll attempt to improve things more than that.

arno-st commented 7 years ago

Hi Jimmy,

I see that you change a lot in snmp_walk and snmp_get function, so now it’s not more working!

Here is my output: With the new version an snmp walk give me this: array(3) { [0]=> array(2) { ["oid"]=> string(37) ".1.3.6.1.4.1.9.9.23.1.2.1.1.4.10108.3" ["value"]=> string(4) "UyC"" } [1]=> array(2) { ["oid"]=> string(37) ".1.3.6.1.4.1.9.9.23.1.2.1.1.4.10109.2" ["value"]=> string(4) " Uà" } [2]=> array(2) { ["oid"]=> string(37) ".1.3.6.1.4.1.9.9.23.1.2.1.1.4.10110.1" ["value"]=> string(4) " U" } }

An snmp_get of the same field give me: string(3) "UyC" string(16) "Hex- 0A 55 00 E0" string(16) "Hex- 0A 55 00 01"

And with the old lib I get the following : The snmpwalk array(4) { [0]=> array(2) { ["oid"]=> string(37) ".1.3.6.1.4.1.9.9.23.1.2.1.1.4.10108.3" ["value"]=> string(0) "" } [1]=> array(2) { ["oid"]=> string(4) "UyC"" ["value"]=> string(3) "UyC" } [2]=> array(2) { ["oid"]=> string(37) ".1.3.6.1.4.1.9.9.23.1.2.1.1.4.10109.2" ["value"]=> string(11) "0A 55 00 E0" } [3]=> array(2) { ["oid"]=> string(37) ".1.3.6.1.4.1.9.9.23.1.2.1.1.4.10110.1" ["value"]=> string(11) "0A 55 00 01" } }

And the snmpget of each value: string(3) "UyC" string(11) "0A:55:00:E0" string(11) "0A:55:00:01"

The new things is the output of snmpwalk is different. And ‘Hex-‘ you put in front of the value read during a snmpget! I will be surprise that has no effect on other part of Cacti, or on plugin !!

And I find the issue and it has nothing to do with cacti, but the way it’s working on net-snmp (I have the answer from a guy on net-snmp mailing list). I don't see anything wrong. The first variable is shown as a printable string and the other two variables are shown as their corresponding hex values.

That's probably occurring because the first value is completly printable, so its shown as the string, but the other two values contain unprintable characters, so they are shown as their hex equivalents instead.

If you want strings shown in hex, try the -Ox option on your commands.

And since my first variable is only made of character higher than 30 it’s is printable, so it does, but the next 2 a made of 00, and it’s is displayed as hex.

So is their anyway I can add the option –Ox in some cacti snmp_get or snmp_walk query ?

Thanks

Arno

On 25 Feb 2017, at 01:58, Jimmy Conner notifications@github.com wrote:

If you are trying to get a data point that is not numeric or needs special cleanup, you should use the raw function. The normal get function will always try to convert to a numeric value. In the case of Hex Strings, it will attempt to convert hard to a number by converting those hex values to their numeric equivalent. So, the raw function is what you should get if you are trying to get some string or hex value and do the cleanup from there. I don't think I'll attempt to improve things more than that.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.