Configuring SNMPv3 for HP Printer

CheckMk: 2.3.0p14
OS: SLES 15 SP5

Hello,

i found several old topics discussing the configuration of snmpv3 for HP Printers in checkmk. But none of them have the necessary information I need.

Fehlender Context bei SNMPv3 Check bei HP Druckern
SNMPv3 Context printer
BUG: SNMP v3 with HP printer - any update or even better a solution?

I configured everything as in these posts and got it partly to working. Problem is that it seems even in CheckMk 2.3 the discovery still does not use the specified SNMP context for the detection of the system description.
Without the system descripten checkmk wont detect the printer snmp sections, wich is the information we want to monitor.

Context rule in wato:


Resulting code in config file:

Based on the output of

cmk -vvvvv --debug --check-discovery printer1

I identified the function that are executed to get the system discription and have gone throught the code starting from

/omd/sites/[site]/lib/python3/cmk/fetchers/_snmpscan.py

until i got to the function that actually defines the get for the snmp backend and creates the netsnmp session in

/omd/sites/MDC_Nagios/lib/python3/cmk/fetchers/cee/snmp_backend/inline.py

Maybe I read the the code at some point wrong but the snmpv3 context defined in the rule should be used even for the system description OID in the service discovery scan.

Anyone got an idea how I get it to work, or do I really have to create custom snmp check for the HP printer?

I would say - no - the context is only used if a section name is provided. The call for system description OID is without any section name and so the context rules defined will not match.
This is a really old bug - something for @martin.hirschvogel :wink:

You are absolutely right. I am pretty new to python and did not know that python considers None as a boolean false. Now the behaviour makes sense.

I already have some Ideas how to make it work, but that would require some minor changes to the context rule, the _snmpscan.py and snmplib/_typedef.py.
But it all is based on the assumption that the SectionName passed to “get_single_oid” in can be just a string.

I think one of the better contacts for this specific problem is someone like @moritz, if not he, then he knows the right people :slight_smile:

Yeah, I guess I am the right people. Unfortunately I’m the right people for a lot of stuff :smiley: .
This bug is quite old indeed – I think it was already quite old when I joined the “Mathias Kettner GmbH” back in the days. But was never really aware of it.
I’ve added in internal ticket for this (link for colleagues: CMK-19986).
But don’t get your hopes up…

If it helps to fix the problem in an official build. I have managed to adjust everything so that a SNMPv3 context can also be stored for the system description OID and it works. However, there are probably still optimization and improvement possibilities.

I changed the following things

/omd/sites/[site]/lib/python3/cmk/fetchers/_snmpscan.py

_prefetch_description_object

get_single_oid(
oid,
single_oid_cache=snmp_cache.single_oid_cache(),
backend=backend,
)

to

get_single_oid(
oid,
single_oid_cache=snmp_cache.single_oid_cache(),
section_name=SectionName(“sys_descr”),
backend=backend,
)

/omd/sites/[site]/lib/python3/cmk/base/automations/check_mk.py

_execute_snmp

data = get_snmp_table(
section_name=None,
tree=BackendSNMPTree(
base=“.1.3.6.1.2.1.1”,
oids=[BackendOIDSpec(c, “string”, False) for c in “1456”],
),
walk_cache={},
backend=make_snmp_backend(snmp_config, log.logger),
)

to

data = get_snmp_table(
section_name=SectionName(“sys_descr”),
tree=BackendSNMPTree(
base=“.1.3.6.1.2.1.1”,
oids=[BackendOIDSpec(c, “string”, False) for c in “1456”],
),
walk_cache={},
backend=make_snmp_backend(snmp_config, log.logger),
)

/omd/sites/[site]/lib/python3/cmk/gui/wato/_check_mk_configuration.py

_valuespec_snmpv3_contexts

choices=lambda: [(None, _(“All SNMP sections”))] + get_snmp_section_names()

to

choices=lambda: [(None, _(“All SNMP sections”))] + [(“sys_descr”, _(“System Description OID”))] + get_snmp_section_names()

/omd/sites/[site]/lib/python3/cmk/snmplib/_typedefs.py

snmpv3_contexts_of

inserted additional variable

var_sysoid_section=SectionName(“sys_descr”)

and changed

if ctx.section is None or ctx.section == section_name:

to

if (ctx.section is None and section_name != var_sysoid_section) or (ctx.section is not None and ctx.section == section_name):

I tried to change the condition in snmpv3_contexts_of in a way, that will not break the old behavior of the context rules that use “All SNMP Sections”. This way a context for the system description oid will only be used if a rule for that section is present like this:

These changes have no effect on SNMPv1 or SNMPv2 since they dont use context. And for SNMP3 it only adds the option to define a context for the system description but the rest should still work the same way. At least on my system i can not find any problems with the systems that use snmpv3 without a context.

In order for the HP printers to monitor reliably with snmpv3, I had to create the rules from this answer
https://forum.checkmk.com/t/bug-snmp-v3-with-hp-printer-any-update-or-even-better-a-solution/20372/12

Hi there,
I may have good news for you: I looked into this problem and created a fix.

For more details see: Werk #18341: snmplib: Always use SNMPv3 contexts in requests

Really thanks for that.
hust installed the patch and as expected it works.