问题
I am using kapacitor to send alert to URL using HTTP POST. Written script is hitting on given url but it is not sending related data to any of given url.
Following is my TICK script.
stream
|from()
.measurement('cpu')
|alert()
.id('kapacitor/{{ index .Tags "host"}}')
.message('{{ .ID }} is {{ .Level }} value:{{ index .Fields "value" }}')
.info(lambda: TRUE)
.post('http://localhost:1440/alert')
.post('http://localhost/test.php')
Following is a first post script:
var express = require("express");
var app = express();
var moment = require("moment");
var dateTime = moment();
var bodyParser = require("body-parser");
var urlencodedParser = bodyParser.urlencoded({extended:false});
var jsonParser = bodyParser.json();
var port = 1440;
app.post('/alert', jsonParser ,function(request, response){
console.log(request.body);
response.send();
});
app.listen(port);
console.log('Express App.js listening to port '+port);
Following is a second post script:
<?php
$content = json_encode($_REQUEST);
echo file_put_contents("/home/mahendra/Documents/tick/highcputick.log", $content);
?>
both urls are getting emtpy data. Kapacitor version is: Kapacitor 1.3.1
Following is Kapacitor [[httppost]] config
[[httppost]]
endpoint = "NodeJs"
url = "http://localhost:1440/alert"
# headers = { Example = "node" }
# basic-auth = { username = "my-user", password = "my-pass" }
回答1:
You actually need to set on the tick script the endpoint, like:
...
.post()
.endpoint('NodeJs')
回答2:
I had a similar problem in php - zend framework and this is how I solved the problem.
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
来源:https://stackoverflow.com/questions/46408175/kapacitor-post-http-post-to-url-not-sending-data