Skip to main content

Hello,
I want to use NET-SNMP-EXTEND-MIB to monitor systemctl services.
I added these two lines in the snmpd configuration:

extend 1 /usr/bin/systemctl is-active centengine.service
extend 2 /usr/bin/systemctl is-active gorgoned.service

 

When I query the MIB with snmpwalk, I get this:

# snmpwalk -v 2c 127.0.0.1 -c public .1.3.6.1.4.1.8072.1.3.2
NET-SNMP-EXTEND-MIB::nsExtendNumEntries.0 = INTEGER: 2
NET-SNMP-EXTEND-MIB::nsExtendCommand."1" = STRING: /usr/bin/systemctl
NET-SNMP-EXTEND-MIB::nsExtendCommand."2" = STRING: /usr/bin/systemctl
NET-SNMP-EXTEND-MIB::nsExtendArgs."1" = STRING: is-active centengine.service
NET-SNMP-EXTEND-MIB::nsExtendArgs."2" = STRING: is-active gorgoned.service
NET-SNMP-EXTEND-MIB::nsExtendInput."1" = STRING:
NET-SNMP-EXTEND-MIB::nsExtendInput."2" = STRING:
NET-SNMP-EXTEND-MIB::nsExtendCacheTime."1" = INTEGER: 5
NET-SNMP-EXTEND-MIB::nsExtendCacheTime."2" = INTEGER: 5
NET-SNMP-EXTEND-MIB::nsExtendExecType."1" = INTEGER: exec(1)
NET-SNMP-EXTEND-MIB::nsExtendExecType."2" = INTEGER: exec(1)
NET-SNMP-EXTEND-MIB::nsExtendRunType."1" = INTEGER: run-on-read(1)
NET-SNMP-EXTEND-MIB::nsExtendRunType."2" = INTEGER: run-on-read(1)
NET-SNMP-EXTEND-MIB::nsExtendStorage."1" = INTEGER: permanent(4)
NET-SNMP-EXTEND-MIB::nsExtendStorage."2" = INTEGER: permanent(4)
NET-SNMP-EXTEND-MIB::nsExtendStatus."1" = INTEGER: active(1)
NET-SNMP-EXTEND-MIB::nsExtendStatus."2" = INTEGER: active(1)
NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."1" = STRING: active
NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."2" = STRING: active
NET-SNMP-EXTEND-MIB::nsExtendOutputFull."1" = STRING: active
NET-SNMP-EXTEND-MIB::nsExtendOutputFull."2" = STRING: active
NET-SNMP-EXTEND-MIB::nsExtendOutNumLines."1" = INTEGER: 1
NET-SNMP-EXTEND-MIB::nsExtendOutNumLines."2" = INTEGER: 1
NET-SNMP-EXTEND-MIB::nsExtendResult."1" = INTEGER: 0
NET-SNMP-EXTEND-MIB::nsExtendResult."2" = INTEGER: 0
NET-SNMP-EXTEND-MIB::nsExtendOutLine."1".1 = STRING: active
NET-SNMP-EXTEND-MIB::nsExtendOutLine."2".1 = STRING: active

I created my configuration file for the centreon_generic_snmp.pl plugin :

{       
        "mapping": {
                "nsExtendResult": {
                        "0": "Up",
                        "1": "Down"
                }
        },
        "snmp": {
                "tables":
                        {
                        "name": "nsExtendObjects",
                        "oid": ".1.3.6.1.4.1.8072.1.3.2",
                        "used_instance": "\\.(\\d+)$",
                        "entries": ,
                                { "name": "nsExtendResult", "oid": ".1.3.6.1.4.1.8072.1.3.2.3.1.4", "map": "nsExtendResult"},
                                { "name": "nsExtendOutput1Line", "oid": ".1.3.6.1.4.1.8072.1.3.2.3.1.1"},
                                { "name": "nsExtendArgs", "oid": ".1.3.6.1.4.1.8072.1.3.2.2.1.3"}
                        ]
                        }
                ]       
        },
        "selection_loop": {
                "name": "Services",
                "source": "%(snmp.tables.nsExtendObjects)",
                "expand_table": {
                        "nsExtendObjects": "%(snmp.tables.nsExtendObjects%(nsExtendObjects.instance)])"
                },
                "formatting": {
                        "printf_msg": "%s ? :  %s is %s",
                        "printf_var":
                                "%(nsExtendObjects.nsExtendArgs)",
                                "%(nsExtendObjects.nsExtendOutput1Line)",
                                "%(nsExtendObjects.nsExtendResult)"
                        ],
                "display_ok": true
                }
        },
        "formatting": {
        }
}

 

But when I run the following command, I have these errors:

# /usr/lib/centreon/plugins/centreon_generic_snmp.pl --plugin=apps::protocols::snmp::plugin --mode=collection --hostname=127.0.0.1 --snmp-community=public --config=/etc/centreon-engine/collection-config/NET-SNMP-EXTEND-MIB-collection.json --debug --verbose
Use of uninitialized value in sprintf at /usr/lib/centreon/plugins/centreon_generic_snmp.pl line 543.
Use of uninitialized value in sprintf at /usr/lib/centreon/plugins/centreon_generic_snmp.pl line 543.
Use of uninitialized value in sprintf at /usr/lib/centreon/plugins/centreon_generic_snmp.pl line 543.
Use of uninitialized value in sprintf at /usr/lib/centreon/plugins/centreon_generic_snmp.pl line 543.
Use of uninitialized value in sprintf at /usr/lib/centreon/plugins/centreon_generic_snmp.pl line 543.
Use of uninitialized value in sprintf at /usr/lib/centreon/plugins/centreon_generic_snmp.pl line 543.
Use of uninitialized value in sprintf at /usr/lib/centreon/plugins/centreon_generic_snmp.pl line 543.
Use of uninitialized value in sprintf at /usr/lib/centreon/plugins/centreon_generic_snmp.pl line 543.
Use of uninitialized value in sprintf at /usr/lib/centreon/plugins/centreon_generic_snmp.pl line 543.
Use of uninitialized value in sprintf at /usr/lib/centreon/plugins/centreon_generic_snmp.pl line 543.
Use of uninitialized value in sprintf at /usr/lib/centreon/plugins/centreon_generic_snmp.pl line 543.
Use of uninitialized value in sprintf at /usr/lib/centreon/plugins/centreon_generic_snmp.pl line 543.
UNKNOWN: Not an ARRAY reference at /usr/lib/centreon/plugins/centreon_generic_snmp.pl line 1670.

 

Do you have any idea what the problem is?
Thanks

Hi ​@LEBRETON,

The first think that hit me in your output was this error message: Not an ARRAY reference at /usr/lib/centreon/plugins/centreon_generic_snmp.pl line 1670.

It is caused by your definition of selection_loop, that should be an array, not an object (is "selection_loop": p...] not "selection_loop": {...}).

 

Then, since you gave all the information to reproduce your issue (and I thank you a lot for that!) I managed to play with your collection and make it kind of work. It’s not perfect but it collects the data you’re interested in.

 

{
"mapping": {
"nsExtendResult": {
"0": "Up",
"1": "Down"
}
},
"snmp": {
"tables":
{
"name": "nsExtendObjects",
"oid": ".1.3.6.1.4.1.8072.1.3.2",
"used_instance": "\\.a23]\\.1\\.(\\d\\d+)\\.?1?$",
"entries": "
{
"name": "nsExtendResult",
"oid": ".1.3.6.1.4.1.8072.1.3.2.3.1.4.1",
"map": "nsExtendResult"
},
{
"name": "nsExtendOutput1Line",
"oid": ".1.3.6.1.4.1.8072.1.3.2.3.1.1.1"
},
{
"name": "nsExtendArgs",
"oid": ".1.3.6.1.4.1.8072.1.3.2.2.1.3.1"
}
]
}
]
},
"selection_loop": i
{
"name": "Services",
"source": "%(snmp.tables.nsExtendObjects)",
"expand_table": {
"nsExtendObjects": "%(snmp.tables.nsExtendObjects.e%(nsExtendObjects.instance)])"
},
"formatting": {
"printf_msg": "%s ? : %s / %s",
"printf_var": i
"%(nsExtendObjects.nsExtendArgs)",
"%(nsExtendObjects.nsExtendOutput1Line)",
"%(nsExtendObjects.nsExtendResult)"
],
"display_ok": true
}
}
],
"formatting": {}
}

Here’s what I obtained:

/usr/lib/centreon/plugins/centreon_generic_snmp.pl --plugin=apps::protocols::snmp::plugin --mode=collection --hostname=127.0.0.1 --snmp-community=public --config=/var/lib/centreon-engine/service-collection-fix.json --verbose
OK: All selections are ok
is-active centengine.service ? : active / Up
is-active gorgoned.service ? : active / Up

Here’s what I did:

  • filtered the OIDs by making the used_instance regular expression more restrictive.
  • Extended the OIDs of the wanted information so that only the group captured by this regex is missing to it to get the value.
  • added a dot  .  before the square brackets in the expand_table section.

☝️

 

This is quality work ( ​@omercier ) ✔️ 🙏

 

💃🍁🎉🎁🌼🥐


Hello,

Thank you very much.
It works perfectly with the correct syntax.

Philippe


Reply