In the previous blog entries, I have shown how to get (a) get list of findings and (b) how to get the details (affected objects) using curl. You can find that blog here. Now I want to show the same information. This time, I am using Powershell/Powercli for our fellow Windows-based administrators.
To get your Access Token, you need to do the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$APITOKEN = "YOUR-TOKEN-HERE" $APITOKENSERVER = "https://console.cloud.vmware.com/csp/gateway/am/api/auth/api-tokens/authorize?grant_type=refresh_token" $ACCESSSERVER = https://skyline.vmware.com/public/api/data $Header = @{ "Accept" = "application/json" "Content-Type" = "application/x-www-form-urlencoded" } $Body = @{ refresh_token = "$APITOKEN" } $MYTOKEN = Invoke-RestMethod -method Post -Uri "$APITOKENSERVER" -Headers $Header -Body $Body |
Now, to get the list, I will create a skyline.json file with the needed query. I can run the json data internally. I choose to do this that you can rerun using the same data. You can even adjust the file to serve another need.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$file2 = "skyline.json" add-content $file2 '{ "query" : "' add-content $file2 '{' add-content $file2 ' activeFindings(limit: 200) {' add-content $file2 ' findings {' add-content $file2 ' findingId' add-content $file2 ' products' add-content $file2 ' totalAffectedObjectsCount' add-content $file2 ' }' add-content $file2 ' }' add-content $file2 '}' add-content $file2 '"}' $FINDINGS = invoke-restmethod -method post -Uri "$ACCESSSERVER" -Headers @{Authorization = "Bearer $MYTOKEN"} -infile skyline.json -ContentType "application/json" write-output $FINDINGS.data.activeFindings.findings |
Now that you have the list, you can highlight the preferred item to review the details. When you run the “get-detail” code, you will need to add those inputs in. Here is the code:
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 |
$file2 = "skyline.json" add-content $file2 '{ "query" : "' add-content $file2 '{' add-content $file2 ' activeFindings(' add-content $file2 ' filter: {' add-content $file2 " findingId: ``"$CHOICE2``"," add-content $file2 " product: ``"$CHOICE3``"" add-content $file2 ' }' add-content $file2 ' limit: 200) {' add-content $file2 ' findings {' add-content $file2 ' findingId' add-content $file2 ' accountId' add-content $file2 ' findingDisplayName' add-content $file2 ' severity' add-content $file2 ' products' add-content $file2 ' findingDescription' add-content $file2 ' findingImpact' add-content $file2 ' recommendations' add-content $file2 ' kbLinkURLs' add-content $file2 ' recommendationsVCF' add-content $file2 ' kbLinkURLsVCF' add-content $file2 ' categoryName' add-content $file2 ' findingTypes' add-content $file2 ' firstObserved' add-content $file2 ' totalAffectedObjectsCount' add-content $file2 ' affectedObjects(start: 0, limit: 200) {' add-content $file2 ' sourceName' add-content $file2 ' objectName' add-content $file2 ' }' add-content $file2 ' }' add-content $file2 ' totalRecords' add-content $file2 ' timeTaken' add-content $file2 ' }' add-content $file2 '}' add-content $file2 '"}' $FINDINGS = invoke-restmethod -method post -Uri "$ACCESSSERVER" -Headers @{Authorization = "Bearer $MYTOKEN"} -infile skyline.json -ContentType "application/json" write-output $FINDINGS.data.activeFindings.findings |
Here is how you will run the “get-detail” code with “FINDINGID” and “SOURCE” (vcenter or management host):
1 |
./get-detail FINDINGID SOURCE |
There you have it. You can see the details in command line as you would inside Skyline Advisor Pro.
Comments