In your manual the format is for GET requests: http: <probe_ip> : <port_number> / <token> ?content= <valid XML_or_JSON>
This format works if I send it with the browser URL. The same code works on another server if using text only (no JSON, no XML) I do not even get an answer or an error from prtg
The json_encode shows: {"prtg":{"result":[{"channel":"MyChannel","value":2483}]}}
My code:
<!DOCTYPE html> <html> <body> <?php $temperature = 2483; $prtgJson = array( 'prtg' => array( 'result' => array(array( 'channel' => 'MyChannel', 'value' => $temperature )) ) ); $stringToPush = "http://probe_ip:5050/S19?content=" . $prtgJson; $xml = file_get_contents($stringToPush); ?> </body> </html>
Article Comments
Thank you so much for your help. How and where to set the content, should I create another json array? Could you please help me.
Jun, 2017 - Permalink
Hi there,
This should do the trick:
<!DOCTYPE html> <html> <body> <?php $temperature = 2483; $prtgJson = array( 'prtg' => array( 'result' => array(array( 'channel' => 'MyChannel', 'value' => $temperature )) ) ); $stringToPush = "http://probe_ip:5050/S19?content=" . json_encode($prtgJson); $xml = file_get_contents($stringToPush); ?> </body> </html>
Otherwise, you'll pushing a PHP array to PRTG, which it can't interpret.
Kind regards,
Stephan Linke, Paessler Tech Support
Jun, 2017 - Permalink
I inserted:
header('Content-Type: application/json'); |
If I add this line at the end:
var_dump($http_response_header, $http_response_body, $xml);
I receive
[0]=> string(15) "HTTP/1.0 200 OK".....
but nothing else. The data never showed up on the sensor.
I added also the json_encode() and no result as well.
I think this is not working properly, I used other clouds and have no problems, only prtg shows problems.
I also tried to use a simple sensor and use the simple format with ?value=100 and the value never sets.
Tried it from the browser. No way to set a value.
Anyone is using this???
Any real simple example to use these functionalities???
I am stuck. Thank you if someone can help.
Jun, 2017 - Permalink
Some update: Made some test and I am sure about the code. The target actively refused the connection !? I add this line of code and got the error: error_reporting(0); ini_set('display_errors', 1); The error was reported as below:
<b>Warning</b>: file_get_contents(http://myIp:5050/S19?content={"prtg":{"result":[{"channel":"MyChannel","value":"2483"}]}}): failed to open stream: No connection could be made because the target machine actively refused it. in <b>C:\Inetpub\vhosts\myServerName.com\httpdocs\test.php</b> on line <b>31</b><br /> <br /> <b>Notice</b>: Undefined variable: http_response_header in <b>C:\Inetpub\vhosts\myServerName.com\httpdocs\test.php</b> on line <b>33</b><br /> NULL
Jun, 2017 - Permalink
Update and end. We could close the case. Found an error in our server setup. Thank you.
Jun, 2017 - Permalink
Hi there
Glad you found it eventually :)
Kind regards,
Stephan, PRTG Tech Support
Jun, 2017 - Permalink
Dear jmjobin
Please set the correct content type when pushing, in this case application/json.
Jun, 2017 - Permalink