Kapacitor .post()HTTP发送到URL而不发送数据 [英] Kapacitor .post() HTTP Post to url not sending data

查看:234
本文介绍了Kapacitor .post()HTTP发送到URL而不发送数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用kapacitor通过HTTP POST将警报发送到URL.书面脚本在给定的URL上命中,但未将相关数据发送到给定的URL.

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.

以下是我的TICK脚本.

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);

?>

两个网址都获取了空数据. Kapacitor版本为: Kapacitor 1.3.1

both urls are getting emtpy data. Kapacitor version is: Kapacitor 1.3.1

以下是Kapacitor [[httppost]]配置

Following is Kapacitor [[httppost]] config

[[httppost]]
   endpoint = "NodeJs"
   url = "http://localhost:1440/alert"
#   headers = { Example = "node" }
#   basic-auth = { username = "my-user", password = "my-pass" }

推荐答案

我在php-zend framework中遇到了类似的问题,这就是我解决问题的方式.

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);

您的消息详细信息将在$ data中.我在这里得到的: https://github.com/influxdata/kapacitor/issues/1681

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

这篇关于Kapacitor .post()HTTP发送到URL而不发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆