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?
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.
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.