centreon / centreon-plugins

Collection of standard plugins to discover and gather cloud-to-edge metrics and status across your whole IT infrastructure.
https://www.centreon.com
Apache License 2.0
310 stars 273 forks source link

[apps::protocols::snmp::plugin] snmp collection mode cannot parse oid leef with constant #4910

Open Luth1ng opened 6 months ago

Luth1ng commented 6 months ago

Quick description

I cannot use constant in snmp leef oid with snmp collection mode

How to reproduce

Try to replace an OID with a constant

Expected result

with this json file :

{
        "mapping": {},
        "constants": {
                "ifIndex": "167837696"
        },
        "snmp": {
                "leefs": [
                        {
                                "name": "opticalIfLaserTxPower",
                                "oid": ".1.3.6.1.4.1.4746.2.6.1.2.1.2.167837696"
                        }
                ]
        },
        "selection": [
                {
                        "name": "myLeefs1",
                        "expand": {
                                "leefvalue": "%(snmp.leefs.opticalIfLaserTxPower)"
                        },
                        "formatting": {
                                "printf_msg": "Status is %s.",
                                "printf_var": [
                                        "%(leefvalue)"
                                ],
                                "display_ok": true
                        }
                }
        ],
        "selection_loop": [],
        "formatting": {}
}

result is : OK: Status is -24. .1.3.6.1.4.1.4746.2.6.1.2.1.2.167837696 = -24

Actual result

With this json file :

{
        "mapping": {},
        "constants": {
                "ifIndex": "167837696"
        },
        "snmp": {
                "leefs": [
                        {
                                "name": "opticalIfLaserTxPower",
                                "oid": ".1.3.6.1.4.1.4746.2.6.1.2.1.2.[%(constants.ifIndex)]"
                        }
                ]
        },
        "selection": [
                {
                        "name": "myLeefs1",
                        "expand": {
                                "leefvalue": "%(snmp.leefs.opticalIfLaserTxPower)"
                        },
                        "formatting": {
                                "printf_msg": "Status is %s.",
                                "printf_var": [
                                        "%(leefvalue)"
                                ],
                                "display_ok": true
                        }
                }
        ],
        "selection_loop": [],
        "formatting": {}
}

Result is :

OK: Status is . ======> variables Status is .

Questions

My goal here is to call a json find to check a particular OID with an input parameter. I don't want to request all the table and filter with this OID.

I know I could use the table and filter the oid with a selection_loop, but I would like to minimize the SNMP requests sent to the equipment.

How can I achieve this ?

omercier commented 4 months ago

Hi @Luth1ng, I have recently faced the exact same limitation and at the moment I see no reason why we wouldn't support it. We'll try to improve that.