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!
Custom Perl Plugin Run At Terminal But Not in Nagios UI??
-
- Posts: 63
- Joined: Fri Sep 09, 2011 1:14 am
Re: Custom Perl Plugin Run At Terminal But Not in Nagios UI?
Try getting rid of the colons in the mentioned configuration.mohsin2011 wrote:# 'check_file_exists'
define command{
command_name: check_file_exists
command_line: $USER1$/check_file_exists -H $HOSTADDRESS$
}
Running "nagios -v $config_file" is almost ALWAYS of assistance when the instance won't start.
-
- Posts: 63
- Joined: Fri Sep 09, 2011 1:14 am
Re: Custom Perl Plugin Run At Terminal But Not in Nagios UI?
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.
[root@localhost ~]# nagios -v $config_file
bash: nagios: command not found
what should i do now hopes for suggestions ..
Thanks in Advance.
Re: Custom Perl Plugin Run At Terminal But Not in Nagios UI?
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