Multiple services in one check

I’m working on a Bash script that I want to use as a Nagios plugin.
The script itself runs fine and gives me the expected results.

The problem I’m running into is this:
I want to check a router to see which connections are currently up or down. The catch is that I don’t know in advance whether the router will have just one interface or multiple interfaces.

For example, the script might return something like this:

OK - (INTERNET) Connected | status=0
OK - (INTERNET2) Connected | status=0
OK - (LTE-BKUP) Connected | status=0

When I configure this in Nagios, I only ever see one service, even though in reality there are three interfaces.

I realize I could create separate scripts or service checks for each interface, but that’s not possible in my setup—and I don’t know ahead of time how many interfaces I’ll be dealing with.

My question: Is there a way to implement this so that a single script can dynamically create a separate service for each interface it finds? Any tips or ideas would be hugely appreciated.

Or am I going about this the wrong way, and is there maybe a different approach I should be looking at?

A Nagios plugin only can output the state for a single service.

What you want is a local check that gets called by the agent. Or depending on the use case even a special agent that outputs a local check section.

BTW: Why don’t you use SNMP to query the router?

First of all, thanks for your response.

I’m using SNMPv3 on the routers and performing an snmpbulkwalk across all interfaces:

snmpbulkwalk -v3 xxxxxxxxxxx IF-MIB::ifDescr

From the snmpbulkwalk output I determine the interface index (ifIndex) and then query the operational status directly:

snmpget -v3 xxxxxxxxxx IF-MIB::ifOperStatus."$ID" -Oqv

Due to performance considerations, I need to minimize the number of SNMP queries. We are operating several thousand routers globally, with only a single centralized polling instance located in Europe and no distributed collectors at remote sites.

Good luck! :smile:

This calls for a special agent where you implement your logic and the output data for the services. You could even re-use agent data sections for interfaces if it’s possible.

Thanks for the input. I was able to solve the problem relatively easily. Thanks for listening.

1 Like