No Data in Graph using simple Perl script

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
kr99
Posts: 8
Joined: Thu Mar 10, 2005 12:57 am

No Data in Graph using simple Perl script

Post by kr99 »

Help !
I've read ( and re-read) the FAQs . I've even rebuilt a new machine and done a fresh install of Cacti and still have the same problem. I am simply trying to read a single value from a file which will be periodically updated via another source. I am using a simple perl script that runs correctly from command line that reads a file called data that has a single value (between 0 & 100). I am getting nothing back from the script into the rrd. Everything in the new machine is owned by root and file perms are OK.

Code: Select all

#!/usr/bin/perl
open(FILE,"data");  
 
  while (<FILE>) {  
      chomp;  
      print $_ ;  
   }  
   close(FILE);
My initial error was CMDPHP: Poller[0] Host[2] DS[10] WARNING: Result from CMD not valid. Partial Result :


debug message is
cacti.log

Code: Select all

10/24/2007 12:15:01 AM - CMDPHP: Poller[0] DEBUG: SQL Exec: "update poller_reindex set assert_value='13891253' where host_id='2' and data_query_id='1' and arg1='.1.3.6.1.2.1.1.3.0'"
10/24/2007 12:15:01 AM - CMDPHP: Poller[0] Host[2] DS[10] WARNING: Result from CMD not valid.  Partial Result:
10/24/2007 12:15:01 AM - CMDPHP: Poller[0] Host[2] DS[10] CMD: /usr/bin/perl /opt/software/cacti/scripts/read.pl, output: U
10/24/2007 12:15:01 AM - CMDPHP: Poller[0] DEBUG: SQL Exec: "insert into poller_output (local_data_id, rrd_name, time, output) values (10, 'xCast', '2007-10-24 00:15:01', 'U')"

Why is the system uptime OID in this output ?? I don't ask for it in my script !


poller.php

Code: Select all

10/24/2007 12:35:01 AM - POLLER: Poller[0] DEBUG: About to Spawn a Remote Process [CMD: /usr/bin/php, ARGS: -q /opt/software/cacti-0.8.6j/cmd.php 0 2]
10/24/2007 12:35:02 AM - POLLER: Poller[0] CACTI2RRD: /usr/local/bin/rrdtool update /opt/software/cacti-0.8.6j/rra/c5_xcast_10.rrd --template xCast 1193204101:U
10/24/2007 12:35:02 AM - SYSTEM STATS: Time:1.0119 Method:cmd.php Processes:1 Threads:N/A Hosts:3 HostsPerProcess:3 DataSources:1 RRDsProcessed:1
OK u:0.00 s:0.00 r:0.00
rrdtool info stuff

Code: Select all

[root@labmachine8 rra]# rrdtool info c5_xcast_10.rrd
filename = "c5_xcast_10.rrd"
rrd_version = "0003"
step = 300
last_update = 1193205001
ds[xCast].type = "GAUGE"
ds[xCast].minimal_heartbeat = 600
ds[xCast].min = 0.0000000000e+00
ds[xCast].max = NaN
ds[xCast].last_ds = "U"
ds[xCast].value = NaN
ds[xCast].unknown_sec = 1 ...
crontab -l
  • */5 * * * * /usr/bin/php /opt/software/cacti/poller.php >> /var/log/poller.log 2>1&
It is probably something really obvious that I can be ashamed of not finding but at this stage I am willing to accept the red face just to get an answer and relieve my frustration. :oops:

Regards
Jan Scholten
Posts: 9
Joined: Mon Oct 15, 2007 6:24 am

Post by Jan Scholten »

what is the output on your command line for

/usr/bin/perl /opt/software/cacti/scripts/read.pl ?
(su'ed to the correct user?)

How did you configure cacti data input method? afaik you need to output a "Tag: Value"

e.g. print "Value:$_";
and define Value as an Output Variable for your script.
kr99
Posts: 8
Joined: Thu Mar 10, 2005 12:57 am

Post by kr99 »

As a test the file "data" has only got one value so the output from Perl script is as follows

Code: Select all

[root@machine8 scripts]# ./read.pl
78.09
[root@labmachine8 scripts]# more data
78.09
I thought a single value input just needed to be a value unlike a pair that needs to be a key/value ?
Jan Scholten
Posts: 9
Joined: Mon Oct 15, 2007 6:24 am

Post by Jan Scholten »

dunno, i thought i read that this changed..

just try with a key and see ;-)
kr99
Posts: 8
Joined: Thu Mar 10, 2005 12:57 am

Post by kr99 »

mmmmmmm..... As a test I used the supplied ping.pl and the instructions in the FAQ to build the ping template. This all worked fine and the graph worked correctly. The output from running the script from command line was simply the returned single value of the rtt. So , withouth changing anything else, I renamed my own read.pl to ping.pl and examined the results. Even though both perl scripts returned a single value , the change to the ping.pl stopped the graph from working and caused the same error message of Result from CMD not valid. So I know that the issue is 100% within my perl script ! So, although they both give me a similar output only the ping.pl is correct ( and my read.pl is wrong ;-).
Can someone tell me where I am going wrong and tell me the error of my script versus the working ping.pl script (below)?

Code: Select all

#!/usr/bin/perl
open(FILE,"data");
while (<FILE>) {
     print $_ ;
  }
close(FILE);

Code: Select all

[root@labmachine8 scripts]# more data
.888

Code: Select all

#!/usr/bin/perl
open(PROCESS, "ping -c 1 $ARGV[0] | grep icmp_seq |");
$ping = <PROCESS>;
close(PROCESS);
$ping =~ m/(.*time=)(.*) (ms|usec)/;
print $2;
kr99
Posts: 8
Joined: Thu Mar 10, 2005 12:57 am

Post by kr99 »

mmmmmmm..... As a test I used the supplied ping.pl and the instructions in the FAQ to build the ping template. This all worked fine and the graph worked correctly. The output from running the script from command line was simply the returned single value of the rtt. So , withouth changing anything else, I renamed my own read.pl to ping.pl and examined the results. Even though both perl scripts returned a single value , the change to the ping.pl stopped the graph from working and caused the same error message of Result from CMD not valid. So I know that the issue is 100% within my perl script ! So, although they both give me a similar output only the ping.pl is correct ( and my read.pl is wrong ;-).
Can someone tell me where I am going wrong and tell me the error of my script versus the working ping.pl script (below)?

Code: Select all

#!/usr/bin/perl
open(FILE,"data");
while (<FILE>) {
     print $_ ;
  }
close(FILE);

Code: Select all

[root@labmachine8 scripts]# more data
.888

Code: Select all

#!/usr/bin/perl
open(PROCESS, "ping -c 1 $ARGV[0] | grep icmp_seq |");
$ping = <PROCESS>;
close(PROCESS);
$ping =~ m/(.*time=)(.*) (ms|usec)/;
print $2;
User avatar
cflong
Posts: 17
Joined: Thu Oct 25, 2007 8:16 am
Contact:

Post by cflong »

It's possible that cacti is stumbling on a new line character. Try calling using the chomp() function to eliminate these.

Code: Select all

#!/usr/bin/perl
open(FILE,"data");
while (<FILE>) {
     my $var=$_;
     chomp($var);
     print "$var";
  }
Also, printing in a key:value format seems to get around some of these issues.
kr99
Posts: 8
Joined: Thu Mar 10, 2005 12:57 am

Post by kr99 »

OK , its working now . I messed around with the perl script and suddenly graph data appears. Guess I better learn Perl!
Good learning experience though ....
If anyone is interested here's the working code to read a single value from a file

Code: Select all

#!/usr/bin/perl
$process = "/bin/cat /opt/software/cacti/scripts/data|";

open(PROCESS, $process);

while (<PROCESS>) {
        chomp;
        print;
        print "\n";
}
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest