The Insights API has just been released. We are getting some questions on more detail examples on how to use it. One example, in particular, is getting the “affected objects” from each Findings. Here, we will show you how simple it is to do so. We will break this down to two sections (1 – how to get a list, 2 – how to get the “affected objects” from the list).
To get the list of Findings in your particular Skyline environment, run this code. Be sure to add YOUR-TOKEN.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#!/bin/sh # APITOKEN="YOUR-TOKEN" SKYLINEACCESS="https://console.cloud.vmware.com/csp/gateway/am/api/auth/api-tokens/authorize?grant_type=refresh_token" SKYLINEAPI="https://skyline.vmware.com/public/api/data" TOKEN=$(curl -s -X POST $SKYLINEACCESS \ --header 'Accept: application/json' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode "refresh_token=$APITOKEN" | jq -r .access_token) curl -s -X POST $SKYLINEAPI -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' -d '{"query": " { activeFindings(limit: 5) { findings { findingId products totalAffectedObjectsCount } } } "}' | jq . |

Next we will get the “affected objects” from one entry on the list. The code is as follow.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
#!/bin/sh # APITOKEN="YOUR-TOKEN" SKYLINEACCESS="https://console.cloud.vmware.com/csp/gateway/am/api/auth/api-tokens/authorize?grant_type=refresh_token" SKYLINEAPI="https://skyline.vmware.com/public/api/data" TOKEN=$(curl -s -X POST $SKYLINEACCESS \ --header 'Accept: application/json' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode "refresh_token=$APITOKEN" | jq -r .access_token) curl -s -X POST $SKYLINEAPI -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' -d '{"query": " { activeFindings( filter: { findingId: \"'$1'\", product: \"'$2'\" } limit: 200) { findings { findingId accountId products findingDisplayName severity findingDescription findingImpact recommendations kbLinkURLs recommendationsVCF kbLinkURLsVCF categoryName findingTypes firstObserved totalAffectedObjectsCount affectedObjects(start: 0, limit: 200) { sourceName objectName objectType version buildNumber solutionTags { type version } firstObserved } } totalRecords timeTaken } }" }' | jq . |

The results will show all of the “affected objects”. Here is the video on this in action.
Comments