我已经使用curl调用在kafka-rest上执行了HTTP。一个请求是成功的,而另一个请求(具有不同的json)则返回422错误({"error_code":422,"message":"Unrecognized : receiver"})。
工作请求
curl -X POST -H "Content-Type: application/vnd.kafka.json.v2+json" -H "Accept: application/vnd.kafka.v2+json" --data '{"records":[{"value":{"foo":"bar"}}]}' "http://localhost:8082/topics/jsontest"出站
{"offsets":[{"partition":0,"offset":0,"error_code":null,"error":null}],"key_schema_id":null,"value_schema_id":null}不工作请求
curl -X POST -H "Content-Type: application/vnd.kafka.json.v2+json" -H "Accept: application/vnd.kafka.v2+json" --data @alert-request.json "http://localhost:8082/topics/jsontest"输出
{"error_code":422,"message":"Unrecognized field: receiver"}alert-request.json
{
"receiver": "email-logs",
"status": "firing",
"alerts": [
{
"status": "firing",
"labels": {
"alertname": "CPUUsageAbove20%",
"instance": "node-exporter:9100",
"job": "node-exporter",
"monitor": "my-project",
"severity": "warn",
"team": "raptors"
},
"annotations": {
"dashboard": "www.prometheus.io",
"description": "CPU usage on node-exporter:9100 has reached 60"
},
"startsAt": "2020-04-30T08:03:17.309164516Z",
"endsAt": "0001-01-01T00:00:00Z",
"generatorURL": "http://0ab6d9955c65:9090/graph?g0.expr=60+%3E+job%3Anode_cpu_seconds%3Ausage+%3E+20\u0026g0.tab=1",
"fingerprint": "9c558a8c20c2ba08"
}
],
"groupLabels": {
"alertname": "CPUUsageAbove20%",
"team": "raptors"
},
"commonLabels": {
"alertname": "CPUUsageAbove20%",
"instance": "node-exporter:9100",
"job": "node-exporter",
"monitor": "my-project",
"severity": "warn",
"team": "raptors"
},
"commonAnnotations": {
"dashboard": "www.prometheus.io",
"description": "CPU usage on node-exporter:9100 has reached 60"
},
"externalURL": "http://5493399b56dc:9093",
"version": "4",
"groupKey": "{}/{team=~\"^(?:(raptors|leafs))$\"}:{alertname=\"CPUUsageAbove20%\", team=\"raptors\"}"
}我需要在json上面使用kafka-rest写到kafka,我使用curl调用在kafka-rest上执行HTTP,但这是返回错误。如何用卡夫卡-rest(卷曲)成功地书写卡夫卡?
发布于 2020-05-10 16:53:58
作为"error_code":422的响应中的错误代码意味着请求有效负载不正确。
根据kafka-rest的API规范,有效的请求有效负载结构之一是
{
"records": [
{
"key": "recordKey",
"value": "recordValue"
}
]
}因此,您的alert-request.json文件应该使用value字段中records中的内容进行修改。
{
"records": [
{
"key": "recordKey",
"value": {
"receiver": "email-logs",
"status": "firing",
"alerts": [
{
"status": "firing",
"labels": {
"alertname": "CPUUsageAbove20%",
"instance": "node-exporter:9100",
"job": "node-exporter",
"monitor": "my-project",
"severity": "warn",
"team": "raptors"
},
"annotations": {
"dashboard": "www.prometheus.io",
"description": "CPU usage on node-exporter:9100 has reached 60"
},
"startsAt": "2020-04-30T08:03:17.309164516Z",
"endsAt": "0001-01-01T00:00:00Z",
"generatorURL": "http://0ab6d9955c65:9090/graph?g0.expr=60+%3E+job%3Anode_cpu_seconds%3Ausage+%3E+20\u0026g0.tab=1",
"fingerprint": "9c558a8c20c2ba08"
}
],
"groupLabels": {
"alertname": "CPUUsageAbove20%",
"team": "raptors"
},
"commonLabels": {
"alertname": "CPUUsageAbove20%",
"instance": "node-exporter:9100",
"job": "node-exporter",
"monitor": "my-project",
"severity": "warn",
"team": "raptors"
},
"commonAnnotations": {
"dashboard": "www.prometheus.io",
"description": "CPU usage on node-exporter:9100 has reached 60"
},
"externalURL": "http://5493399b56dc:9093",
"version": "4",
"groupKey": "{}/{team=~\"^(?:(raptors|leafs))$\"}:{alertname=\"CPUUsageAbove20%\", team=\"raptors\"}"
}
}
]
}请注意,key字段是可选的,您可以提供适合您的用例的任何唯一键。
https://stackoverflow.com/questions/61715273
复制相似问题