"Cannot find file" error on host
Posted: Wed Aug 20, 2014 7:06 pm
So I wrote a perl script that connects to an FTP server, uploads a file, downloads the same file, and checks it for previously written stuff. The whole idea is to make sure people can upload and download. When I tested it via the terminal, I got the correct outputs for OK and CRITICAL, depending on my tests. For some reason, once I added it to nagios, I'm getting the error:
This makes no sense to me because I'm 100% sure the file is there, WITH all the permissions it needs. I even ran the file from the terminal using the path specified in the error and got normal results.
I've posted copies of my command, host, and template files below, along with the script itself. What in the world could be causing this?
Host definition:
Template definition:
Command definition:
Perl script:
I even tried rubber duck debugging this, following the cfg files as if I were Nagios, and it should work!
Code: Select all
(No output on stdout) stderr: execvp(/usr/local/nagios/libexec/ftp.pl, ...) failed. errno is 2: No such file or directory
I've posted copies of my command, host, and template files below, along with the script itself. What in the world could be causing this?
Host definition:
Code: Select all
define host{
use transfer-template
host_name FTP Health Check
alias FTP Health Check
check_command check_ftp
}
Code: Select all
define host{
name transfer-template ; The name of this host template
use generic-host ; Inherit default values from the generic-host template
check_period 24x7 ; By default, Windows servers are monitored round the clock
check_interval 1 ; Actively check the server every 1 minutes
retry_interval 0.5 ; Schedule host check retries at 0.5 minute intervals
max_check_attempts 2 ; Check each server 2 times (max)
notification_period 24x7 ; Send notification out at any time - day or night
notification_interval 10 ; Resend notifications every 10 minutes
notification_options d,r ; Only send notifications for specific host states
contact_groups admins ; Notifications get sent to the admins by default
hostgroups 2 ; Host groups that Windows servers should be a member of
register 0 ; DONT REGISTER THIS - ITS JUST A TEMPLATE
}
Code: Select all
define command{
command_name check_ftp
command_line $USER1$/ftp.pl
}
Code: Select all
#!usr/bin/perl
use Net::FTP;
use lib "PATH TO LIBRARY";
#use Try::Tiny; /depreciated
use Time::Piece;
$host = "FTP SERVER";
$user = "FTP USERNAME";
$pw = "FTP PASSWORD";
$dir = "Test";
$getFile = "ftptest";
$putFile = "/usr/local/nagios/Misc/ftptest";
$date = localtime->strftime('%m/%d/%Y %H:%M');
#Writes current date to file for nagios checking
open (FILE, ">$putFile\n");
print FILE "$date\n";
close (FILE);
#Connects to FTP directory
$ftp = Net::FTP->new($host) or die "Can't open $host\n";
$ftp->login($user, $pw) or die "Can't login with $user\n";
$ftp->cwd($dir) or die "Can't connect to $dir\n";
#Sends to directory, gets from directory
$ftp->put($putFile);
$ftp->get($getFile);
#Reads date from file to make sure it matches $date
open(FILE, "$getFile");
while(<FILE>){
chomp;
$fileOut = $_;
}
#Nagios logic
if ($fileOut == $date) {
print "OK - FTP Services Working\n";
exit 0; #Nagios OK return code
}
else {
print "CRITICAL - FTP services degraded\n";
exit 2; #Nagios CRITICAL return code
}