New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


php cannot send json sensor data

Votes:

0

Your Vote:

Up

Down

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>

http-get json php

Created on Jun 14, 2017 12:31:49 PM by  jmjobin (0) 1

Last change on Jun 15, 2017 3:54:05 AM by  Sven Roggenhofer [Paessler Technical Support]



7 Replies

Votes:

0

Your Vote:

Up

Down

Dear jmjobin

Please set the correct content type when pushing, in this case application/json.

Created on Jun 15, 2017 3:56:03 PM by  Arne Seifert [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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.

Created on Jun 15, 2017 4:25:35 PM by  jmjobin (0) 1



Votes:

0

Your Vote:

Up

Down

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

Created on Jun 16, 2017 12:16:06 PM by  Stephan Linke [Paessler Support]

Last change on Jun 16, 2017 12:16:19 PM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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.

Created on Jun 16, 2017 6:35:35 PM by  jmjobin (0) 1

Last change on Jun 19, 2017 4:51:37 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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={&quot;prtg&quot;:{&quot;result&quot;:[{&quot;channel&quot;:&quot;MyChannel&quot;,&quot;value&quot;:&quot;2483&quot;}]}}): 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

Created on Jun 19, 2017 9:21:58 AM by  jmjobin (0) 1

Last change on Jun 19, 2017 10:18:12 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Update and end. We could close the case. Found an error in our server setup. Thank you.

Created on Jun 19, 2017 9:52:49 AM by  jmjobin (0) 1



Votes:

0

Your Vote:

Up

Down

Hi there

Glad you found it eventually :)


Kind regards,
Stephan, PRTG Tech Support

Created on Jun 19, 2017 10:18:54 AM by  Stephan Linke [Paessler Support]



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.