Custom Python service chack fails "no module named"

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.

Seems that this is related to NetApp, since the NaServer module comes up when you purely google for it.

Not sure how to retrieve that module though, since every URL is hidden with a login form.


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 -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:

[root@mysatellitenode plugins]# pwd
[root@mysatellitenode plugins]# grep append check_lag_time

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.

Once it works, please share the plugin on :slight_smile:


Thanks Michael,

Yes I fully intend to share the plugin on github/Nagios exchange once I’m happy with it. Pretty much there now thanks.