We understand that not all administrators are using Linux or Mac OSX. Here are the steps to use the Skyline Insight API when in Windows.
NOTE: Please review this blog entry before proceeding. You need to do the prerequisites prior to using Powercli.
- Add “API User role”
- Create API Token
In order to create an Access Token from your API Token, here is the command to run.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$Header = @{ "Accept" = "application/json" "Content-Type" = "application/x-www-form-urlencoded" } $Body = @{ refresh_token = "YOUR-API-TOKEN" } $MYTOKEN = Invoke-RestMethod -method Post -Uri 'https://console.cloud.vmware.com/csp/gateway/am/api/auth/api-tokens/authorize?grant_type=refresh_token' -Headers $Header -Body $Body $MYTOKEN2 = $MYTOKEN.access_token |

Now that you have the Access Token, you can get the Skyline Findings. Run the next command.
1 |
$FINDINGS = invoke-restmethod -method post -Uri 'https://skyline.vmware.com/public/api/data' -Headers @{Authorization = "Bearer $MYTOKEN2"} -infile skyline.json -ContentType "application/json" |
NOTE: you need to create a skyline.json file as the “-infile”. For this easy example, I have chosen to get 1 output.
NOTE: I have updated the json file example.
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 |
{ "query" : " { activeFindings(limit: 200) { findings { findingId accountId findingDisplayName severity products findingDescription findingImpact recommendations kbLinkURLs recommendationsVCF kbLinkURLsVCF categoryName findingTypes firstObserved totalAffectedObjectsCount } totalRecords timeTaken } } "} |
If you are like me, you want the output to mirror the output of Skyline Advisor Pro user interface. By doing so, both outputs should look identical. Here are the entries that is needed for the CSV formatted output.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$FINDINGID = $FINDINGS.data.activeFindings.findings.findingId $DESCRIPTION = $FINDINGS.data.activeFindings.findings.findingDescription $RISK = $FINDINGS.data.activeFindings.findings.findingImpact $SEVERITY = $FINDINGS.data.activeFindings.findings.severity $RECOMMENDATIONS = $FINDINGS.data.activeFindings.findings.recommendations $SOURCE = $FINDINGS.data.activeFindings.findings.affectedObjects.objects.sourceName $OBJNAME = $FINDINGS.data.activeFindings.findings.affectedObjects.objects.objectName $OBJTYPE = $FINDINGS.data.activeFindings.findings.affectedObjects.objects.objectType #$SUMMARY = $FINDINGS.data.activeFindings.findings.affectedObjects.objects $HOSTVER = $FINDINGS.data.activeFindings.findings.affectedObjects.objects.version $BUILD = $FINDINGS.data.activeFindings.affectedObjects.objects.findings.buildNumber $FIRSTOBS = $FINDINGS.data.activeFindings.findings.firstObserved $REFERENCE = $FINDINGS.data.activeFindings.findings.kbLinkURLs |
1 2 3 4 5 6 |
new-item Finding_$FINDINGID.csv set-content Finding_$FINDINGID.csv "$([char]34)Finding Id$([char]34),""Issue Description$([char]34),""Risk if no Action Taken$([char]34),""Severity$([char]34),""Recommendations$([char]34),""Source Name$([char]34),""Object Name$([char]34),""Object Type$([char]34),""Summary$([char]34),""Host Version$([char]34),""Build$([char]34),""First Observed$([char]34),""Reference$([char]34)" add-content Finding_$FINDINGID.csv "$([char]34)$FINDINGID$([char]34),""$DESCRIPTION$([char]34),""$RISK$([char]34),""$SEVERITY$([char]34),""$RECOMMENDATIONS$([char]34),""$SOURCE$([char]34),""$OBJNAME$([char]34),""$OBJTYPE$([char]34),""$SUMMARY$([char]34),""$HOSTVER$([char]34),""$BUILD$([char]34),""$FIRSTOBS$([char]34),""$REFERENCE$([char]34)" |

In the end, you have the output of the Skyline Findings in a CSV format. You can now post this into a ticket or automation of your choice.
Comments