I have written my own service check in Python which runs OK on the command line, but when run from Icinga (I configured it with Web & Director if relevant) the service check fails with the following output:
Traceback (most recent call last):
File "/usr/lib64/nagios/plugins/check_lag_time", line 5, in <module>
from NaServer import *
ImportError: No module named 'NaServer'
Has anybody got suggestions on how to resolve this please, thanks.
Try searching with pip whether this module exists. Never heard of this unfortunately. Does the plugin’s README provide details on its requirements? It should.
I don’t see that either. Is it your own module that you’re importing? If so, put it in the same directory as the script and just check that the icinga user has read permissions for it.
Ah now, well I wrote the service check based on the NetApp SDK.
As I say, when I run the service check on the satellite node via the CLI the check executes properly
# ./check_lag_time -w 5000 -c 14400 -l 1.1.1.1 -u "myuser" -p mypassword -s mysvm -v myvolume
OK: Volume myvolume on source vServer mysvm is lagged by 3893 seconds.
I was wondering if there were any python-specific actions I needed to do.
The module for the service check is reachable, it has to be for the above output to work, I simply placed it in a subdirectory of the nagios plugin libexec folder:
Ok, that explains it better. You’re testing as root user, where the path is put in a relative fashion and the lookup works. If the plugin is executed by the daemon user icinga, this pwd doesn’t exist and as such, it fails to look it up.
You’ll need to either put in the full path, or you’ll go by adding the path to your PYTHONPATH environment in icinga2’s sysconfig. I would avoid the latter though.
I don’t know whether it is possible to install NetApp’s SDK into system’s Python, but that also can be a bad idea on upgrades.
It may also be the case that the plugin is executed on a remote host where the SDK isn’t installed, keep that in mind.
TL;DR - the simplest solution will be to add the full lookup path inside your plugin’s code.