we use ip namespaces on Ubuntu 18.04 and want to monitor network interfaces in all namespaces.
The plugin we use to monitor interfaces in the default namespace: https://exchange.icinga.com/winem/check_linux_net_dev
I have the following ideas:
1. add the namespace to the arguments…
1.1 …and copy the the /proc/net/dev file from that namespace to /tmp/ and parse that file
1.2 …have redundant code in the plugin and read the file from /proc/net/dev in that namespace line by line
2. modify the plugin to use the subprocess library and run the script in the namespace
3. add a new icinga2 command to execute the check command in the namespace already
1.1 - would work but my gut feeling tells me that there is probably a smarter solution.
1.2 - I could avoid redundant code if I replace the
with open('/proc/net/dev') part with a function that opens, reads and closes the file manually and use that one for both cases. This is my least preferred solution
2 - spawning the module with sudo might be a bit tricky. Guess this would work but there is this gut feeling that tells me that this is this gut feeling that yells “DON’T DO IT!” again
3 - the solution I prefer right now. I just have to figure out a working sudoers config to allow the
nagios user to run just the required command with sudo privilges
Please let me know what you think about the ideas above or if you have a completely different approach or maybe a module that is capable to handle different namespaces already. Any input is appreciated!