Custom Perl Plugin Run At Terminal But Not in Nagios UI??
Posted: Wed Oct 26, 2011 6:17 am
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!
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!