php script does not work as Data Input Method

Post support questions that directly relate to Linux/Unix operating systems.

Moderators: Developers, Moderators

Carsten
Posts: 8
Joined: Tue Mar 09, 2010 11:27 am

php script does not work as Data Input Method

Post by Carsten »

Hello community,

hope my English is not too bad so that can understand my problem with cacti.

Here is my scenario:
I installed cacti 0.8.7b on OpenSuse 11. Everything works fine after installations. I was also able to create some graphs with values polled with snmp.

But then I had a php script which polls the value of a counter. This php script works fine as a single script. The value I wanted to get I got in my browser.
Following I wanted to include that script to cacti so that this value polled by the script creates a nice graph. So I copied it to the cacti path and than to the folder scripts. As next step I created a new Data Input Method. I choosed "Script/Command" for Input Type and of course the path to the script for Input String. I created an Output Field called value2 because the value in the php script is called $values2. I selected update RRA.
The following steps were creating a Data Source and a Graph. The result was an empty graph. As I exported the CSV-file I saw that the values of the graph were "NaN". So my idea was that the graph does not get the value of the php script.

So my question is: is there any mistake I did or does anyone knows why the graph does not get the value of the script.

Really need help for this problem,

Thanks a lot,
Carsten
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Please see http://docs.cacti.net/manual:087:3a_adv ... ut_methods.
At least the naming of the variable that shows up on the output line seems strange to me.
R.
Carsten
Posts: 8
Joined: Tue Mar 09, 2010 11:27 am

Post by Carsten »

I did like it is explained in this HowTo. And I checked it again. But the graph is still empty. It seems that the graph does not get the value but I do not know why.

Does the name of the Output Field has to be the same as in the script? I mean the variable of the php script is $value2. Does the name of the Output Field need to b be $value2 or just value2?
Is it possible that there is another reason that the value of the script does not reach the graph?

Thanks a lot ,
Carsten
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Please run your script from command line and post the original output. I fear that we won't understand each other without that
R.
Carsten
Posts: 8
Joined: Tue Mar 09, 2010 11:27 am

Post by Carsten »

The result of executing the script in the command line lokks like:
<br>varible

The variable has of course always another value because it is the result of a counter.
So the result is
<br> 1527 or
<br> 1530
and so on.

Thanks a lot,
Carsten
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Please only spit out the value, no preceding <br> or space or whitespace of any kind.
The only alternatice is to use e.g.
description:value
where
"description" is some text (a single word). It has to match the "Data Input Method's Output Variable's name"
":" is a colon
"value" is the current value
Again, no whitespace.

R.
Carsten
Posts: 8
Joined: Tue Mar 09, 2010 11:27 am

Post by Carsten »

OK, I changed the script in a way that the result of the scrip in the command line shows a result like description:value.

In my case it shows now Counter:variable. The variable is a specific value. So the result is for example:
Counter:20154 or
Counter:20210

But I still have the problem that the graph which uses this script as Data Input Method is still empty.

Thanks a lot,
Carsten
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Please post a screenshot of the Data Input Method definitions.
R.
Carsten
Posts: 8
Joined: Tue Mar 09, 2010 11:27 am

Post by Carsten »

Here is the screenshot of my Data Input Method:
Attachments
Bildschirmfoto-Cacti - Mozilla Firefox 3 Beta 5.png
Bildschirmfoto-Cacti - Mozilla Firefox 3 Beta 5.png (104.67 KiB) Viewed 4556 times
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

I suppose, the Input String should read |path_php| /usr/share/cacti ...
R.
Carsten
Posts: 8
Joined: Tue Mar 09, 2010 11:27 am

Post by Carsten »

OK, I tried now the following combinations of Input Strings:

|/usr/share/php5_php| /usr/share/cacti/scripts/Strom.php
|/usr/share/php5| /usr/share/cacti/scripts/Strom.php
|/usr/share/php| /usr/share/cacti/scripts/Strom.php
/usr/share/php5_php /usr/share/cacti/scripts/Strom.php
/usr/share/php5 /usr/share/cacti/scripts/Strom.php
/usr/share/php /usr/share/cacti/scripts/Strom.php
php /usr/share/cacti/scripts/Strom.php

Non of it worked. Still having an empty graph. And I do not have any clue why!!!

Thanks a lot,
Carsten
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

gandalf wrote:I suppose, the Input String should read |path_php| /usr/share/cacti ...
R.
This was meant _verbosely_. The red text should not be replaced by anything.|path_php| is a cacti-internal variable
R.
Carsten
Posts: 8
Joined: Tue Mar 09, 2010 11:27 am

Post by Carsten »

It still does not work. But maybe the mistake is not in the Data Input Method or I just do not have the right understanding in this case for Cacti.

However the graph is still empty. If you have any other ideas what could be wrong, just let me know.

Thanks a lot,
Carsten
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Are you able to post/pm/mail the script?
R.
Carsten
Posts: 8
Joined: Tue Mar 09, 2010 11:27 am

Post by Carsten »

Sorry that I'm answering only now.
But here is the script I want to use. It is not written on my own, I just got it and have to use it.

Code: Select all

<?php
$ip = '192.168.24.110';
$port = 4000;
 
$sock = fsockopen($ip, $port, &$errno, &$errstr, 5);
  
fwrite ($sock, "counter.read.07\n");
$answer = fread($sock, 2096);
fclose ($sock);
 
$buffer = split(';', $answer);   
 
for ($i =0;$i < count($buffer);$i++) {
   if (ereg("value=",$buffer[$i])){
     $value = substr($buffer[$i],6); //hier ist der Wert
     }
   }

echo ('Counter:' .$value);

?>
Thanks a lot,
Carsten
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests