1

Makefile:

QUERY := "securityresources | where type == 'microsoft.security/assessments' | summarize by assessmentKey=name | join kind=inner ( securityresources | where type == 'microsoft.security/assessments/subassessments' | extend assessmentKey = extract('.*assessments/(.+?)/.*',1, id) ) on assessmentKey | where properties.additionalData.assessedResourceType == 'ContainerRegistryVulnerability' | extend status = properties.status.code | extend severity = properties.status.severity"

.ONESHELL:
check:
    # az graph query -q ${QUERY}
    results="`az graph query -q ${QUERY}`"
    @for result in $$results.data;
    do
        echo "$${result.status}"
    done

Output of az graph query -q ${QUERY} looks like:

{ "count": 10,
  "data" : [{"status":"healthy", "abc":"123"},
            {"status":"unhealthy", "abc":"322"},
            {"status":"healthy", "abc":"432"}
           ]
}

Error:

/bin/bash: line 4: ${result.status}: bad substitution make: ***

[Makefile:23: check] Error 1

How to assign command output to a variable and iterate on that object and access keys, values of those objects?

2
  • What are you expecting $$results.data to do? It does not look like a UNIX/Linux question to me.
    – U. Windl
    Commented Sep 30, 2022 at 8:49
  • @U.Windl $$results.data should return array of dictionaries to iterate. Need a right syntax of script(Linux) to run using make file. Commented Oct 2, 2022 at 10:13

1 Answer 1

1

You can use jq to iterate through JSON.

Something like:

az graph query -q ${QUERY} | jq .data[].status

Although, not sure how this is related to make

2
  • getting jq command not found when run using make Commented Sep 22, 2022 at 13:01
  • @Pythoncoder Install it. The jq is not a necessary tool and is not installed from the get go, you have to install it additionally. But it is a well known and exists in all repositories.
    – White Owl
    Commented Sep 22, 2022 at 13:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .