Perl script runs in terminal but not when called by nagios
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Perl script runs in terminal but not when called by nagios
We are trying to monitor a VPN using a plug-in called “check_vpn.pl” downloaded from the nagios exchange. We are encountering difficulties with the script. When we run the script in the terminal it works however it brings up an error with the nagios core meaning that when nagios calls the script there is an error. The error seems to be in this section of the script:
# Create SNMP Session
($session, $error) = Net::SNMP->session(-hostname=>$host,-community=>$community,-port=>161);
#die "session error: $error" unless ($session);
if (! defined $session){
print "session error: $error";
exit($STATUSCODE{'UNKNOWN'});
}
# Walk sonicSAStatPeerGateway for list of active session OIDs
$result = $session->get_table(-baseoid => $sonicSAStatPeerGateway);
#die "request error: ".$session->error unless (defined $result);
if (! defined $result){
print "request error: ".$session->error;
exit($STATUSCODE{'UNKNOWN'});
}
We can run the script in the terminal using the command
nagios@nagios-virtual-machine:~$/usr/local/nagios/libexec/xxx.x.xxx -C xxxxx -V xxxxx
Which gives the output:
Use of uninitialized value in print at /usr/local/nagios/libexec/check_vpn.pl line 59.
index of oids 8
splits 2
data index .439300970
getdata HASH(0x2020d88)
datatable 195.11.xxx.xxx
splits 2
data index .636748606
getdata HASH(0x2020680)
datatable 213.123.xxx.xxx
splits 2
data index .1197858815
getdata HASH(0x2020bc0)
datatable 83.100.xxx.xxx
splits 2
data index .3221980697
getdata HASH(0x2025118)
datatable 87.102.xxx.xxx
splits 2
data index .3331040650
getdata HASH(0x201abf8)
datatable 213.249.xxx.xxx
splits 2
data index .3381330750
getdata HASH(0x20205f0)
datatable 213.123.xxx.xxx
splits 2
data index .3427044043
getdata HASH(0x2020e30)
datatable 94.72.xxx.xxx
splits 2
data index .3741549102
getdata HASH(0x201ac70)
datatable 87.102.xxx.xxx
namedata HASH(0x2020740)
name !xxxxxxxxxx!
passed VPN Name !xxxxxxxxx!
namedata HASH(0x2020cb0)
name !xxxxxxxxxxx!
passed VPN Name !xxxxxxxxx!
namedata HASH(0x201abf8)
name !Batty!
passed VPN Name !xxxxxxxxxx!
Any time this occurs the most likely issue is environment. When you login you are invoking things like /etc/profile, /etc/bashrc, /etc/bashprofile, $HOME/.profile, $HOME/.bashrc and/or $HOME/.bash_profile to condition your environment. These things set many environment variables chief among which is $PATH which tells it where to look for executables when you give a short name. (For example if the ls command is in /bin your PATH variable would need to include /bin for you to be able to just type "ls" rather than having to type "/bin/ls" every time.) However there are other important variables as well. When you run Nagios (or cron or any other background process) it isn't logging in so typically does NOT invoke the above files. That means you have to insure the background process knows what environment settings it should have - the best way to do that is to include them in the script.
So if you add a line to the script to output the env to a file and run it from command line then again from Nagios you can find what the environmental differences are between the two runs.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.