Skip to content

Instantly share code, notes, and snippets.

@BasvanH
Last active November 13, 2023 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BasvanH/cc7cb3974657bde5926af69869e73b0b to your computer and use it in GitHub Desktop.
Save BasvanH/cc7cb3974657bde5926af69869e73b0b to your computer and use it in GitHub Desktop.
Get Veeam Backup for Azure pending update status.
# This script get the pending updates from the Veeam Backup for Azure appliance.
# Since this information isnt available in VSPC I decided to write a script that uses the
# API and updates API to pull this info.
#
# You can integrate this into your own monitoring solution.
#
# `$pendingUpdates` is a integer and filled with the pending update count
# `$updateCategories` is a string and filled with the categories of the pending updates.
#
# Use at your own risk.
#
# Skip invalid or self signed SSL certifitates and force TLS1.2
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
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$url = "https://<url of your vba appliance>"
$username = "<your vba username>"
$password = "<your vba password>"
$body = @{
username=$username
password=$password
}
try {
$result = Invoke-RestMethod -Method Post -Uri $url/api/oauth2/token -Body $body -ContentType "application/x-www-form-urlencoded" -UseBasicParsing -ErrorAction Stop
} catch {
Write-Error "Failed to authenticate to VBA API."
exit 1
}
if ('access_token' -in $result.PSobject.Properties.Name) {
Write-Host "VBA access token received."
$headers = @{
Authorization="Bearer $($result.access_token)"
}
try {
$result = Invoke-RestMethod -Method Get -Uri $url/api/v5/system/updaterLink -Headers $headers -ErrorAction Stop
} catch {
Write-Error "Failed to retrieve updater refresh token."
exit 1
}
if ($result.Length -gt 20) {
Write-Host "VBA updater refresh token received."
$refreshToken = $result.Split("=")[1]
$body = @{
refresh_token=$refreshToken
grant_type="refresh_token"
} | ConvertTo-Json
try {
$result = Invoke-RestMethod -Method Post -Uri $url/updater/api/v2/auth/refresh-token -Body $body -ContentType "application/json" -ErrorAction Stop
} catch {
Write-Error "Failed to retrieve updater authentication token."
exit 1
}
if ('access_token' -in $result.PSobject.Properties.Name) {
Write-Host "VBA updater access token received."
$headers = @{
Authorization="Bearer $($result.access_token)"
}
try {
$result = Invoke-RestMethod -Method Get -Uri $url/updater/api/v2/updates/packages-list -Headers $headers -ErrorAction Stop
} catch {
Write-Error "Failed to retrieve updater update list."
exit 1
}
if ($result.origins.Count -gt 0) {
Write-Host "We have pending updates, lets get them."
$updateCategories = @{}
$pendingUpdates = 0
Foreach ($orgin in $result.origins) {
$updateCategory = [PSCustomObject]@{
Name=$orgin.name
Count=$orgin.childs.Count
}
$pendingUpdates += $orgin.childs.Count
$updateCategories["$($orgin.name)"] = $updateCategory
}
$updateCategories = ($updateCategories.Values | ForEach-Object { "$($_.Name): $($_.Count)" }) -join [System.Environment]::NewLine
Write-Host "There are $($pendingUpdates) pending updates."
} else {
$updateCategories = ""
$pendingUpdates = 0
Write-Host "No pending updates."
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment