Cacti / cacti

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

Poller and snmp_version = '2' #80

Closed interduo closed 7 years ago

interduo commented 7 years ago

Poller doesn't work properly when we choose in host snmp version = 2.

The poller tries to run snmpwalk with -v 2 parameter. Snmpwalk doesn't have -v2. There is -v 2c!

Please correct this mistake.

Mal2012 commented 7 years ago

The PHP Poller uses the functions from php7-snmp / php5-snmp: For SNMP v2c it uses snmp2_get

I can't see any Problems in /lib/snmp.php and it is working for my setup.

Maybe the error is in your php5/7-snmp version.

interduo commented 7 years ago

I've updated php5-snmp from 5.6.27+dfsg-0+deb8u1 to 5.6.28+dfsg-0+deb8u1. The problem does exist.

From poller-error.log:

Invalid version specified after -v flag: 2 USAGE: snmpwalk [OPTIONS] AGENT [OID]

Version: 5.7.2.1 Web: http://www.net-snmp.org/ Email: net-snmp-coders@lists.sourceforge.net

OPTIONS: -h, --help display this help message -H display configuration file directives understood -v 1|2c|3 specifies SNMP version to use -V, --version display package version number SNMP Version 1 or 2c specific -c COMMUNITY set the community string SNMP Version 3 specific -a PROTOCOL set authentication protocol (MD5|SHA) -A PASSPHRASE set authentication protocol pass phrase -e ENGINE-ID set security engine ID (e.g. 800000020109840301) -E ENGINE-ID set context engine ID (e.g. 800000020109840301) -l LEVEL set security level (noAuthNoPriv|authNoPriv|authPriv) -n CONTEXT set context name (e.g. bridge1) -u USER-NAME set security name (e.g. bert) -x PROTOCOL set privacy protocol (DES|AES) -X PASSPHRASE set privacy protocol pass phrase -Z BOOTS,TIME set destination engine boots/time General communication options -r RETRIES set the number of retries -t TIMEOUT set the request timeout (in seconds) Debugging -d dump input/output packets in hexadecimal -D[TOKEN[,...]] turn on debugging output for the specified TOKENs (ALL gives extremely verbose debugging output)

I think there is a problem with /lib/snmp.php line:117 (?)

how to diagnose that? how to turn debug mode for snmp function?

interduo commented 7 years ago

2016-12-13 16:00:08 - CMDPHP PHP ERROR Backtrace: (CactiShutdownHandler)(/lib/functions.php: 4203 cacti_debug_backtrace) 2016-12-13 16:00:08 - ERROR PHP ERROR: Call to undefined method SNMP::set_security() in file: /var/www/html/cacti/lib/snmp.php on line: 78

I've found something like that also in my logs. But I don't know what host did that error.

cigamit commented 7 years ago

It really seems that php-snmp is having issue on your Cacti server. If you are getting that "undefined method" error, it would be your Cacti server causing it. That method has been in php since 5.4.

http://us.php.net/manual/en/snmp.setsecurity.php

The other strange part is that you shouldn't even be getting to that section of code unless you are using SNMP v3 on a host (or your php-snmp is messed up)

interduo commented 7 years ago

The error is generated by: [Unix - Count Oids] 'https://cacti/data_input.php?action=edit&id=13'

And the input field: /usr/bin/snmpwalk <ip> -v <ver> -c <comm> <oid> | /bin/wc -l | /bin/awk \'{printf$0}\'

There is pasted <ver> = 2 instead of <ver> = 2c

How and where to change that or add the condition?

cigamit commented 7 years ago

Can you please create a pull request? You setup seems to have php-snmp not installed. In either case, a pull request is the easy fix.

cigamit commented 7 years ago

Also, please post:

1) OS and version 2) php --version 3) php -m

Thanks

interduo commented 7 years ago
  1. Debian Stable (Jessie)
  2. php --version PHP 5.6.29-0+deb8u1 (cli) (built: Dec 13 2016 16:02:08)
  3. php -m [PHP Modules] bcmath bz2 calendar Core ctype date dba dom ereg exif fileinfo filter ftp gd gettext hash iconv json ldap libxml mbstring mcrypt mhash mysql mysqli openssl pcntl pcre PDO pdo_mysql Phar posix readline Reflection session shmop SimpleXML snmp soap sockets SPL standard sysvmsg sysvsem sysvshm tokenizer wddx xml xmlreader xmlwriter Zend OPcache zip zlib

[Zend Modules] Zend OPcache

I cannot do a pull request because I don't know where is the problem.

cigamit commented 7 years ago

Okay, after giving this some thought, it is clear that the data input method is coded incorrectly. Cacti has a special type code snmp_version that provides a numeric version 1,2,3, it is upto the script to alter that to a compatible format.

So, calling snmpwalk directly from the input string is not recommended. What should be done instead is to write a simple countoids.sh shell script and call that instead. Inside that script you can translate 2 to 2c.

There are possibly other issues, for example the undefined method is an interesting bug, but you may want to open that separately if it continues to happen.

Once you make the change to the Data Input Method, it would be good to update the author on that change, or if it exists in the DocoWiki, make a note there.

cigamit commented 7 years ago

Going to close this for now. If the other bug re-occurs, just let us know.