Azure CLI inline parameters not working - json

I'm trying to pass in parameters inline to a ARM template from within PowerShell using the following command:
azure group deployment create -f my_arm_template.json -g myresourcegroup -p '{\"slot\":\"blue\"}' --verbose
and receive the error:
Error converting value "blue" to type 'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Data.Definitions.DeploymentParameterDefinition'. Path 'properties.parameters.slot'
I'm using the example given from this page:
https://azure.microsoft.com/en-us/documentation/articles/resource-group-template-deploy/
I have tried without escaping the quotes just like the example and various other ways but every other attempt breaks when trying to validate my template.
UPDATE 1: I have tried this from CMD in addition to Powershell with the same results.

The problem wasn't the way I was escaping the JSON but it was the value I was giving. Instead of:
{"slot":"blue"}
it should have been:
{"slot":{"value":"blue"}}

Related

Could not parse timeStamp <1.65269E+12> using format defined by property jmeter.save.saveservice.timestamp_format=ms on sample 1.65269E+12,3752

At the time of generating the Html report getting below error.
please give the Suggestion to overcome this issue.
thanks in advance.
enter image description here
There is a problem with your .jtl results file, JMeter expects to find a long value representing a timestamp in milliseconds since beginning of Unix epoch
You should replace 1.65269E+12 with its "long" equivalent of 1652690000000
If you opened and saved JMeter's .jtl results file using Excel or equivalent you should re-save it again and configure the first column to contain numeric values without floating points.
Also be aware that you can run a JMeter test and generate HTML reporting dashboard in command-line non-GUI mode in one shot like:
jmeter -n -t /path/to/testplan.jmx -l /path/to/testresult.jtl -e -o /path/to/dashboard
More information: Generating Reports

Passing variable to aws cli inline json

I wrote a script to create sqs resource on local stack. I wanted to pass a value that I get from one cli command to the next but inside an inline json. Following is the section of the script in question.
arn=$(aws --endpoint-url=http://localhost:4576 sqs get-queue-attributes \
--queue-url http://localhost:4576/my_dead_letter_queue_url \
--query 'Attributes.QueueArn' \
--output text)
aws --endpoint-url=http://localhost:4576 sqs create-queue \
--queue-name my_queue \
--attributes \
'{"RedrivePolicy":"{\"deadLetterTargetArn\":\"$arn\", \"maxReceiveCount\":\"5\"}"}'
So I'm trying to pass that "arn" variable but the cli is taking that as a string and trying to find a sqs with url "$arn" and fails. I also tried removing the quote. In that case, the error is malformed string.
Instead of the arn variable, if I use the arn value as string there, it works.
Can someone please show me how to pass that variable inside that inline json if it is possible?
Thank you for reading :)
Shahed
I was able to do the following with successful results, grant it it doesn't process the json (for that I'm just replacing tokens via sed), but I updated my example and tested it at least in bash with what I was doing:
#!/bin/bash
export awscmd="aws --region us-east-1 iam"
function setArn() {
${awscmd} list-policies --query 'Policies[?PolicyName==`'${1}'`].{ARN:Arn}' --output text
}
arn=$(setArn "some-policy-name")
echo '{"RedrivePolicy":"{"deadLetterTargetArn":"'$arn'", "maxReceiveCount":"5"}"}'
$ ./somearntest.sh
{"RedrivePolicy":"{"deadLetterTargetArn":"arn:aws:iam::############:policy/some-policy-name", "maxReceiveCount":"5"}"}
Notice the use of single tics to concatenate the output result outside of the string. This is in bash 4 and I removed the escaped \"s as I think that was added in error; ymmv.
The problem here is you are trying to expand a bash variable inside single quotes. Using single quotes like this is usually to pass a bunch of strings and unqoutable stuff as one argument. If you can't replace them with double quotes you'll have to resort to dirty eval hacks, which I do not recommend.
Here is an example:
$ arn=foobar
$ echo '{"RedrivePolicy":"{\"deadLetterTargetArn\":\"$arn\", \"maxReceiveCount\":\"5\"}"}'
{"RedrivePolicy":"{\"deadLetterTargetArn\":\"$arn\", \"maxReceiveCount\":\"5\"}"}
$ eval echo '{"RedrivePolicy":"{\"deadLetterTargetArn\":\"$arn\", \"maxReceiveCount\":\"5\"}"}'
{RedrivePolicy:{"deadLetterTargetArn":"foobar", "maxReceiveCount":"5"}}
For more information I suggest to check How eval works and Expansion of variables inside single quotes

docker and format json

I'm trying to get usable json from the docker cli, however it seems it will only produce json for individual items, and not the complete result, as a whole.
For example, running docker container ls -a --format="{{ json .Names }}" produces:
"hopeful_payne"
"trusting_turing"
"stupefied_morse"
"unruffled_noyce"
"pensive_fermi"
"objective_neumann"
"confident_bhaskara"
"unruffled_cray"
"epic_newton"
"boring_bartik"
"priceless_sinoussi"
"naughty_grothendieck"
"hardcore_bose"
"sad_jones"
"optimistic_napier"
"trusting_stallman"
"xenodochial_dijkstra"
"pedantic_cocks"
The above is not json.
How can I produce a result that is, ideally, a json array?
I think you cannot do this using docker only.
The command-line's format function is effectively taking each input line (one for each container) and applying the Go template to it. So you need another tool to aggregate the lines into a JSON array.
One way that you can achieve your goal is using the excellent jq tool:
docker container ls --format="{\"name\":\"{{.Names}}\"}" --all | jq --slurp
This generates each container line as a JSON string: {"name": "[VALUE]"} and then uses jq to slurp them into a JSON array.
A challenge doing this directly in bash is JSON's stricture that the last element in a list can't be terminated with a ,. So, the following simple bash script generates invalid JSON and you'd need extra logic to remove it (or better yet, not add the last one):
echo "[$(for CONTAINER in $(docker container ls --format="{{.Names}}" --all); do echo "{\"name\":\"${CONTAINER}\"},"; done;)]"
What are you trying to do with these JSON responses? It might be easier just to talk directly to the Docker API, which will give you JSON responses directly. E.g., to get a list of containers:
curl --unix-socket /var/run/docker.sock http://localhost/v1.24/containers/json
You can, as DazWilkin suggested, use jq for filtering JSON on the command line. E.g., if we want a list of container names:
curl --unix-socket /var/run/docker.sock http://localhost/v1.24/containers/json |
jq '[.[]|.Names]'
You can find Docker API documentation here.
One way to think of the output is that it's JSONL: http://jsonlines.org/
This Docker output is JSON, per line. Since you asked for a single attribute -- just the name -- you're simply getting a string back. But, notice it's quoted. It's technically JSON. It may make more sense if you update your format to {{ json . }}, which will then output lines that look more like the JSON you're expecting.
However, it's still a JSON document per line, so you'd have to process each line as its own document.

jsawk won't parse valid JSON

I'm currently developing a bash script that makes a query to a server with curl, and returns a JSON object. I'm trying to parse that object with jsawk. For example, here is some data I'm trying to parse:
{
"account":{
"quota":20,
"email":"test#example.com",
"uuid":"12ae7a0cbd",
"email_verified":true
}
}
In terminal I'm running cat test.json | jsawk -q 'account.quota'.
Assume test.json is the above object. Every time I run that command, I always get the following error: jsawk: js error: ReferenceError: account is not defined, even though account is very clearly defined.
Try
<test.json jsawk 'return this.account.quota'
I removed your useless use of cat.

running an autokey script with input parameters

Is it possible to run an AutoKey script with input parameters? (e.g autokey-run -s scriptname param1 param2 ...) I've tried using sys.argv, but for some reason, when running the script through AutoKey (as opposed to through python), argv[0] just contains the string "/usr/local/bin/autokey-gtk", and all other indices are empty. Is there another way to do it?
Here's some sample code:
import sys
keyboard.send_keys(sys.argv[0])
--
$ autokey-run -s scriptname testparam
>>/usr/local/bin/autokey-gtk
I'm aware this is an odd use of AutoKey, but I need it for its ability to send keyboard events.
I solved this problem by writing a bash function that wrote the arguments to a temp file, ran the autokey script, then deleted the file. I've had no issues with that solution thus far.