Retrieve multiple independent SNMP areas

Hi there,

I looked this up in the CheckMK Documentation before but unfortunately they didn’t add it yet.
Is there any way to retrieve multiple independent SNMP areas with one “register.snmp_section()” statement?

Thank you,
Lou1s

Yes there is. A small example follows.

register.snmp_section(
    name="cmciii",
    detect=contains(".1.3.6.1.2.1.1.2.0", ".1.3.6.1.4.1.2606.7"),
    fetch=[
        SNMPTree(
            base=".1.3.6.1.4.1.2606.7.4.1.2.1",
            oids=[
                OIDEnd(),
                "2",  # RITTAL-CMC-III-MIB::cmcIIIDevName
                "3",  # RITTAL-CMC-III-MIB::cmcIIIDevAlias
                "6",  # RITTAL-CMC-III-MIB::cmcIIIDevStatus
            ],
        ),
        SNMPTree(
            base=".1.3.6.1.4.1.2606.7.4.2.2.1",
            oids=[
                OIDEnd(),
                "3",  # RITTAL-CMC-III-MIB::cmcIIIVarName
                "4",  # RITTAL-CMC-III-MIB::cmcIIIVarType
                "5",  # RITTAL-CMC-III-MIB::cmcIIIVarUnit
                "7",  # RITTAL-CMC-III-MIB::cmcIIIVarScale
                "10",  # RITTAL-CMC-III-MIB::cmcIIIVarValueStr
                "11",  # RITTAL-CMC-III-MIB::cmcIIIVarValueInt
            ],
        ),
    ],
    parse_function=parse_cmciii,
)
1 Like

@andreas-doehler Thanks for the quick answer and solution!

@andreas-doehler I just got the error “value of ‘fetch’ keyword must be SNMPTree or non-empty list of SNMPTrees”. Is there anything that I have to import or adjust in comparison to the “normal” SNMP-Plugin process?

Thank you!

you might need to change the parse function a bit. To stay with @andreas-doehler example this sould change from (for a single SNMPTree):

def parse_cmciii(string_table: StringByteTable):

to (for a list of SNMPTrees):

from typing import List

def parse_cmciii(string_table: List[StringByteTable]):

@thl-cmk Thank you for the answer. Is “StringByteTable” a type which is pre implemented by checkmk? Because now I get the error “name ‘StringByteTable’ is not defined”.

it is, but I see this is my error, leave the Byte out of StringByteTable :wink: . This is a special version of StringTable that will be used with OIDBytes in the SNMPTree. Both versions of string_table can be imported like this

from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import (
    StringByteTable,
    StringTable,
)

@thl-cmk No problem :slight_smile: After importing the StringTable I still get the error for the fetch: “value of ‘fetch’ keyword must be SNMPTree or non-empty list of SNMPTrees”. Do I have to change something in consideration to the assignment of the fetch variable?

can you post your register.snmp_section here?

@thl-cmk Here it is:

register.snmp_section(
        name="wago_750_881",
        parse_function=parse_wago_750_881,
        detect=contains(".1.3.6.1.2.1.1.1.0", "WAGO 750-881"),
        fetch=[
            SNMPTree(
                base=".1.3.6.1.2.1.1",
                oids=[
                    OIDEnd(),
                    "3.0", 
                ],
            ),
            SNMPTree(
                base=".1.3.6.1.2.1.4",
                oids=[
                    OIDEnd(),
                    "3.0",  
                    "4.0",  
                    "5.0",  
                    "6.0",  
                    "7.0",  
                    "8.0",  
                    "9.0",  
                    "10.0", 
                    "11.0", 
                    "12.0", 
                ],
            ),
        ],
    )

looks ok, have just completed it with the rest of a very basic check and it works. So your issue is not with the register.snmp_section

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from typing import List
from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import (
    DiscoveryResult,
    CheckResult,
    StringTable,
)

from cmk.base.plugins.agent_based.agent_based_api.v1 import (
    register,
    Service,
    Result,
    State,
    SNMPTree,
    contains,
    OIDEnd,
)


def parse_wago_750_881(string_table: List[StringTable]):
    print(string_table)  # for debugging only
    return string_table


def discovery_wago_750_881(section) -> DiscoveryResult:
    yield Service()


def check_wago_750_881(section) -> CheckResult:
    yield Result(state=State.UNKNOWN, summary='Not yet implemented')


register.snmp_section(
    name="wago_750_881",
    parse_function=parse_wago_750_881,
    detect=contains(".1.3.6.1.2.1.1.1.0", "WAGO 750-881"),  # replaced with 'cisco'
    fetch=[
        SNMPTree(
            base=".1.3.6.1.2.1.1",
            oids=[
                OIDEnd(),
                "3.0",
            ],
        ),
        SNMPTree(
            base=".1.3.6.1.2.1.4",
            oids=[
                OIDEnd(),
                "3.0",
                "4.0",
                "5.0",
                "6.0",
                "7.0",
                "8.0",
                "9.0",
                "10.0",
                "11.0",
                "12.0",
            ],
        ),
    ],
)

register.check_plugin(
    name='wago_750_881',
    service_name='Wago',
    discovery_function=discovery_wago_750_881,
    check_function=check_wago_750_881,
)

a sample cmk -vII

OMD[build]:~$ cmk -vII --debug testdevice
Discovering services and host labels on: testdevice
testdevice:
+ FETCHING DATA
[SNMPFetcher] Execute data source
No piggyback files for 'testdevice'. Skip processing.
No piggyback files for 'simulant.home.intern'. Skip processing.
[PiggybackFetcher] Execute data source
+ ANALYSE DISCOVERED HOST LABELS
[[['', '29485498']], [['', '60314567', '15', '0', '41447733', '0', '0', '2300700', '2031809', '8', '337']]]
SUCCESS - Found no host labels
+ ANALYSE DISCOVERED SERVICES
+ EXECUTING DISCOVERY PLUGINS (9)
  1 wago_750_881
SUCCESS - Found 1 services
OMD[build]:~$

a sample cmk -v

OMD[build]:~$ cmk -v --debug testdevice
+ FETCHING DATA
[SNMPFetcher] Execute data source
No piggyback files for 'testdevice''. Skip processing.
No piggyback files for 'simulant.home.intern'. Skip processing.
[PiggybackFetcher] Execute data source
[[['', '29485498']], [['', '60314567', '15', '0', '41447733', '0', '0', '2300700', '2031809', '8', '337']]]
Wago                 Not yet implemented
No piggyback files for 'testdevice'. Skip processing.
[snmp] Success, [piggyback] , execution time 0.4 sec | execution_time=0.370 user_time=0.130 system_time=0.040 children_user_time=0.000 children_system_time=0.000

as you can see CMK will fetch your OIDs and creates the service Wago. The only thing I have changed on your section is replacing WAGO 750-881 by cisco as I don’t have a WAGO device for testing.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.