Kapacitor .post() HTTP Post to url not sending data

隐身守侯 提交于 2019-12-10 15:29:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!