Curl command to pass arguments in the ICINGA API:
I have a curl command and passing it on a Bash script, I need to have two variables in the POST method for this URL, How do i pass the parameter to the CURL command
curl -k -s -u 'root:icinga' -H 'Accept: application/json' \
-X POST 'https://sample.com:5665/v1/actions/acknowledge-problem?type=Service' \
-d '{ "author": "icingaadmin", "comment": " Working on it.", "notify": true, "filter": "host.name == {\"$1\} && service.name == {\"$2\}"" }''' \
| python -m json.tool
The $1 and $2 should have hostname and servicenames respectively
Please help
thanks Aravind
If you use single quotes (
'like this'
) in bash, you get a literal string with no variable expansion. That is, compare:With:
This is exactly the same situation as in your
curl
command line, where you have:There's actuall a number of quoting problems there starting with the
'''
at the end, and including the""
just before the final}
. If you want those variables to expand you will need to move them outside of your single quotes. You can do this:In this case, the
"$1"
is outside of the single quotation marks. Alternatively, you can do this:Here we're just using double quotes on the outside, so variable expansion works normally, but we have to escape every literal
"
inside the string.Using the first option, the final argument to
-d
would look like something like this ("something" because I'm not familiar with icinga):If
$1
isfoo
and$2
isbar
, this gives you: