Skip to content

Add snmp_init_mib function to allow MIB tree to be reset using environment variables#21452

Draft
eskyuu wants to merge 2 commits intophp:masterfrom
eskyuu:snmp-init-mib
Draft

Add snmp_init_mib function to allow MIB tree to be reset using environment variables#21452
eskyuu wants to merge 2 commits intophp:masterfrom
eskyuu:snmp-init-mib

Conversation

@eskyuu
Copy link

@eskyuu eskyuu commented Mar 15, 2026

I have been trying to use the PHP SNMP extension in LibreNMS to replace calls to external snmp* programs. One issue I have come across is that there is no way to clear the MIB tree in the PHP SNMP extension. It becomes even worse with PHP-FPM where the MIB tree is persistent across different requests.

The above causes issues when a script wants to do multiple SNMP queries against incompatible MIBs because there is currently no way to clear the MIB tree and start again.

This PR add a new snmp_init_mib() function that frees up the existing MIB tree and then calls init_mib(), which will:

  • Set the MIB directories according to the MIBDIRS environment variable
  • Load MIBs according to the MIBS environment variable (plus any IMPORTs)
  • Load MIB files according to the MIBFILES variable

I have chosen to only expose the one function above because the other functions like shutdown_mib(), init_mib_internals() netsnmp_read_module() require understanding how the net-snmp internals work to ensure everything is initialised properly. The proposed function can be used to clear the MIB tree back to the default state if the environment variables are not changed, or to reset to a known state if the environment variables are updated.

It's marked as draft until I have tested that it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants