尝试cURL松弛时获取无效的有效负载 [英] Getting invalid payload when trying to cURL slack

查看:59
本文介绍了尝试cURL松弛时获取无效的有效负载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当nginx无法重新加载时,我正在尝试使URL松弛.我能够检查nginx失败,并且在出现时可以cURL松弛.尝试将来自失败的重新加载的错误消息包含在我的cURL命令中时,我遇到了无效的有效载荷错误.这是我必须执行的脚本:

I am trying to cURL slack when nginx fails to reload. I am able to check that nginx failed and can cURL slack when it does. I am running into an invalid payload error when trying to include the error message from the failed reload within my cURL command. This is the script I have to do that:

#!/bin/bash

OUTPUT=$(nginx -s reload 2>&1 > /dev/null >/mnt/efs/out.txt)

ESCAPE=$(echo $OUTPUT | sed 's/"/\"/g' | sed "s/'/\'/g" )

nginx -t || curl -X POST --data-urlencode 'payload={"username": "reload-monitor-lizard", "text": "'"${ESCAPE}"'", "icon_emoji": ":ghost:"}' https://hooks.slack.com/services/xxxxxxx/xxxxx/xxxxxxxxxxxxxxxxxxxx

我尝试使用引号,但是它仍然给我无效的有效载荷错误或发送

I've tried playing around with the quotes, but it either still gives me the invalid payload error or sends

$ {ESCAPE}

${ESCAPE}

作为消息.关于我在做什么错的任何建议吗?

as the message. Any suggestions on what I am doing wrong?

更新:

通过将变量中的双引号替换为单引号来解决此问题,如下所示:

Fixed this by replacing the double quotes in my variable with single quotes like this:

ESCAPE=$(echo $OUTPUT | sed "s/\"/'/g" )

推荐答案

这对我来说很好:

curl -X POST -H \"Content-type: application/json\" --data \"{\\\"text\\\":\\\"Here your text!!\\\"}\" <host_slack>

这篇关于尝试cURL松弛时获取无效的有效负载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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