This is a part of a script I have been using for about 2 years to pull basic data out of the Zerto analytic portal. I have really only just scratched the surface of what I can get.
When I first wrote this all I needed was the number of green/yellow/red VPGs but there is so much more.
Below is the code needed to connect to the portal and pull out a VPG list, alerts, VM info.
once connected, each section will pull put an object array. how you use that is up to you.
## User Prefs
## load credentials from file
# to create cred file open a powershell window as the user that will be running the script
# run
# $credential = Get-Credential
# enter the userID and password in the dialog box.
# run
# $credential | Export-CliXml -Path '[Path]\[filename].xml'
# done!
$Credentials = Import-CliXml -Path '[Path]\[filename].xml'
# putting creds in variables is not good but the HTTPS $body need them in that format.
$zaUsername = $Credentials.GetNetworkCredential().username
$zaPassword = $Credentials.GetNetworkCredential().password
$zaUsername = "user ID" # best to use a credential object and delete these 2 lines.
$zaPassword = "password" # best to use a credential object and delete these 2 lines.
## functions
# I copied this function from StackOverflow.com I have no idea what this function does except make the invoke web request work, I had to use this in early 2021 as Zerto changed something on there site.
function Set-UseUnsafeHeaderParsing
{
param(
[Parameter(Mandatory,ParameterSetName='Enable')]
[switch]$Enable,
[Parameter(Mandatory,ParameterSetName='Disable')]
[switch]$Disable
)
$ShouldEnable = $PSCmdlet.ParameterSetName -eq 'Enable'
$netAssembly = [Reflection.Assembly]::GetAssembly([System.Net.Configuration.SettingsSection])
if($netAssembly)
{
$bindingFlags = [Reflection.BindingFlags] 'Static,GetProperty,NonPublic'
$settingsType = $netAssembly.GetType('System.Net.Configuration.SettingsSectionInternal')
$instance = $settingsType.InvokeMember('Section', $bindingFlags, $null, $null, @())
if($instance)
{
$bindingFlags = 'NonPublic','Instance'
$useUnsafeHeaderParsingField = $settingsType.GetField('useUnsafeHeaderParsing', $bindingFlags)
if($useUnsafeHeaderParsingField)
{
$useUnsafeHeaderParsingField.SetValue($instance, $ShouldEnable)
}
}
}
}
## end of functions
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 -bor [System.Net.SecurityProtocolType]::Tls11
#Getting Zerto Analytics Token
$body = '{"username": "' + $zaUsername + '","password":"' + $zaPassword + '"}'
$contentType = 'application/json'
Set-UseUnsafeHeaderParsing -Enable
$xZertoAnalyticsToken = Invoke-RestMethod -Uri "https://analytics.api.zerto.com/v2/auth/token" -Method POST -Body $body -ContentType $contentType
#Build authorization header
$authHeaders = @{"Authorization" = "Bearer " + $xZertoAnalyticsToken.token}
#Get RPO statistics for VPG
#Set the vpgIdentifier of the VPG you want to pull statistics for
$vpgIdentifier = "VPGID"
#Get the current time
$CurrentDateTime = Get-Date
#Get current time -5 minutes to pull statistics from last 5 minutes
$ts = New-TimeSpan -Minutes 5
$FiveMinutseAgo = Get-Date($CurrentDateTime-$ts) -Format O
#URL Encode time
$FiveMinutesAgo = [System.Web.HttpUtility]::UrlEncode($FiveMinutesAgo)
$getRpoStatsUrl = "https://analytics.api.zerto.com/v2/reports/stats-rpo?startDate=" + $FiveMinutesAgo + "&vpgIdentifier=" + $vpgIdentifier
## get VMs
$getRpoStatsUrl = "https://analytics.api.zerto.com/v2/monitoring/protected-vms"
$ZertoVMs = Invoke-RestMethod -Uri $getRpoStatsUrl -Headers $authHeaders
## get Sites
$getRpoStatsUrl = "https://analytics.api.zerto.com/v2/reports/sites-list"
$ZertoSites = Invoke-RestMethod -Uri $getRpoStatsUrl -Headers $authHeaders
## Get alerts
$getRpoStatsUrl = "https://analytics.api.zerto.com/v2/monitoring/alerts"
$ZertoAlerts = Invoke-RestMethod -Uri $getRpoStatsUrl -Headers $authHeaders
## Get VPGs
$getRpoStatsUrl = "https://analytics.api.zerto.com/v2/monitoring/vpgs"
$ResZertoVPGs = Invoke-RestMethod -Uri $getRpoStatsUrl -Headers $authHeaders
$ZertoVPGs = $ResZertoVPGs.vpgs
## Get journel info
$getJournalsUrl = "https://analytics.api.zerto.com/v2/reports/stats-journal-storage?endDate=(YYYY)-(MM)-(DD)T(hh)%3A(mm)%3A(ss)Z&vpgIdentifier=(VPG GUID)"
$ResJournals = Invoke-RestMethod -Uri $getJournalsUrl -Headers $authHeaders
$ZertoJstat = $ResJournals
# get all VPGs in protected site
$sitevpgs = $ZertoVPGs | where{$_.protectedSite[0].name -eq "(Site name)"}