November 17th, 2012, 07:47 AM
Cacti custom perl script
I've done a lot of coding over the years, however I am currently working on my 2nd ever perl script.
What I am doing is building a custom Cacti graph which gets it's data from my perl script. When I run my script at the command line it works fine, however when it is called from cacti it graphs the result as 0.
I have narrowed the issue down to an SSH call in the script that looks like the below:
if I use the commented line everything works fine in Cacti and I get my nice shiny graph. If I use the SSH command line it works fine from the command line, but does not work when Cacti calls the script. I am completely at a loss as to what is wrong, and I'm not overly sure if it's my lack of knowledge in perl, or lack of knowledge in Cacti that's causing me problems.
my $result = `/usr/bin/ssh -i /path/to/dsa_key root\@x.x.x.x "/path/to/remote/script | /bin/grep my_data"`;
#my $result = "data I should get back from the above line";
I thought it may have been a permissions issue on the script, but I have tried 0644, 0755 and 0777 and all of them give me a 0 result in the graph.
Any help is much appreciated.
November 17th, 2012, 10:58 PM
I'd obviously spent too long looking at this last night, when I looked with fresh eyes this morning I found the problem pretty easily.
The problem was with the SSH key being used, or more accurately I forgot that the script would be called by the www-data user when cacti ran, and as root when I ran it in the command line. I su'd to www-data and found the issue, generated a new key pair for that user and BAM, nice shiny stats in Cacti.