Custom Perl Plugin Run At Terminal But Not in Nagios UI??

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
mohsin2011
Posts: 63
Joined: Fri Sep 09, 2011 1:14 am

Custom Perl Plugin Run At Terminal But Not in Nagios UI??

Post by mohsin2011 »

Hi,

i have created my own custom plugin in perl that is,

#!/usr/bin/perl
#
# check_file_exists.pl
#
# Checks if a file exists.
#


use POSIX;
use lib "/usr/local/nagios/libexec" ;
use utils qw($TIMEOUT %ERRORS); # Import predefined status-codes and timeout variable

sub print_usage() {
print "Usage: check_file_exists -f <filename> [-t <timeout>]\n";
}

sub print_help() {
print_usage();
print "\n";
print "Options:\n";
print "-f|--filename (string)\n";
print " set the filename to check for existance\n";
print "\n";
}

for($i = 0; $i < $#ARGV; $i++) {
if($ARGV[$i] =~ /^-h|^--help/) { # Help argument
print_help();
exit($ERRORS{"OK"});
}
elsif($ARGV[$i] =~ /^-f|^--filename/) { # filename argument
$i++;
$filename = $ARGV[$i];
}
elsif($ARGV[$i] =~ /^-t|^--timeout/) { # timeout argument
$i++;
$TIMEOUT = $ARGV[$i];
}
else { # Unknown argument, print help
print_usage();
exit($ERRORS{"UNKNOWN"});
}
}

if (!defined($filename)) {
# No filename was given.
print_usage();
exit($ERRORS{"UNKNOWN"});
}

# Timeout handler used
$SIG{'ALRM'} = sub {
print "CRITICAL: Plugin timed out after $TIMEOUT seconds\n";
exit($ERRORS{'CRITICAL'});
};

# Install timeout handler, so that the plugin does not hang indefinitely.
alarm($TIMEOUT);

if (-f $filename) {
print "OK - Filename $filename exists.\n";
exit($ERRORS{"OK"});
} else {
print "CRITICAL - Filename $filename does not exist.\n";
exit($ERRORS{"CRITICAL"});
}

i add command and service in command.cfg and windows.cfg respectivly the command code is,
# 'check_file_exists'
define command{
command_name: check_file_exists
command_line: $USER1$/check_file_exists -H $HOSTADDRESS$
}

service code is,
define service{
use generic-service
host_name musewerx-72c7b0
service_description File
check_command check_file_exists
}

then i copy the perl file where all other plugins are located and run it at terminal it results fine then i convert it to binary file using perlcc commant ant try to run it it runs fine at terminal but when i add service and command perameters it give error ,

[root@localhost libexec]# service nagios restart
Running configuration check... CONFIG ERROR! Restart aborted. Check your Nagios configuration.


Hopes for yous Suggestions...

Thanks in Advance!
crfriend
Posts: 61
Joined: Thu Sep 01, 2011 7:53 am
Location: Central New England (USA)
Contact:

Re: Custom Perl Plugin Run At Terminal But Not in Nagios UI?

Post by crfriend »

mohsin2011 wrote:# 'check_file_exists'
define command{
command_name: check_file_exists
command_line: $USER1$/check_file_exists -H $HOSTADDRESS$
}
Try getting rid of the colons in the mentioned configuration.

Running "nagios -v $config_file" is almost ALWAYS of assistance when the instance won't start.
mohsin2011
Posts: 63
Joined: Fri Sep 09, 2011 1:14 am

Re: Custom Perl Plugin Run At Terminal But Not in Nagios UI?

Post by mohsin2011 »

as you told me i tried to do it but get error that is,

[root@localhost ~]# nagios -v $config_file
bash: nagios: command not found


what should i do now hopes for suggestions ..

Thanks in Advance.
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: Custom Perl Plugin Run At Terminal But Not in Nagios UI?

Post by mguthrie »

You need to point to the actual location of the nagios binary and the main nagios.cfg file. On a source install it looks like:

Code: Select all

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Locked