Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNMP Issues on recent version of PHP #3447

Closed
nuno-silva opened this issue Apr 9, 2020 · 12 comments
Closed

SNMP Issues on recent version of PHP #3447

nuno-silva opened this issue Apr 9, 2020 · 12 comments
Labels
bug Undesired behaviour confirmed Bug is confirm by dev team resolved A fixed issue
Milestone

Comments

@nuno-silva
Copy link
Contributor

Describe the bug

I have the following errors/warnings showing up on one of my SNMPv2 devices:

2020/04/09 16:41:38 - CMDPHP WARNING: SNMP Error:'', Device:'10.0.0.113', OID:'.1.3.6.1.4.1.2021.4.15.0'
2020/04/09 16:41:38 - CMDPHP PHP ERROR WARNING Backtrace: (/scripts/ss_netsnmp_memory.php[53]:ss_netsnmp_memory(), /scripts/ss_netsnmp_memory.php[295]:cacti_snmp_get(), /lib/snmp.php[141]:snmp2_get(), CactiErrorHandler())
2020/04/09 16:41:38 - ERROR PHP WARNING: snmp2_get() expects parameter 4 to be integer, float given in file: /var/www/cacti/htdocs/cacti/lib/snmp.php on line: 141
2020/04/09 16:41:38 - CMDPHP WARNING: SNMP Error:'', Device:'10.0.0.113', OID:'.1.3.6.1.4.1.2021.4.14.0'
2020/04/09 16:41:38 - CMDPHP PHP ERROR WARNING Backtrace: (/scripts/ss_netsnmp_memory.php[53]:ss_netsnmp_memory(), /scripts/ss_netsnmp_memory.php[295]:cacti_snmp_get(), /lib/snmp.php[141]:snmp2_get(), CactiErrorHandler())
2020/04/09 16:41:38 - ERROR PHP WARNING: snmp2_get() expects parameter 4 to be integer, float given in file: /var/www/cacti/htdocs/cacti/lib/snmp.php on line: 141
2020/04/09 16:41:38 - CMDPHP WARNING: SNMP Error:'', Device:'10.0.0.113', OID:'.1.3.6.1.4.1.2021.4.4.0'
2020/04/09 16:41:38 - CMDPHP PHP ERROR WARNING Backtrace: (/scripts/ss_netsnmp_memory.php[53]:ss_netsnmp_memory(), /scripts/ss_netsnmp_memory.php[295]:cacti_snmp_get(), /lib/snmp.php[141]:snmp2_get(), CactiErrorHandler())
2020/04/09 16:41:38 - ERROR PHP WARNING: snmp2_get() expects parameter 4 to be integer, float given in file: /var/www/cacti/htdocs/cacti/lib/snmp.php on line: 141
2020/04/09 16:41:38 - CMDPHP WARNING: SNMP Error:'', Device:'10.0.0.113', OID:'.1.3.6.1.4.1.2021.4.3.0'
2020/04/09 16:41:38 - CMDPHP PHP ERROR WARNING Backtrace: (/scripts/ss_netsnmp_memory.php[53]:ss_netsnmp_memory(), /scripts/ss_netsnmp_memory.php[295]:cacti_snmp_get(), /lib/snmp.php[141]:snmp2_get(), CactiErrorHandler())
2020/04/09 16:41:38 - ERROR PHP WARNING: snmp2_get() expects parameter 4 to be integer, float given in file: /var/www/cacti/htdocs/cacti/lib/snmp.php on line: 141
2020/04/09 16:41:38 - CMDPHP WARNING: SNMP Error:'', Device:'10.0.0.113', OID:'.1.3.6.1.4.1.2021.4.6.0'
2020/04/09 16:41:38 - CMDPHP PHP ERROR WARNING Backtrace: (/scripts/ss_netsnmp_memory.php[53]:ss_netsnmp_memory(), /scripts/ss_netsnmp_memory.php[295]:cacti_snmp_get(), /lib/snmp.php[141]:snmp2_get(), CactiErrorHandler())
2020/04/09 16:41:38 - ERROR PHP WARNING: snmp2_get() expects parameter 4 to be integer, float given in file: /var/www/cacti/htdocs/cacti/lib/snmp.php on line: 141
2020/04/09 16:41:38 - CMDPHP WARNING: SNMP Error:'', Device:'10.0.0.113', OID:'.1.3.6.1.2.1.25.2.2.0'
2020/04/09 16:41:38 - CMDPHP PHP ERROR WARNING Backtrace: (/scripts/ss_netsnmp_memory.php[53]:ss_netsnmp_memory(), /scripts/ss_netsnmp_memory.php[295]:cacti_snmp_get(), /lib/snmp.php[141]:snmp2_get(), CactiErrorHandler())
2020/04/09 16:41:38 - ERROR PHP WARNING: snmp2_get() expects parameter 4 to be integer, float given in file: /var/www/cacti/htdocs/cacti/lib/snmp.php on line: 141

To Reproduce

Steps to reproduce the behaviour:

  1. Create a device using SNMPv1 or v2
  2. Wait for poller to run
  3. See ERROR in cacti log

Expected behavior

Expected no warnings or errors.

Additional context

Using:

  • Cacti version 1.2.11 with cmd.php poller
  • PHP Version 7.2.29 (Linux)

Affected lines:

cacti/lib/snmp.php

Lines 138 to 142 in 812bb8d

if ($version == '1') {
$snmp_value = snmpget($hostname . ':' . $port, $community, $oid, ($timeout * 1000), $retries);
} elseif ($version == '2') {
$snmp_value = snmp2_get($hostname . ':' . $port, $community, $oid, ($timeout * 1000), $retries);
} else {

@nuno-silva nuno-silva added bug Undesired behaviour unverified Some days we don't have a clue labels Apr 9, 2020
@netniV
Copy link
Member

netniV commented Apr 9, 2020

That would suggest you've put a non integer timeout against a device?

@nuno-silva
Copy link
Contributor Author

This device has the SNMP Timeout timeout set to 2500:

image

@TheWitness
Copy link
Member

This is all about tight type casting in more recent php's I think. Depending of API or CLI, we are either dividing by 1000 (CLI) or multiplying (API). Looks like in 7.2.x they are converting to a float when multiplying. Almost feels like a php but.

@TheWitness TheWitness changed the title ERROR PHP WARNING: snmp2_get() expects parameter 4 to be integer, float given in file: /var/www/cacti/htdocs/cacti/lib/snmp.php on line: 141 SNMP Issues on recent versionf of PHP Apr 10, 2020
@TheWitness TheWitness changed the title SNMP Issues on recent versionf of PHP SNMP Issues on recent version of PHP Apr 10, 2020
TheWitness added a commit that referenced this issue Apr 10, 2020
SNMP Issues on recent versions of PHP
@TheWitness TheWitness added resolved A fixed issue and removed unverified Some days we don't have a clue labels Apr 10, 2020
@TheWitness
Copy link
Member

Please test on the latest version of lib/snmp.php in the 1.2.x branch. Closed is resolved.

@TheWitness TheWitness added this to the 1.2.12 milestone Apr 10, 2020
@nuno-silva
Copy link
Contributor Author

Thank you for your work.

I applied a1eed00 to the lib/snmp.php file (only) and am just getting these now:

2020/04/11 00:41:46 - CMDPHP WARNING: SNMP Error:'', Device:'10.0.0.113', OID:'.1.3.6.1.4.1.2021.4.15.0'
2020/04/11 00:41:46 - CMDPHP WARNING: SNMP Error:'', Device:'10.0.0.113', OID:'.1.3.6.1.4.1.2021.4.14.0'
2020/04/11 00:41:46 - CMDPHP WARNING: SNMP Error:'', Device:'10.0.0.113', OID:'.1.3.6.1.4.1.2021.4.4.0'
2020/04/11 00:41:46 - CMDPHP WARNING: SNMP Error:'', Device:'10.0.0.113', OID:'.1.3.6.1.4.1.2021.4.3.0'
2020/04/11 00:41:46 - CMDPHP WARNING: SNMP Error:'', Device:'10.0.0.113', OID:'.1.3.6.1.4.1.2021.4.6.0'
2020/04/11 00:41:46 - CMDPHP WARNING: SNMP Error:'', Device:'10.0.0.113', OID:'.1.3.6.1.2.1.25.2.2.0'

That's probably another issue.

However, if I remove the error suppression (@) you added to the snmp2_get calls, I still get these:

2020/04/11 01:41:40 - CMDPHP PHP ERROR WARNING Backtrace: (/scripts/ss_netsnmp_memory.php[53]:ss_netsnmp_memory(), /scripts/ss_netsnmp_memory.php[295]:cacti_snmp_get(), /lib/snmp.php[145]:snmp2_get(), CactiErrorHandler())
2020/04/11 01:41:40 - ERROR PHP WARNING: snmp2_get() expects parameter 4 to be integer, float given in file: /var/www/cacti/htdocs/cacti/lib/snmp.php on line: 145
2020/04/11 01:41:40 - CMDPHP WARNING: SNMP Error:'', Device:'10.0.0.113', OID:'.1.3.6.1.4.1.2021.4.14.0'
2020/04/11 01:41:40 - CMDPHP PHP ERROR WARNING Backtrace: (/scripts/ss_netsnmp_memory.php[53]:ss_netsnmp_memory(), /scripts/ss_netsnmp_memory.php[295]:cacti_snmp_get(), /lib/snmp.php[145]:snmp2_get(), CactiErrorHandler())
2020/04/11 01:41:40 - ERROR PHP WARNING: snmp2_get() expects parameter 4 to be integer, float given in file: /var/www/cacti/htdocs/cacti/lib/snmp.php on line: 145
2020/04/11 01:41:40 - CMDPHP WARNING: SNMP Error:'', Device:'10.0.0.113', OID:'.1.3.6.1.4.1.2021.4.4.0'
2020/04/11 01:41:40 - CMDPHP PHP ERROR WARNING Backtrace: (/scripts/ss_netsnmp_memory.php[53]:ss_netsnmp_memory(), /scripts/ss_netsnmp_memory.php[295]:cacti_snmp_get(), /lib/snmp.php[145]:snmp2_get(), CactiErrorHandler())
2020/04/11 01:41:40 - ERROR PHP WARNING: snmp2_get() expects parameter 4 to be integer, float given in file: /var/www/cacti/htdocs/cacti/lib/snmp.php on line: 145
2020/04/11 01:41:40 - CMDPHP WARNING: SNMP Error:'', Device:'10.0.0.113', OID:'.1.3.6.1.4.1.2021.4.3.0'
2020/04/11 01:41:40 - CMDPHP PHP ERROR WARNING Backtrace: (/scripts/ss_netsnmp_memory.php[53]:ss_netsnmp_memory(), /scripts/ss_netsnmp_memory.php[295]:cacti_snmp_get(), /lib/snmp.php[145]:snmp2_get(), CactiErrorHandler())
2020/04/11 01:41:40 - ERROR PHP WARNING: snmp2_get() expects parameter 4 to be integer, float given in file: /var/www/cacti/htdocs/cacti/lib/snmp.php on line: 145
2020/04/11 01:41:40 - CMDPHP WARNING: SNMP Error:'', Device:'10.0.0.113', OID:'.1.3.6.1.4.1.2021.4.6.0'
2020/04/11 01:41:40 - CMDPHP PHP ERROR WARNING Backtrace: (/scripts/ss_netsnmp_memory.php[53]:ss_netsnmp_memory(), /scripts/ss_netsnmp_memory.php[295]:cacti_snmp_get(), /lib/snmp.php[145]:snmp2_get(), CactiErrorHandler())
2020/04/11 01:41:40 - ERROR PHP WARNING: snmp2_get() expects parameter 4 to be integer, float given in file: /var/www/cacti/htdocs/cacti/lib/snmp.php on line: 145
2020/04/11 01:41:40 - CMDPHP WARNING: SNMP Error:'', Device:'10.0.0.113', OID:'.1.3.6.1.2.1.25.2.2.0'
2020/04/11 01:41:40 - CMDPHP PHP ERROR WARNING Backtrace: (/scripts/ss_netsnmp_memory.php[53]:ss_netsnmp_memory(), /scripts/ss_netsnmp_memory.php[295]:cacti_snmp_get(), /lib/snmp.php[145]:snmp2_get(), CactiErrorHandler())
2020/04/11 01:41:40 - ERROR PHP WARNING: snmp2_get() expects parameter 4 to be integer, float given in file: /var/www/cacti/htdocs/cacti/lib/snmp.php on line: 145

This suggests the issue is not resolved, just silenced :/

My guess is that in $timeout = (int) $timeout * 1000; the (int) conversion takes precedence over the multiplication. I tested it like this and it worked: $timeout = (int) ($timeout * 1000);.

So, my suggestion is to change the parentheses to $timeout = (int) ($timeout * 1000); and remove the error suppression (@) as these don't do any good. I can do a pull request if you prefer. Let me know.

By the way, with the SNMP Timeout set to 2500 (milliseconds) in the GUI, the timeout value I'm getting for this device in the cacti_snmp_get function, before the multiplication, is 2500000, so it was already converted to microseconds somewhere else? After the multiplication I get 2500000000. Can you confirm this? Maybe this is also a separate issue. For reference, the snmp2_get function already expects the timeout value to be in microseconds.


On an unrelated note, it wouldn't hurt to issue a warning when cacti_snmp_options_sanitize fails instead of just silently returning an invalid value, e.g. here:

cacti/lib/snmp.php

Lines 127 to 129 in 9284bdd

if (!cacti_snmp_options_sanitize($version, $community, $port, $timeout, $retries, $max_oids)) {
return 'U';
}
This would make it easier to debug possible (future) problems.

@TheWitness
Copy link
Member

Fantastic work. Feel free to create a pull request!

@nuno-silva
Copy link
Contributor Author

Alright. Can you just confirm the units on the timeout variable, please?

@nuno-silva
Copy link
Contributor Author

Or should I open another issue for that?

@TheWitness
Copy link
Member

php-snmp is microseconds, net-snmp-utils are seconds, and cacti store in milliseconds.

@TheWitness
Copy link
Member

@nuno-silva, how's that pull request coming along?

TheWitness added a commit that referenced this issue Apr 20, 2020
Handling the casting correctly now.
@nuno-silva
Copy link
Contributor Author

@TheWitness Sorry, work got in the way, but I see you already fixed the parentheses.

I will still try to look into this and I'll open a pull request if I do find that something needs be fixed:

By the way, with the SNMP Timeout set to 2500 (milliseconds) in the GUI, the timeout value I'm getting for this device in the cacti_snmp_get function, before the multiplication, is 2500000, so it was already converted to microseconds somewhere else? After the multiplication I get 2500000000. Can you confirm this? Maybe this is also a separate issue. For reference, the snmp2_get function already expects the timeout value to be in microseconds.

This would be a new issue anyway; it's probably not related to a "recent version of PHP".

@netniV
Copy link
Member

netniV commented Apr 27, 2020

I have no idea where you found that issue * whistles *

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Undesired behaviour confirmed Bug is confirm by dev team resolved A fixed issue
Projects
None yet
Development

No branches or pull requests

3 participants