In order to debug a much larger program, I wrote a simple Perl script and corresponding Cacti data input method/data source. The Perl script is:
#! /usr/bin/perl -w
print "2";
This script works fine, and I was able to build a graph off of it. However, I added some code that references an external ASCII file and uses the values in this file to create a hash of hashes. This hash isn't used in the output; it's simply to help me debug my other program.
#! /usr/bin/perl -w
$cust_file = "./active_customers.txt";
$strFieldDelimiter = ":";
%customer = ();
open(hdlCUSTFILE, $cust_file) || die "ERROR: could not find or open the file '$cust_file'. Check to make sure this file exists.\n";
# Loop through the active customer file
while ($line = <hdlCUSTFILE>)
{
# Parse the line into fields
chomp $line;
@arrFields = split(/$strFieldDelimiter/, $line);
# Push the elements of the array into a hash of hashes
$customer{$arrFields[0]} = { 'rtname' => $arrFields[1],
'contract' => $arrFields[3],
};
}
close hdlCUSTFILE;
print "2";
The issue is that now my data source is not getting any values. Once I made the change in the script the values cacti is pulling in changed to "N:U".
- cat ../log/rrd.log | grep jpl_test
04/22/2004 8:01 AM - CMD: /usr/bin/rrdtool create /usr/local/apache/htdocs//cacti/rra/jpl_test_875.rrd \
DS:jpl_test:GAUGE:600:0:100 \
04/22/2004 8:02 AM - CMD: /usr/bin/rrdtool update /usr/local/apache/htdocs//cacti/rra/jpl_test_875.rrd --template jpl_test N:2
04/22/2004 8:07 AM - CMD: /usr/bin/rrdtool update /usr/local/apache/htdocs//cacti/rra/jpl_test_875.rrd --template jpl_test N:2
04/22/2004 8:12 AM - CMD: /usr/bin/rrdtool update /usr/local/apache/htdocs//cacti/rra/jpl_test_875.rrd --template jpl_test N:2
04/22/2004 8:17 AM - CMD: /usr/bin/rrdtool update /usr/local/apache/htdocs//cacti/rra/jpl_test_875.rrd --template jpl_test N:2
04/22/2004 8:22 AM - CMD: /usr/bin/rrdtool update /usr/local/apache/htdocs//cacti/rra/jpl_test_875.rrd --template jpl_test N:2
04/22/2004 8:27 AM - CMD: /usr/bin/rrdtool update /usr/local/apache/htdocs//cacti/rra/jpl_test_875.rrd --template jpl_test N:2
04/22/2004 8:32 AM - CMD: /usr/bin/rrdtool update /usr/local/apache/htdocs//cacti/rra/jpl_test_875.rrd --template jpl_test N:2
04/22/2004 8:37 AM - CMD: /usr/bin/rrdtool update /usr/local/apache/htdocs//cacti/rra/jpl_test_875.rrd --template jpl_test N:2
04/22/2004 8:42 AM - CMD: /usr/bin/rrdtool update /usr/local/apache/htdocs//cacti/rra/jpl_test_875.rrd --template jpl_test N:2
04/22/2004 8:47 AM - CMD: /usr/bin/rrdtool update /usr/local/apache/htdocs//cacti/rra/jpl_test_875.rrd --template jpl_test N:U
04/22/2004 8:52 AM - CMD: /usr/bin/rrdtool update /usr/local/apache/htdocs//cacti/rra/jpl_test_875.rrd --template jpl_test N:U
04/22/2004 8:57 AM - CMD: /usr/bin/rrdtool update /usr/local/apache/htdocs//cacti/rra/jpl_test_875.rrd --template jpl_test N:U
04/22/2004 9:02 AM - CMD: /usr/bin/rrdtool update /usr/local/apache/htdocs//cacti/rra/jpl_test_875.rrd --template jpl_test N:U
04/22/2004 9:07 AM - CMD: /usr/bin/rrdtool update /usr/local/apache/htdocs//cacti/rra/jpl_test_875.rrd --template jpl_test N:U
Yet when I run my Perl script from the command line, it's fine:
- ./jpl.pl
2
Does Cacti have a problem with Perl scripts that access external files? I've got other Perl scripts that contain a hash of hashes, those work fine. Thanks for any help/advice.
Perl: strange error accessing external file
Moderators: Developers, Moderators
-
- Posts: 2
- Joined: Thu Apr 22, 2004 11:53 am
- Location: San Carlos, CA
perl script
Hi Jerry
Definitly you can run perl scripts or shell script to access to files, I'm doing it.
Did you tried to launch manually php.cmd, and check the output of the command ?
Check :
if the user which runs php.cmd or cactid has access to that file
for the paths to your file in your script, the cron doesn't run in the cacti directory, thus your path for your file is probably wrong.
Good Luck
Definitly you can run perl scripts or shell script to access to files, I'm doing it.
Did you tried to launch manually php.cmd, and check the output of the command ?
Check :
if the user which runs php.cmd or cactid has access to that file
for the paths to your file in your script, the cron doesn't run in the cacti directory, thus your path for your file is probably wrong.
Good Luck
-
- Posts: 2
- Joined: Thu Apr 22, 2004 11:53 am
- Location: San Carlos, CA
re: perl script
That was it. I was using a relative path to my external file; I re-coded with the absolute path and it works now. Thanks for you help and the quick response!
JPL
Who is online
Users browsing this forum: No registered users and 2 guests