Http .post not sending data

kapacitor

#1

Ok I have been making some baby steps as I would like to use influxdb and kapacitor for a project I am working on. However I can’t figure or even hack my way around .post returning an empty array.

These are my scripts:

dbrp "TEST_MEASUREMENTS"."autogen"

batch
	|query('''
		SELECT mean(data)
		FROM "TEST_MEASUREMENTS"."autogen"."temperature"
		WHERE processed != true
	''')
		.period(5h)
		.every(1m)
		.groupBy('my_id')
	|alert()
		.crit(lambda: "mean" > 30)
		.message('observableName: {{.Name}} mean: {{index .Fields "mean"}} myId: {{index .Tags "my_id"}}')
		.post('http://localhost/api/post-alerts')
		.log('/tmp/alert_temp')

This triggers the alert and is logged but the post parameters are empty. This is a php script I try to use to extract it:

$data = $this->params()->fromPost();
error_log("Data: $data");

The array returned is empty. Though it logs correctly. This is a similar problem to what I have: https://stackoverflow.com/questions/46408175/kapacitor-post-http-post-to-url-not-sending-data but the answer is not relevant to me.


#2

I found the solution to the problem for anyone facing a similar issue.

header(‘Content-Type: application/json’);
$data = json_decode(file_get_contents(‘php://input’),true);

Your message details will be in $data. I got this here: https://github.com/influxdata/kapacitor/issues/1681