My script looks like
import requests
import base64
user="domain\\username"
pass="password"
Authentication_mode="Windows"
tok=Authentication_mode+":"+user+":"+pass #referring the doc for authentication at https://learn.microsoft.com/en-us/rest/api/operationsmanager/authentication/login
token=base64.b64encode(bytes(token,'utf-8')).decode()
headers={'content-type':'application/json',
'Authorization': 'Basic %s' % token
}
payload={}
url="http://<Servername>/OperationsManager/authenticate"
respone=requests.post(url,headers=headers,data=payload)
print(response)
I am getting the response code 401 instead of 200. FYI I have tried NTLM auth(gives error 400),HTTPBasicauth, HTTPDigestAuth.
The Powershell script which is given at https://community.squaredup.com/answers/question/scom-1801-rest-api/ ,I want to do this with Python.
$scomHeaders = New-Object “System.Collections.Generic.Dictionary[[String],[String]]”
$scomHeaders.Add(‘Content-Type’,’application/json; charset=utf-8′)
$bodyraw = “Windows”
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($bodyraw)
$EncodedText =[Convert]::ToBase64String($Bytes)
$jsonbody = $EncodedText | ConvertTo-Json
$uriBase = ‘http://xxxxxx/OperationsManager/authenticate’
$auth = Invoke-RestMethod -Method POST -Uri $uriBase -Headers $scomheaders -body $jsonbody -UseDefaultCredentials -SessionVariable websession
$query = @($query = @( @{ “classid” = “” “displayColumns”= “severity”, “monitoringobjectdisplayname”, “name”, “age”, “repeatcount”, “lastModified” })
$jsonquery = $query | ConvertTo-Json
$Response = Invoke-WebRequest -Uri “http://xxxxxx/OperationsManager/data/alert” -Method Post -Body $jsonquery -ContentType “application/json” -UseDefaultCredentials -WebSession $websession
$alerts = ConvertFrom-Json -InputObject $Response.Content
$alerts.rows | select monitoringobjectdisplayname,name,severity,age