In some cases, the SCOM Data Source for Grafana may fail to connect to SCOM. To troubleshoot the issue, you can use a PowerShell script to verify the connection.
To troubleshoot the connection to the SCOM REST API, you can use the script below. Make sure that the followin variables reflect your environment:$URIBase = 'http://<FQDN>/OperationsManager'
$userName ="contoso\administrator";
$password ="*********";
# The SCOM REST API authentication URL
$URIBase = 'http://<FQDN>/OperationsManager'
$userName ="contoso\administrator";
$password ="*********";
$AuthenticationMode= "Network"
$scomHeaders = New-Object “System.Collections.Generic.Dictionary[[String],[String]]”
$scomHeaders.Add('Content-Type','application/json; charset=utf-8')
$bodyraw = "($AuthenticationMode):$($userName):$($password)”
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($bodyraw)
$EncodedText =[Convert]::ToBase64String($Bytes)
$JSONBody = $EncodedText | ConvertTo-Json
#Authenticate
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($userName, $securePassword)
#$cred = $(Get-Credential)
$auth = Invoke-WebRequest -Method POST -Uri $uriBase/authenticate -Headers $scomheaders -body $jsonbody -Credential $cred -SessionVariable WebSession
#Include CSRF Token
$csrfTocken = $WebSession.Cookies.GetCookies($uriBase) | Where-Object { $_.Name -eq 'SCOM-CSRF-TOKEN' }
$scomHeaders.Add('SCOM-CSRF-TOKEN', [System.Web.HttpUtility]::UrlDecode($csrfTocken.Value))
#Examples to Invoke the required SCOM API
#Criteria: Enter the displayname of the SCOM object
$Criteria = "DisplayName LIKE '%Windows%'"
#Convert our criteria to JSON format
$JSONBody = $Criteria | ConvertTo-Json
$Response = Invoke-RestMethod -Uri $URIBase/data/class/monitors -Method Post -Body $JSONBody -WebSession $WebSession -Headers $SCOMHeaders -Credential $cred
$Response.Content | Convertto-json
# Print out the alert results
$Alerts = $Response.Rows
$Alerts