php script does not work as Data Input Method
Moderators: Developers, Moderators
php script does not work as Data Input Method
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
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
- gandalf
- Developer
- Posts: 22383
- Joined: Thu Dec 02, 2004 2:46 am
- Location: Muenster, Germany
- Contact:
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.
At least the naming of the variable that shows up on the output line seems strange to me.
R.
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
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
- gandalf
- Developer
- Posts: 22383
- Joined: Thu Dec 02, 2004 2:46 am
- Location: Muenster, Germany
- Contact:
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.
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.
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
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
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
|/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
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.
Thanks a lot,
Carsten
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);
?>
Carsten
Who is online
Users browsing this forum: No registered users and 7 guests