Cacti: SNMP Issues on recent version of PHP

Created on 9 Apr 2020  路  12Comments  路  Source: Cacti/cacti

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:

https://github.com/Cacti/cacti/blob/812bb8df1656bd06580fadc5cf5ddd9a2752ac0e/lib/snmp.php#L138-L142

bug confirmed resolved

All 12 comments

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

This device has the SNMP Timeout timeout set to 2500:

image

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.

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

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:
https://github.com/Cacti/cacti/blob/9284bdd0b42112b199a98cd3476e92744637792b/lib/snmp.php#L127-L129 This would make it easier to debug possible (future) problems.

Fantastic work. Feel free to create a pull request!

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

Or should I open another issue for that?

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

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

@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".

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

Was this page helpful?
0 / 5 - 0 ratings