Here is an example how you can use the REST API on the BluecatDNSServer to query data via the workflow interface (alternatively you could use its API directly).
I am sure that you can use this concept for other web interfaces.
The script is a translation of a CURL request. It shows how to query the token and use this “BASIC Token” for further queries.
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
#BY J.Kühnis #Invoke Webrequest/RestMethod to get IP Adress & Mac-Adress from Bluecat API #translation of CURL Commands ############################ # CURL sample # #Get TOKEN #curl -k https://URL/rest_login -X POST -H "Content-Type: application/json" --data "{\"username\":\"your USERNAME\",\"password\":\"your USERNAME\"}" # #GET Request: #curl -k https://URL/get_ip_infos/get_ip_infos_endpoint -X GET -H "auth: Basic ****SOME TOKEN****" -H "Content-Type: application/json" --data "{\"host\":\"SERVERNAME\"}" # # #result: #{ # "ip": "some ip", # "mac": "some mac" #} ############################ #Trust SelfSigned SSL/TLS Channel add-type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy #Generate Web Token (Basic Token) Function Get-WebTokenBasic{ [CmdletBinding()] Param( [Parameter(Mandatory = $true)][string]$Username, [Parameter(Mandatory = $true)][string]$Password ) $json=ConvertTo-Json (@{"username"="$Username";"password"="$Password";}) $token = (Invoke-WebRequest -Uri "https://URL/rest_login" -Body $json -ContentType "application/json" -Method POST).content | Out-String | ConvertFrom-Json $token = $token.access_token $global:headers = @{auth="Basic $token"} } #Get IP or Mac from Servername Function Get-DNSBluecatValues{ [CmdletBinding()] Param( [Parameter(Mandatory = $true)][string]$ServerName ) $json4= (@{"host"="$servername";}) | ConvertTo-Json Try { Get-WebTokenBasic $result = Invoke-WebRequest -Uri "https://URL/get_ip_infos/get_ip_infos_endpoint" -Headers $headers -Body $json4 -Method Post -ContentType "application/json" $global:result = $result | ConvertFrom-Json return $global:result } Catch { $ErrorMessage = $_.Exception.Message $FailedItem = $_.Exception.ItemName Write-Warning "Failed Authentication or Webrequest" Break } } |
0