Skyline Insight API Powershell example

Share on:

Short example on how to use the new Skyline Insight API with Powershell

Install the following module which will simplify the usage.

1Install-Module -Name PSGraphQL -Repository PSGallery -Scope CurrentUser

You have to create a API token for your Skyline ORG: https://docs.vmware.com/en/VMware-Skyline/1.0/skyline-api-guide/GUID-44592D1C-647D-4578-974A-C75D1D670B36.html

The Script:

  • you have to replace REFRESHTOKEN with your generated refresh token
  • you have to adjust your query based on your needs
 1$Header = @{
 2 "Accept" = "application/json"
 3 "Content-Type" = "application/x-www-form-urlencoded"
 4}
 5 
 6$Body = @{
 7 refresh_token = "REFRESHTOKEN"
 8}
 9 
10 
11$FULLTOKEN = 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
12 
13$MYTOKEN = $FULLTOKEN.access_token
14
15$headers = @{Authorization="Bearer $MYTOKEN"}
16$uri = "https://skyline.vmware.com/public/api/data"
17
18$myQuery = '
19    query {
20		activeFindings(
21			filter: {
22			        findingId: "vSphere-VIBAcceptanceLevels",
23			        product: "vcsa.local"
24			      }
25			limit: 200
26			) {
27		    findings {
28		      findingId
29		      accountId
30		      findingDisplayName
31		      severity
32		      products
33		      findingDescription
34		      findingImpact
35		      recommendations
36		      kbLinkURLs
37		      recommendationsVCF
38		      kbLinkURLsVCF
39		      categoryName
40		      findingTypes
41		      firstObserved
42		      totalAffectedObjectsCount
43		    }
44		    totalRecords
45		    timeTaken
46		  }
47   }
48'
49
50$response = Invoke-GraphQLQuery -Query $myQuery -Headers $headers -Uri $uri
51$response | ConvertTo-Json -Depth 100

Example Output:

 1PS /Users/hemmi/Documents> ./skyline_insight_api.ps1
 2{
 3  "data": {
 4    "activeFindings": {
 5      "findings": [
 6        {
 7          "findingId": "vSphere-VIBAcceptanceLevels",
 8          "accountId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
 9          "findingDisplayName": "vSphere-VIBAcceptanceLevels",
10          "severity": "TRIVIAL",
11          "products": [
12            "vcsa.local"
13          ],
14          "findingDescription": "ESXi host has one or more VIBs which is not VMware or Partner supported.",
15          "findingImpact": "Environmental Stability",
16          "recommendations": [
17            "Please work with 3rd party to validate if this VIB is necessary or can be updated. It is possible to run into a problem with secure boot when having VIBs that do not have appropriate VIB acceptance levels."
18          ],
19          "kbLinkURLs": [
20            "https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.security.doc/GUID-751034F3-5337-4DB2-8272-8DAC0980EACA.html"
21          ],
22          "recommendationsVCF": [
23            ""
24          ],
25          "kbLinkURLsVCF": [
26            ""
27          ],
28          "categoryName": "Compute",
29          "findingTypes": [
30            "TROUBLESHOOTING"
31          ],
32          "firstObserved": 1622285726305,
33          "totalAffectedObjectsCount": 1
34        }
35      ],
36      "totalRecords": 1,
37      "timeTaken": 27
38    }
39  }
40}