10

I'm using some Perl-based scripts for service checks in Nagios and I get (Service check did not exit properly) and (null) as the result in Nagios, but the script works great on the command line.

I've seen solutions online suggesting to disable the internal Perl interpreter by setting enable_embedded_perl=0 in the Nagios configuration or by specifying the path to an interpreter explicitly. This did not help with the issue.

What else could it be?

Oliver Salzburg
  • 4,505
  • 16
  • 53
  • 80

3 Answers3

11

Nagios includes its own embedded perl interpreter. Your plugin is probably not epn compliant.

You might want to disable it globally, or just disable it for your script. The bottom of that docs page shows you how to do this.

Basically, add # nagios: -epn on its own line somewhere within the first ten lines of your script. This should fix your problem.

You could also make it compliant, but it's almost certainly not worth the trouble.

idupree
  • 103
  • 3
Keith
  • 4,627
  • 14
  • 25
  • Yeah, thanks for the suggestion. Even though I explicitly stated that this did not have any impact on the specific problem I was facing. – Oliver Salzburg Mar 26 '14 at 09:29
  • This is real resolve for nagios. without -epn, plugin is included and executed internally by nagios. with -epn, it is loaded as external executable, similar to binaries or bash scripts. See page: http://nagios.sourceforge.net/docs/3_0/embeddedperl.html and consider epn complaint – Znik Oct 10 '14 at 10:53
  • 1
    The colon is required in `# nagios: -epn`, per the docs and per my tests. – idupree Jun 03 '15 at 23:17
  • 1
    Strangely enough, the current Ubuntu LTS (18.04) version of nagios-plugins-standard (2.2-3ubuntu2) has this issue. Things work if I either modify affected plugins, eg `check_disk_smb` and `check_file_age`, or if I set ```use_embedded_perl_implicitly=0``` – Akom Mar 12 '19 at 15:10
  • Fixed it for me! Thanks... – Oscar Bravo Apr 01 '20 at 08:21
3

Some Perl scripts from the Nagios Exchange will try to include the utils.pm Perl module. You'll find a line like this somewhere in it:

use lib "/usr/local/nagios/libexec";

When installing Nagios on Debian, the default location of the utils.pm file is /usr/lib/nagios/plugins/utils.pm. So the use lib directive should be:

use lib "/usr/lib/nagios/plugins";

Executing the command from the command line most likely worked because you were in /usr/lib/nagios/plugins/, editing your plugin.

Oliver Salzburg
  • 4,505
  • 16
  • 53
  • 80
2

Prefix the command with /usr/bin/perl.

This solution is more of a workaround, it's probably not a good idea to do so but at least your plugin should work the same way it does when you launch it from the terminal.

NOTE: In my experience # nagios -epn works quite often, but sometimes it doesn't seem to be enough. I noticed that when this happens, the faulty plugins reports many warnings (when the script is invoked with perl -w).

tiktak
  • 121
  • 1