[Solved] Simple PHP Script

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

Moderators: Developers, Moderators

Post Reply
Forodrim
Posts: 6
Joined: Tue May 28, 2013 4:54 am
Location: Duisburg, Germany

[Solved] Simple PHP Script

Post by Forodrim »

Hi,

I have a, hopefully simple Question:
I want to us a PHP Script to get the outside Temperature, I use a freely available API and have the Location hardcoded (for now)
The Script looks like this:

Code: Select all

<?PHP
$outtemp_json = file_get_contents('http://api.openweathermap.org/data/2.5/weather?lat=51&lon=6&units=metric');
$outtemp = json_decode($outtemp_json,true);

$result = ($outtemp["main"]["temp"]);
print ($result);
?>
Since it will only return one value, the Input method is simple too:

Image

And the Data Template:

Image

but when used in a graph template is just returns 0.00 as value?
Can you help me find the error?
Last edited by Forodrim on Fri Jul 12, 2013 7:54 am, edited 1 time in total.
User avatar
phalek
Developer
Posts: 2838
Joined: Thu Jan 31, 2008 6:39 am
Location: Kressbronn, Germany
Contact:

Re: Simple PHP Script

Post by phalek »

I would change COUNTER to GAUGE, as Counter will only give you a diff between the previous temp and the current temp, which most of the time is probably just 0.
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
Forodrim
Posts: 6
Joined: Tue May 28, 2013 4:54 am
Location: Duisburg, Germany

Re: Simple PHP Script

Post by Forodrim »

I changed it to Gauge, but it didn't solved it :(
User avatar
phalek
Developer
Posts: 2838
Joined: Thu Jan 31, 2008 6:39 am
Location: Kressbronn, Germany
Contact:

Re: Simple PHP Script

Post by phalek »

Goto Console -> Data Sources and check that data source ( Turn On Data Source Debug Mode ). It probably still states COUNTER. If that's the case, you will need to delete the graph and associated data sources and re-create them.
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
Forodrim
Posts: 6
Joined: Tue May 28, 2013 4:54 am
Location: Duisburg, Germany

Re: Simple PHP Script

Post by Forodrim »

I did that, the debug info:

/usr/local/rrdtool/bin/rrdtool create \
/var/www/html/cacti/rra/pdu_hinten_outtemp_1512.rrd \
--step 300 \
DS:OutTemp:GAUGE:600:0:1000000 \
RRA:AVERAGE:0.5:1:500 \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MAX:0.5:1:500 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797 \
User avatar
phalek
Developer
Posts: 2838
Joined: Thu Jan 31, 2008 6:39 am
Location: Kressbronn, Germany
Contact:

Re: Simple PHP Script

Post by phalek »

Then I suggest increasing the logging level to debug for one polling cycle and check the cacti log for what it does when querying that one.
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
Forodrim
Posts: 6
Joined: Tue May 28, 2013 4:54 am
Location: Duisburg, Germany

Re: Simple PHP Script

Post by Forodrim »

I get this:

07/11/2013 12:40:24 PM - CMDPHP: Poller[0] Host[49] DS[1512] WARNING: Result from CMD not valid. Partial Result: U
07/11/2013 12:40:24 PM - POLLER: Poller[0] CACTI2RRD: /usr/local/rrdtool/bin/rrdtool update /var/www/html/cacti/rra/pdu2_pdutemp_463.rrd --template PDUtemp 1373539224:233
07/11/2013 12:40:24 PM - CMDPHP: Poller[0] Host[49] DS[1512] CMD: /var/www/html/cacti/scripts/outtemp.php, output: U
07/11/2013 12:40:24 PM - WEATHERMAP: Poller[0] WM poller_output: STARTING


so the error is with the script?
how can I run it from command line to see the output?

I made sure the script belongs to apache:apache, just as the other scripts.
User avatar
phalek
Developer
Posts: 2838
Joined: Thu Jan 31, 2008 6:39 am
Location: Kressbronn, Germany
Contact:

Re: Simple PHP Script

Post by phalek »

Someone else on the forum just had the same problem, and he was able to solve it by putting the output name in front of the returned number like this:

Code: Select all

echo "outTemp:".($result);
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
Forodrim
Posts: 6
Joined: Tue May 28, 2013 4:54 am
Location: Duisburg, Germany

Re: Simple PHP Script

Post by Forodrim »

sadly, it didn't solve it :

07/11/2013 05:15:26 PM - POLLER: Poller[0] CACTI2RRD: /usr/local/rrdtool/bin/rrdtool update /var/www/html/cacti/rra/pdu2_pdutemp_463.rrd --template PDUtemp 1373555726:233
07/11/2013 05:15:26 PM - CMDPHP: Poller[0] Host[49] DS[1725] WARNING: Result from CMD not valid. Partial Result: U
07/11/2013 05:15:26 PM - CMDPHP: Poller[0] Host[49] DS[1725] CMD: /var/www/html/cacti/scripts/outtemp.php, output: U
07/11/2013 05:15:26 PM - WEATHERMAP: Poller[0] WM poller_output: STARTING

can I run the script manually from commendline to see if it runs?
Like the same when cacti runs it, so i can see the result?
User avatar
phalek
Developer
Posts: 2838
Joined: Thu Jan 31, 2008 6:39 am
Location: Kressbronn, Germany
Contact:

Re: Simple PHP Script

Post by phalek »

sure you can !
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
Forodrim
Posts: 6
Joined: Tue May 28, 2013 4:54 am
Location: Duisburg, Germany

Re: Simple PHP Script

Post by Forodrim »

I got it to work, I made a couple of errors:

To debug I changed the cron for the poller to write the result into a log file, instead of dev/null
This showed, that the Permissions for the script were wrong, I forgot the allow execution :/

After I changed this, cacti still didn't execute it as PHP file, so I had to add the following to the Input String in the Data Input:
/usr/bin/php <path_cacti>/scripts/outtemp.php

Now the Script is working as it should :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest