Patch for check_mysqld for using the from Nagios


Hi all,

i posted this on NagiosWiki, but i have no idea if someone will find the page it is on. So… here it is for all to read and use.

= not found when executing check_mysqld. ==

I encountered the following error when executing :

Can’t locate in @INC (@INC contains: /usr/lib/nagios/plugins /mysql/modules /local/perl5 /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.7/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl/5.8.4 /usr/lib/perl5/site_perl/5.8.3 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.7/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/5.8.7 /usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl/5.8.4 /usr/lib/perl5/vendor_perl/5.8.3 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /local/nagios-plugins/check_mysqld line 167.

The thing is, when executed from the directory where the is located there is no problem. I execute the check from the Nagios host to a host (the host in the middle…) that holds the check_mysqld script, which checks a database on yet another host. The host in the middle suffered the “Can’t locate” error.

A collegue (Marco T.) wrote a quick patch in the script to fix this, and it works like charm! Here’s a diff:

— check_mysqld.dist 2009-02-24 14:12:15.000000000 +0100
+++ check_mysqld 2009-02-24 14:13:44.000000000 +0100
@@ -154,6 +154,14 @@

use strict;


  •   my $self = xx-marker0-xx;
  •   if($self =~ /^(.+)\/^\/]+$/) {
  •           $self = ;
  •   }
  •   push @INC, $self;


default mysql hostname, port, database, user and password, see NOTES above

my $HOSTNAME= ‘localhost’;
my $PORT= 3306;

Simply put these lines below the “use strict” line in the script and you are in business:

my $self = xx-marker0-xx;
if($self =~ /^(.+)/^/]+$/) {
$self = ;
push @INC, $self;


I posted the wrong code… sorry
Th diff messed up the code and i just cut and pasted it…
This is the correct stuff:

my $self = $0;
if($self =~ /^(.+)/^/]+$/) {
push @INC, $1;