added
This commit is contained in:
@@ -204,7 +204,75 @@ function Get-DattoApiCredentials {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Logging Helpers
|
function Get-DattoRmmSites {
|
||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory)]
|
||||||
|
[string] $Password,
|
||||||
|
|
||||||
|
[Parameter()]
|
||||||
|
[string] $WebhookUrl = $Global:DattoWebhookUrl
|
||||||
|
)
|
||||||
|
|
||||||
|
# 1) Fetch Datto API credentials from your webhook
|
||||||
|
Write-Verbose "Fetching Datto API credentials from $WebhookUrl"
|
||||||
|
try {
|
||||||
|
$headers = @{ 'SVSMSPKit' = $Password }
|
||||||
|
$creds = Invoke-RestMethod -Uri $WebhookUrl -Headers $headers -Method GET
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Throw "Failed to fetch credentials from webhook: $_"
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiUrl = $creds.ApiUrl
|
||||||
|
$apiKey = $creds.ApiKey
|
||||||
|
$apiSecretKey = $creds.ApiSecretKey
|
||||||
|
|
||||||
|
# 2) Request an OAuth token
|
||||||
|
Write-Verbose "Requesting OAuth token from $apiUrl/auth/oauth/token"
|
||||||
|
try {
|
||||||
|
$securePwd = ConvertTo-SecureString -String 'public' -AsPlainText -Force
|
||||||
|
$credObj = New-Object System.Management.Automation.PSCredential('public-client', $securePwd)
|
||||||
|
|
||||||
|
$tokenResp = Invoke-RestMethod `
|
||||||
|
-Uri "$apiUrl/auth/oauth/token" `
|
||||||
|
-Credential $credObj `
|
||||||
|
-Method 'POST' `
|
||||||
|
-ContentType 'application/x-www-form-urlencoded' `
|
||||||
|
-Body "grant_type=password&username=$apiKey&password=$apiSecretKey"
|
||||||
|
|
||||||
|
$token = $tokenResp.access_token
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Throw "Failed to obtain OAuth token: $_"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 3) Fetch the list of RMM sites
|
||||||
|
Write-Verbose "Fetching RMM sites from $apiUrl/api/v2/account/sites"
|
||||||
|
try {
|
||||||
|
$authHeader = @{ Authorization = "Bearer $token" }
|
||||||
|
$sitesResp = Invoke-RestMethod `
|
||||||
|
-Uri "$apiUrl/api/v2/account/sites" `
|
||||||
|
-Method 'GET' `
|
||||||
|
-Headers $authHeader `
|
||||||
|
-ContentType 'application/json'
|
||||||
|
|
||||||
|
$siteList = $sitesResp.sites | Select-Object `
|
||||||
|
@{ Name = 'Name'; Expression = { $_.name } }, `
|
||||||
|
@{ Name = 'UID'; Expression = { $_.uid } }
|
||||||
|
|
||||||
|
if (-not $siteList) {
|
||||||
|
Write-Warning "No sites were returned by the API."
|
||||||
|
return @()
|
||||||
|
}
|
||||||
|
|
||||||
|
return $siteList
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Throw "Failed to fetch sites from API: $_"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Initialize a global in-memory log cache
|
# Initialize a global in-memory log cache
|
||||||
if (-not $Global:LogCache -or -not ($Global:LogCache -is [System.Collections.ArrayList])) {
|
if (-not $Global:LogCache -or -not ($Global:LogCache -is [System.Collections.ArrayList])) {
|
||||||
|
|||||||
Reference in New Issue
Block a user